tazpkg rev 370

Added --root option to tazpkg remove. Helps me to remove packages in chroot without chrooting into it.
author Christopher Rogers <slaxemulator@gmail.com>
date Fri Oct 29 17:02:32 2010 +0000 (2010-10-29)
parents f9c4712bb590
children b1cbfecc1363
files tazpkg
line diff
     1.1 --- a/tazpkg	Fri Oct 29 15:12:12 2010 +0000
     1.2 +++ b/tazpkg	Fri Oct 29 17:02:32 2010 +0000
     1.3 @@ -1752,23 +1752,36 @@
     1.4  		#
     1.5  		check_root
     1.6  		check_for_package_on_cmdline
     1.7 -		if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
     1.8 +		ROOT=""
     1.9 +		while [ -n "$3" ]; do
    1.10 +			case "$3" in
    1.11 +			--root=*)
    1.12 +				ROOT="${3#--root=}"
    1.13 +				;;
    1.14 +			*)	shift 2
    1.15 +				echo -e "\nUnknown option $*.\n"
    1.16 +				exit 1
    1.17 +				;;
    1.18 +			esac
    1.19 +			shift
    1.20 +		done
    1.21 +		if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
    1.22  			echo ""
    1.23  			eval_gettext "\$PACKAGE is not installed."; echo
    1.24  			exit 0
    1.25  		else
    1.26  			ALTERED=""
    1.27  			THE_PACKAGE=$PACKAGE	# altered by receipt
    1.28 -			for i in $(cd $INSTALLED ; ls); do
    1.29 -				[ -f $INSTALLED/$i/receipt ] || continue
    1.30 +			for i in $(cd $ROOT$INSTALLED ; ls); do
    1.31 +				[ -f $ROOT$INSTALLED/$i/receipt ] || continue
    1.32  				DEPENDS=""
    1.33 -				. $INSTALLED/$i/receipt
    1.34 +				. $ROOT$INSTALLED/$i/receipt
    1.35  				case " $(echo $DEPENDS) " in
    1.36  				*\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
    1.37  				esac
    1.38  			done
    1.39  			EXTRAVERSION=""
    1.40 -			. $INSTALLED/$THE_PACKAGE/receipt
    1.41 +			. $ROOT$INSTALLED/$THE_PACKAGE/receipt
    1.42  		fi
    1.43  		echo ""
    1.44  		if [ -n "$ALTERED" ]; then
    1.45 @@ -1777,7 +1790,7 @@
    1.46  				echo "  $i"
    1.47  			done
    1.48  		fi
    1.49 -		REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
    1.50 +		REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
    1.51  		if [ -n "$REFRESH" ]; then
    1.52  			eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
    1.53  			for i in $REFRESH; do
    1.54 @@ -1791,32 +1804,32 @@
    1.55  			echo -e "\033[1m`gettext \"Removing:\"`\033[0m $PACKAGE"
    1.56  			echo "================================================================================"
    1.57  			# Pre remove commands.
    1.58 -			if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
    1.59 +			if grep -q ^pre_remove $ROOT/$INSTALLED/$PACKAGE/receipt; then
    1.60  				pre_remove
    1.61  			fi
    1.62  			gettext "Removing all files installed..."
    1.63 -			if [ -f $INSTALLED/$PACKAGE/modifiers ]; then
    1.64 -			    for mod in `cat $INSTALLED/$PACKAGE/modifiers`
    1.65 +			if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
    1.66 +			    for mod in `cat $ROOT$INSTALLED/$PACKAGE/modifiers`
    1.67  			    do
    1.68 -				for file in `cat $INSTALLED/$PACKAGE/files.list`
    1.69 +				for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
    1.70  				do
    1.71 -					[ $(grep ^$file$ $INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
    1.72 +					[ $(grep ^$file$ $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
    1.73  					remove_with_path $file
    1.74  				done
    1.75  			    done
    1.76  			else
    1.77 -				for file in `cat $INSTALLED/$PACKAGE/files.list`
    1.78 +				for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
    1.79  				do
    1.80  					remove_with_path $file
    1.81  				done
    1.82  			fi
    1.83  			status
    1.84 -			if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
    1.85 +			if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
    1.86  				post_remove
    1.87  			fi
    1.88  			# Remove package receipt.
    1.89  			gettext "Removing package receipt..."
    1.90 -			rm -rf $INSTALLED/$PACKAGE
    1.91 +			rm -rf $ROOT$INSTALLED/$PACKAGE
    1.92  			status
    1.93  			sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
    1.94  				$LOCALSTATE/installed.md5 2> /dev/null
    1.95 @@ -1827,7 +1840,7 @@
    1.96  				echo -n " (y/N) ? "; read anser
    1.97  				if [ "$anser" = "y" ]; then
    1.98  					for i in $ALTERED; do
    1.99 -						if [ -d "$INSTALLED/$i" ]; then
   1.100 +						if [ -d "$ROOT$INSTALLED/$i" ]; then
   1.101  							tazpkg remove $i
   1.102  						fi
   1.103  					done
   1.104 @@ -1838,11 +1851,11 @@
   1.105  				echo -n " (y/N) ? "; read anser
   1.106  				if [ "$anser" = "y" ]; then
   1.107  					for i in $REFRESH; do
   1.108 -						if [ $(wc -l < $INSTALLED/$i) -gt 1 ]; then
   1.109 +						if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
   1.110  							eval_gettext "Check \$INSTALLED/\$i for reinstallation"; echo
   1.111  							continue
   1.112  						fi
   1.113 -						rm -r $INSTALLED/$i
   1.114 +						rm -r $ROOT$INSTALLED/$i
   1.115  						tazpkg get-install ${i%/modifiers} --forced
   1.116  					done
   1.117  				fi