#!/bin/bash # # SPM - SIMLINUX PACKET MANAGER # # Copyright (c) 2006 Sergi Coll (sergi at sim00.net) # # http://www.sim00.net/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. VER=0.3a if [ "$PREFIX" == "" ]; then PREFIX=/ fi BASEDEDADES_DE_PAQUETS=$PREFIX/simlinux/uninstall OPTERR=1 function help() { echo "" echo "SPM - SIMLINUX PACKET MANAGER - $VER - http://www.sim00.net/" echo "Ús: "`basename $0`" [OPCIO] [PARAMETRES]" echo "" echo " -h Pantalla d'ajuda" echo " -l Llista de paquets" echo " -q Llistar continguts de paquets" echo " -i Instal.lar paquets" echo " -e Desinstal.lar paquets" echo " -b Llistar contigut d'un paquet" echo " -f Cercar fitxers" echo " -r Recrea el paquet a partir dels fitxers instal.lats" echo " -s Ocupació en disc dels paquets" echo "" } function query() { cat $BASEDEDADES_DE_PAQUETS/uninstall_$1 } function list () { ls -lb1 $BASEDEDADES_DE_PAQUETS/uninstall_* | cut -d '_' -f 2 } function fetch () { for i in `ls -lb1 $BASEDEDADES_DE_PAQUETS/uninstall_*| cut -d '_' -f 2`; do TROBAT=`cat $BASEDEDADES_DE_PAQUETS/uninstall_$i |grep $1` if [ "$TROBAT" != "" ]; then echo "$i : $TROBAT" fi done } function erase () { if [ -f $BASEDEDADES_DE_PAQUETS/uninstall_$1 ]; then if [ -f $PREFIX/simlinux/log/uninstall.log ]; then touch $PREFIX/simlinux/log/uninstall.log else mkdir -p $PREFIX/simlinux/log/ >/dev/null 2>/dev/null touch $PREFIX/simlinux/log/uninstall.log fi echo "Eliminant $1 ..." for i in `cat $BASEDEDADES_DE_PAQUETS/uninstall_$1|grep -v simlinux`; do rm -df $PREFIX/$i >>$PREFIX/simlinux/log/uninstall.log 2>>$PREFIX/simlinux/log/uninstall.log echo -n "#" done echo "" echo "Finalitzat" rm $BASEDEDADES_DE_PAQUETS/uninstall_$1 else echo "ERROR: Fitxer de desinstalació no trobat: $BASEDEDADES_DE_PAQUETS/uninstall_$1" fi } function install () { cd $PREFIX && tar jxvf $1 ldconfig -r $PREFIX } function bz2query () { tar jtvf $1 } function rollback () { if [ -f $BASEDEDADES_DE_PAQUETS/uninstall_$1 ]; then if [ -f $PREFIX/simlinux/log/rollback.log ]; then touch $PREFIX/simlinux/log/rollback.log else mkdir -p $PREFIX/simlinux/log/ >/dev/null 2>/dev/null touch $PREFIX/simlinux/log/rollback.log fi if [ -f /tmp/rollback.tmp ]; then rm -rf /tmp/rollback.tmp fi for fr in `cat $BASEDEDADES_DE_PAQUETS/uninstall_$1 |sed -e 's/.//'`; do if [ -f $fr ]; then echo $fr >>/tmp/rollback.tmp fi done echo "Recreant el paquet $1 ..." tar jcvf $1.tar.bz2 --files-from=/tmp/rollback.tmp >>$PREFIX/simlinux/log/rollback.log 2>>$PREFIX/simlinux/log/rollback.log echo "Finalitzat" rm -rf /tmp/rollback.tmp else echo "ERROR: Fitxer de desinstalació no trobat: $BASEDEDADES_DE_PAQUETS/uninstall_$1" fi } function sumarize () { if [ -f $BASEDEDADES_DE_PAQUETS/uninstall_$1 ]; then for FILEPACK in `cat $BASEDEDADES_DE_PAQUETS/uninstall_$1 |sed -e 's/.//'`; do if [ -f $FILEPACK ]; then echo $FILEPACK >>/tmp/sumarize.tmp fi done FILESUM=`cat /tmp/sumarize.tmp` du -chs $FILESUM rm /tmp/sumarize.tmp else echo "ERROR: Fitxer de desinstalació no trobat: $BASEDEDADES_DE_PAQUETS/uninstall_$1" fi } while getopts "hlq:i:e:f:b:r:s:" OPTION; do case "$OPTION" in h) help ;; l) list ;; q) q_opt="$OPTARG"; query $q_opt ;; i) i_opt="$OPTARG"; install $i_opt ;; e) e_opt="$OPTARG"; erase $e_opt ;; f) f_opt="$OPTARG"; fetch $f_opt ;; b) b_opt="$OPTARG"; bz2query $b_opt ;; r) r_opt="$OPTARG"; rollback $r_opt ;; s) s_opt="$OPTARG"; sumarize $s_opt ;; \?) help ;; esac done if [ $# -lt "1" ]; then help fi