spk rev 17

libspk.sh: set $root for all files/DB path, spk-rm: work with --root=
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 12:29:41 2012 +0200 (2012-05-15)
parents 57ae420bd1c2
children e5d4c5d3ccf4
files lib/libspk.sh spk-rm
line diff
     1.1 --- a/lib/libspk.sh	Tue May 15 12:08:23 2012 +0200
     1.2 +++ b/lib/libspk.sh	Tue May 15 12:29:41 2012 +0200
     1.3 @@ -11,14 +11,13 @@
     1.4  . /etc/slitaz/slitaz.conf
     1.5  
     1.6  # Internal variables.
     1.7 -# We should have ${root}/$PKGS_DB ???
     1.8 -mirrorurl="$PKGS_DB/mirror"
     1.9 -installed="$PKGS_DB/installed"
    1.10 -pkgsdesc="$PKGS_DB/packages.desc"
    1.11 -pkgsmd5="$PKGS_DB/packages.md5"
    1.12 +mirrorurl="${root}${PKGS_DB}/mirror"
    1.13 +installed="${root}${PKGS_DB}/installed"
    1.14 +pkgsdesc="${root}${PKGS_DB}/packages.desc"
    1.15 +pkgsmd5="${root}${PKGS_DB}/packages.md5"
    1.16  # ????do we need packages.equiv????
    1.17 -blocked="$PKGS_DB/blocked-packages.list"
    1.18 -activity="$PKGS_DB/activity"
    1.19 +blocked="${root}${PKGS_DB}/blocked-packages.list"
    1.20 +activity="${root}${PKGS_DB}/activity"
    1.21  
    1.22  #
    1.23  # Functions
     2.1 --- a/spk-rm	Tue May 15 12:08:23 2012 +0200
     2.2 +++ b/spk-rm	Tue May 15 12:29:41 2012 +0200
     2.3 @@ -6,7 +6,8 @@
     2.4  # Copyright (C) SliTaz GNU/Linux - BSD License
     2.5  # Author: See AUTHORS files
     2.6  #
     2.7 -. /usr/lib/slitaz/libspk.sh
     2.8 +#. /usr/lib/slitaz/libspk.sh
     2.9 +. lib/libspk.sh
    2.10  
    2.11  #
    2.12  # Functions
    2.13 @@ -23,6 +24,7 @@
    2.14  
    2.15  $(boldify $(gettext "Options:"))
    2.16    --confirm   $(gettext "Ask before removing any packages")
    2.17 +  --root      $(gettext "Set the root file system path")
    2.18    --verbose   $(gettext "Be more verbose when removing files")
    2.19  
    2.20  $(boldify $(gettext "Examples:"))
    2.21 @@ -49,16 +51,16 @@
    2.22  # Remove a single package
    2.23  remove() {
    2.24  	altered=""
    2.25 -	for i in $(cd ${root}${installed} ; ls); do
    2.26 -		[ -f ${root}${installed}/$i/receipt ] || continue
    2.27 +	for i in $(cd $installed ; ls); do
    2.28 +		[ -f $installed/$i/receipt ] || continue
    2.29  		unset_receipt
    2.30 -		. ${root}${installed}/$i/receipt
    2.31 +		. $installed/$i/receipt
    2.32  		case " $(echo $DEPENDS) " in
    2.33  			*\ $pkg\ *) altered="$altered $i" ;;
    2.34  		esac
    2.35  	done
    2.36  	unset_receipt
    2.37 -	. ${root}${installed}/$pkg/receipt
    2.38 +	. $installed/$pkg/receipt
    2.39  
    2.40  	if [ -n "$altered" ]; then
    2.41  		eval_gettext "The following packages depend on \$PACKAGE:"; echo
    2.42 @@ -66,7 +68,7 @@
    2.43  			echo "  $i"
    2.44  		done
    2.45  	fi
    2.46 -	refresh=$(cd ${root}${installed} ; grep -sl ^$PACKAGE$ */modifiers)
    2.47 +	refresh=$(cd $installed ; grep -sl ^$PACKAGE$ */modifiers)
    2.48  	if [ -n "$refresh" ]; then
    2.49  		eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
    2.50  		for i in $refresh; do
    2.51 @@ -84,7 +86,7 @@
    2.52  			fi
    2.53  		fi
    2.54  		for i in $altered; do
    2.55 -			if [ -d "${root}${installed}/$i" ]; then
    2.56 +			if [ -d "$installed/$i" ]; then
    2.57  				# TODO: use spk-rm
    2.58  				echo "tazpkg remove $i --root=$root"
    2.59  			fi
    2.60 @@ -92,43 +94,43 @@
    2.61  	fi
    2.62  
    2.63  	# Handle pre_remove
    2.64 -	if grep -q ^pre_remove ${root}${installed}/$PACKAGE/receipt; then
    2.65 +	if grep -q ^pre_remove $installed/$PACKAGE/receipt; then
    2.66  		pre_remove $root
    2.67  	fi
    2.68  
    2.69  	# Remove all files
    2.70  	gettext "Removing all installed files..."
    2.71  	[ "$verbose" ] && newline
    2.72 -	if [ -f ${root}${installed}/$PACKAGE/modifiers ]; then
    2.73 -	    for file in `cat ${root}${installed}/$PACKAGE/files.list`
    2.74 +	if [ -f $installed/$PACKAGE/modifiers ]; then
    2.75 +	    for file in `cat $installed/$PACKAGE/files.list`
    2.76  	    do
    2.77 -			for mod in `cat ${root}${installed}/$PACKAGE/modifiers`
    2.78 +			for mod in `cat $installed/$PACKAGE/modifiers`
    2.79  			do
    2.80 -				[ -f ${root}${installed}/$mod/files.list ] && \
    2.81 -					[ $(grep "^$(echo $file | grepesc)$" ${root}${installed}/$mod/files.list | wc -l) -gt 1 ] \
    2.82 +				[ -f $installed/$mod/files.list ] && \
    2.83 +					[ $(grep "^$(echo $file | grepesc)$" $installed/$mod/files.list | wc -l) -gt 1 ] \
    2.84  					&& continue 2
    2.85  			done
    2.86 -			[ "$verbose" ] && gettext "Removing:"; echo -n " ${root}${file}"
    2.87 +			[ "$verbose" ] && (gettext "Removing:"; echo -n " ${root}${file}")
    2.88  			remove_file ${root}${file}
    2.89  	    done
    2.90  	else
    2.91 -		for file in $(cat ${root}${installed}/$PACKAGE/files.list)
    2.92 +		for file in $(cat $installed/$PACKAGE/files.list)
    2.93  		do
    2.94 -			[ "$verbose" ] && gettext "Removing:"; echo -n " ${root}${file}"
    2.95 +			[ "$verbose" ] && (gettext "Removing:"; echo -n " ${root}${file}")
    2.96  			remove_file ${root}${file}
    2.97  			[ "$verbose" ] && status
    2.98  		done
    2.99  	fi
   2.100 -	[ "$verbose" ] || status
   2.101 +	[ ! "$verbose" ] && status
   2.102  
   2.103  	# Handle post_remove
   2.104 -	if grep -q ^post_remove ${root}${installed}/$PACKAGE/receipt; then
   2.105 +	if grep -q ^post_remove $installed/$PACKAGE/receipt; then
   2.106  		post_remove $root
   2.107  	fi
   2.108  
   2.109  	# Remove package receipt.
   2.110  	gettext "Removing package receipt..."
   2.111 -	rm -rf ${root}${installed}/$PACKAGE
   2.112 +	rm -rf $installed/$PACKAGE
   2.113  	status
   2.114  	sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
   2.115  		${root}${PKGS_DB}/installed.$SUM 2> /dev/null
   2.116 @@ -143,12 +145,12 @@
   2.117  			fi
   2.118  		fi
   2.119  		for i in $refresh; do
   2.120 -			if [ $(wc -l < ${root}${installed}/$i) -gt 1 ]; then
   2.121 +			if [ $(wc -l < $installed/$i) -gt 1 ]; then
   2.122  				gettext "For reinstallation check:"; echo " $installed/$i"
   2.123  				continue
   2.124  			fi
   2.125  			# TODO: use spk-add
   2.126 -			rm -r ${root}${installed}/$i
   2.127 +			rm -r $installed/$i
   2.128  			tazpkg -gi ${i%/modifiers} --forced --root=$root
   2.129  		done
   2.130  	fi
   2.131 @@ -176,7 +178,7 @@
   2.132  		--*) continue
   2.133  	esac
   2.134  	# Be sure package is installed
   2.135 -	if [ ! -f "${root}${installed}/$pkg/receipt" ]; then
   2.136 +	if [ ! -f "$installed/$pkg/receipt" ]; then
   2.137  		echo -n "$(boldify "$pkg") "
   2.138  		gettext "package is not installed"; newline
   2.139  		continue
   2.140 @@ -185,6 +187,7 @@
   2.141  	[ "$count" == 1 ] && newline
   2.142  	boldify $(gettext "Removing"; echo " $pkg")
   2.143  	separator
   2.144 +	[ "$verbose" ] && echo "DB: $installed"
   2.145  	# Handle --confirm
   2.146  	if [ "$confirm" ]; then
   2.147  		gettext "Confirm uninstallation of"; echo -n " $pkg:"