2
# Copyright (C) 2007-2011 Matias A. Fonzo, Santiago del Estero, AR
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
# Localizaci�n % Idioma:
18
TEXTDOMAINDIR=/usr/share/locale
25
# Una funci�n para mostrar mensajes normales:
26
msg() { local LC_ALL ; printf '%s\n' "$@"; }
28
# Una funci�n para mensajes de advertencia:
29
warn() { local LC_ALL; printf '%b\n' "$@" >&2; }
32
msg $"Installs one or more packages in your system." \
34
$"Usage: add [options] package_name.tlz ..." \
37
$" -h, --help Show this help and exit." \
38
$" -v, --version Show the version of the program." \
39
$" -f, --force Overwrite installed package." \
40
$" -w, --warn Warn about of the files and" \
41
$" directories that will be" \
42
$" installed or overwritten." \
48
"Copyright (C) 2007-2011 Matias A. Fonzo <selk@dragora.org>." \
49
"License GPLv3+: GNU GPL version 3 or later:" \
50
"<http://gnu.org/licenses/gpl.html>" \
51
"This is free software: you are free to change and redistribute it." \
52
"There is NO WARRANTY, to the extent permitted by law."
75
warn $"${0##*/}: Invalid option: $1"
83
# Si no hay argumentos, llama a la funci�n de ayuda:
84
(( $# == 0 )) && { usage ; exit 0; }
86
# Sale ante cualquier error:
89
# Advierte acerca de los directorios y archivos del
90
# paquete que ser�n instalados o sobreescritos:
91
if [[ $OPT = WARN ]]; then
93
msg "" $"% Scanning $1 ..." ""
94
LC_ALL=C tar --use-compress-program=lzip -tvvf "$1" | awk '!/^drwx/'
101
# Comprobamos la variable de entorno ROOT:
102
if [[ -n $ROOT && ! -d $ROOT ]]; then
103
warn $"${0##*/}: ROOT=${ROOT}: Invalid directory"
109
# Chequeo de sanidad.
111
# Comprueba si el sistema de archivos
112
# se encuentra en modo de s�lo-lectura:
113
if ! touch ${ROOT}/pkg-add$$ ; then
114
warn $"The filesystem (on $ROOT) is in read-only mode."
117
rm -f ${ROOT}/pkg-add$$
119
# Base de datos por defecto:
122
# Nos aseguramos de que las partes de la base de datos exista:
128
if [[ ! -d ${DB}/$directory ]]; then
129
mkdir -p "${DB}/$directory"
135
# Una funci�n para reflejar el nombre base:
136
_basename() { local name ; name=${1##*/} ; printf "${name%$2}"; }
138
# Una funci�n que ejecuta los scripts de pre y post instalaci�n:
142
if [[ -r ${ROOT}/install/$fileName ]]; then
143
msg $"| $fileName execution for $pkgname ..."
146
install -m 0755 install/$fileName \
147
-D ${DB}/pkg/${fileName}/$pkgname && \
148
rm -f install/$fileName
153
# Guardamos y exportamos la variable de entorno LC_ALL
154
# para que algunos comandos corran m�s r�pido:
159
for package in "$@" ; do
160
if [[ -f $package ]]; then
161
# Comprueba la extensi�n del paquete:
164
pkgname=$(_basename $package .tlz)
167
warn "${package}: Does not end in .tlz"
172
warn $"${0##*/}: ${package}: File not found or non-regular"
177
# Si el paquete no est� en la base de datos, lo instalamos:
178
if [[ ! -r ${DB}/pkg/$pkgname || $OPT = FORCE ]]; then
179
msg "" $"> Installing $pkgname ..." ""
181
# Chequea la integridad del paquete:
182
msg $"% Testing integrity ..." ""
183
tar --use-compress-program=lzip -tf $package >/dev/null
185
# Descomprime el tarball:
188
--use-compress-program=lzip \
189
--strip-components=1 --show-stored-names \
191
) < $package > ${DB}/pkg/$pkgname
193
if (( $CODE != 0 )); then
194
rm -f ${DB}/pkg/$pkgname
198
warn $"${DB}/pkg/${pkgname}: Already installed"
203
# Muestra la descripci�n en el lenguaje disponible, de acuerdo a la
204
# "locale" usada por el sistema, y a la variable de entorno $LANG:
210
??_??|*.ISO8859-1|*.iso88591|*.ISO-8859-1)
216
# Imprime el archivo de descripci�n:
217
if [[ -f ${ROOT}/description/${DLANG} ]]; then
218
( cd ${ROOT}/description
219
if [[ $UTF8_OUTPUT ]]; then
220
fmt <(iconv --from-code=ISO8859-1 --to-code=UTF-8 $DLANG)
224
# Movemos los archivos a la base de datos:
226
mv "$file" "${DB}/pkg/description/${pkgname}_${file}"
231
# Ejecuta el script de pre-post instalaci�n:
232
exe_install "pre-post"
234
# Ejecuta el script de post-instalaci�n:
235
exe_install "post-install"
237
# Remueve los directorios de descripci�n e instalaci�n:
238
rmdir ${ROOT}/{description,install} >/dev/null 2>&1 || :