#!/bin/sh # # --- CARGA LAS VARIABLES DEL PKGBUILD Y AÑADE LAS FALTANTES source PKGBUILD startdir="$(pwd)" [ -z $prefix ] && prefix=/usr [ -z $arch ] && arch=i386 [ -f /etc/tgzbuild.conf ] && source /etc/tgzbuild.conf [ -f /etc/tgzbuild.functions ] && source /etc/tgzbuild.functions # --- AHORA CAMBIAMOS LAS VARIABLES A MAYUSCULAS PARA EL ESTANDAR # --- solo cambio las variables QUE SI utilizamos STARTDIR="$startdir" PKGNAME="$pkgname" PKGVER="$pkgver" PKGREL="$pkgrel" PKGDESC="$pkgdesc" URL="$url" LICENSE="$license" CONFLICTS="$conflicts" ARCH="$arch" SOURCE="$source" MD5SUMS="$md5sums" DEPENDS="$depends" MAKEDEPENDS="$makedepends" OPTIONS="$options" PREFIX="$prefix" # --- CHEKEA KE TENGAMOS PERMISOS DE ESCRITURA EN EL DIRECTORIO if [ -w "$STARTDIR" ]; then mkdir -p "$STARTDIR/src" else error "No se puede escribir en el directorio ( $STARTDIR )" exit 123 fi # --- PRIMERO QUE NADA CHEKEAMOS QUE TENGAMOS LAS DEPENDECIAS QUE REKIERE EL PAKETE # ---!!! ESTE CHEKEO ES MUY BASICO Y PUEDE QUE NO FUNCIONE DE LA FORMA CORRECTA !!! if [ -z $depends ]; then msg "No hay dependencias a comprobar... " else msg "Comprobando dependencias.. " errors=0 for i in ${depends[@]} do dep=$(echo $i | sed "s/\“//g" | sed "s/\”//g") # esto es para corregir el problema con los nombres que contengan + if [ "$dep" = "gtk2" ]; then dep="gtk+2" fi if [ "$dep" = "dvdrtools" ]; then dep="dvd+rw-tools" fi if ls -1 /var/log/packages | grep -i $dep 1> /dev/null 2> /dev/null ; then true else error "$i es requerido... " errors=$(($errors+1)) fi done if [ "$errors" -ge "1" ]; then error "Dependencias faltantes... " e=n echo -n "Deseas continuar de todas maneras?... [n/y] " read e until [ "$e" = "n" -o "$e" = "N" -o "$e" = "y" -o "$e" = "Y" ]; do echo -n "Deseas continuar de todas maneras?... [n] " read e done if [ "$e" = "n" -o "$e" = "N" ]; then error "Cancelando compilacion... " exit 123 else warning "Continuando con dependencias faltantes... " true fi fi fi # --- DESCARGA EL PAKETE DESDE LA WEB # --- utiliza el gestor definido en /etc/tgzbuild.conf if [ -z $SOURCE ]; then warning "No hay fuentes que descargar... " else msg "Obteniendo sources..." cd "$STARTDIR/src" for netfile in ${SOURCE[@]}; do file=`strip_url $netfile` if [ -f ../$file ]; then msg " Encontrado $file en el directorio" cp ../$file . else if [ -z "$FTPAGENT" ]; then error "FTPAGENT no esta configurado. Chequea /etc/tgzbuild.conf " msg "Cancelando..." exit 123 fi ftpclient=`echo $FTPAGENT | awk {'print $1'}` if [ ! -x $ftpclient ]; then error "ftpclient `basename $ftpclient` no esta instalado." msg "Cancelando..." exit 123 fi proto=`echo $netfile | sed 's|://.*||'` if [ "$proto" != "ftp" -a "$proto" != "http" -a "$proto" != "https" ]; then error "$netfile no fue encontrado en el direcorio build y no es una URL valida." msg "Cancelando..." exit 123 fi msg " Descargando $file" $FTPAGENT $netfile 2>&1 if [ ! -f $file ]; then error "Fallo la descarga $file" msg "Cancelando..." exit 123 fi fi done fi # # --- Chekea el MDSSUM en los archivos if [ -z $MD5SUMS ]; then warning "No hay MD5SUMS para verificar... " else if [ ${#MD5SUMS[@]} -ne ${#SOURCE[@]} ]; then warning "MD5sums no existe o esta incompleto. No se puede veeficiar la integritdad." elif [ `type -p md5sum` ]; then msg "Validando los archivos con MD5sums" errors=0 idx=0 for netfile in ${SOURCE[@]}; do file=`strip_url $netfile` echo -n " $file ... " >&2 echo "${MD5SUMS[$idx]} $file" | md5sum -c - >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "FALLO" >&2 errors=1 else echo "OK" >&2 fi idx=$(($idx+1)) done if [ $errors -gt 0 ]; then error "Uno o mas archivos no pasaron la validacion!" exit 123 fi else warning "El programa md5sum no fue encontrado. No se puede verificar los archivos" sleep 1 fi fi # # --- Extrae los archivos if [ ! -z $SOURCE ]; then msg "Extrayendo fuentes..." for netfile in ${SOURCE[@]}; do unziphack=0 file=`strip_url $netfile` unset cmd case $file in *.tar.gz|*.tar.Z|*.tgz) cmd="tar --use-compress-program=gzip -xf $file" ;; *.tar.bz2|*.tbz2) cmd="tar --use-compress-program=bzip2 -xf $file" ;; *.tar) cmd="tar -xf $file" ;; *.zip) unziphack=1 cmd="unzip -qqo $file" ;; *.gz) cmd="gunzip $file" ;; *.bz2) cmd="bunzip2 $file" ;; esac if [ "$cmd" != "" ]; then msg " $cmd" $cmd if [ $? -ne 0 ]; then # unzip will return a 1 as a warning, it is not an error if [ "$unziphack" != "1" -o $? -ne 1 ]; then error "Fallo al extraer $file" msg "Aborting..." exit 1 fi fi fi done fi # # --- ACA YA COMIENZAN LOS PASOS DEL COMPILADO # acomodamos los permisos if [ -d $STARTDIR/src/$PKGNAME-$PKGVER ]; then if [ "`id -u`" = "0" ]; then cd $STARTDIR/src/$PKGNAME-$PKGVER chown -R root.root . find . -perm 666 -exec chmod 644 {} \; find . -perm 664 -exec chmod 644 {} \; find . -perm 600 -exec chmod 644 {} \; find . -perm 444 -exec chmod 644 {} \; find . -perm 400 -exec chmod 644 {} \; find . -perm 440 -exec chmod 644 {} \; find . -perm 777 -exec chmod 755 {} \; find . -perm 775 -exec chmod 755 {} \; find . -perm 511 -exec chmod 755 {} \; find . -perm 711 -exec chmod 755 {} \; find . -perm 555 -exec chmod 755 {} \; fi fi # chekea la existencia del directorio pkg if [ -d $STARTDIR/pkg ]; then msg "Removiendo pkg/ directorio..." rm -rf $STARTDIR/pkg fi mkdir -p $STARTDIR/pkg # comienza el compilado msg "Comenzando build()..." build 2>&1 if [ $? -gt 0 ]; then error "Build Fallo. Cancelando..." exit 2 fi # --- Arreglamos un poco los directorios antes de crear el pakete # mueve /usr/share/man a /usr/man cd $STARTDIR if [ -d pkg/usr/share/man ]; then mkdir -p pkg/usr/man cp -a pkg/usr/share/man/* pkg/usr/man/ rm -rf pkg/usr/share/man fi # remuevo /usr/share si esta vacio cd $STARTDIR if [ -d pkg/usr/share ]; then if [ -z "`ls -1 pkg/usr/share`" ]; then rm -r pkg/usr/share fi fi # comprime las paginas del manual cd $STARTDIR msg "Comprimiendo man pages..." find $STARTDIR/pkg/{usr{,/local,/share},opt/*}/man -type f 2>/dev/null | while read i ; do ext="${i##*.}" fn="${i##*/}" if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then find $STARTDIR/pkg/{usr{,/local,/share},opt/*}/man -lname "$fn" 2> /dev/null | while read ln ; do rm -f "$ln" ln -sf "${fn}.gz" "${ln}.gz" done gzip -9 "$i" fi done # Crea la documentacion para eslack cd $STARTDIR mkdir -p $STARTDIR/pkg/$PREFIX/doc/$PKGNAME-$PKGVER cd $STARTDIR/src/$PKGNAME-$PKGVER for f in AUTHORS \ COPYING \ ChangeLog \ INSTALL \ NEWS \ README \ TODO \ VERSIONS \ FAQ do cp -avf $f $STARTDIR/pkg/$PREFIX/doc/$PKGNAME-$PKGVER/ 1> /dev/null 2>/dev/null done # strip binarios cd $STARTDIR msg "Stripping simbolos desde librarias..." find $STARTDIR/pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ | grep -v "No such file" | grep -v "format not recognized" msg "Stripping simbolos desde binarios..." find $STARTDIR/pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ -exec /usr/bin/strip '{}' \; 2>&1 \ | grep -v "No such file" | grep -v "format not recognized" # remueve directorios vacios cd $STARTDIR msg "Removiendo directorios vacios..." find $STARTDIR/pkg -mindepth 1 -type d -empty -exec rmdir {} \; # Crea una breve descripcion cd $STARTDIR/pkg mkdir -p $STARTDIR/pkg/install echo "$PKGNAME: " "$PKGDESC" >> $STARTDIR/pkg/install/slack-desc echo "$PKGNAME: " >> $STARTDIR/pkg/install/slack-desc echo "$PKGNAME: " "$URL" " $LICENSE" >> $STARTDIR/pkg/install/slack-desc echo "$PKGNAME: " "License" " $LICENSE" >> $STARTDIR/pkg/install/slack-desc echo "$PKGNAME: " "$PACKAGER" >> $STARTDIR/pkg/install/slack-desc echo "$PKGNAME: " >> $STARTDIR/pkg/install/slack-desc # Ahora si, crea el tgz final cd $STARTDIR msg "Creando el paquete..." cd $STARTDIR/pkg && makepkg -l y -c n -p $PKGNAME-$PKGVER-$ARCH-$PKGREL.tgz 1> /dev/null 2> /dev/null if [ "$?" = "0" ]; then [ -z $PKGDEST ] && PKGDEST=$STARTDIR mv $PKGNAME-$PKGVER-$ARCH-$PKGREL.tgz $PKGDEST msg "Limpiando... " rm -rf $STARTDIR/pkg $STARTDIR/src $STARTDIR/install msg "Listo" else error "Fallo la creacion del paquete" fi