spk rev 13

spk-rm: almost finished and works fine
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 10:11:54 2012 +0200 (2012-05-15)
parents 8517989e8588
children dcf6700bb045
files spk-rm
line diff
     1.1 --- a/spk-rm	Sun May 13 13:42:38 2012 +0100
     1.2 +++ b/spk-rm	Tue May 15 10:11:54 2012 +0200
     1.3 @@ -21,21 +21,144 @@
     1.4  $(boldify $(gettext "Usage:")) $name [packages|--options]
     1.5  
     1.6  $(boldify $(gettext "Options:"))
     1.7 +  --confirm   $(gettext "Ask before removing any packages")
     1.8 +  --verbose   $(gettext "Be more verbose when removing files")
     1.9  
    1.10  $(boldify $(gettext "Examples:"))
    1.11 -  $name nano clex leafpad
    1.12 -  $name nano clex --confirm
    1.13 +  $name package1 package2 packagesN
    1.14 +  $name package1 --confirm --verbose
    1.15  
    1.16  EOT
    1.17  	exit 0
    1.18  }
    1.19  
    1.20 +# Avoid dirname errors by checking for argument anf then remove file and
    1.21 +# empty directory. Usage: remove_file file
    1.22 +remove_file() {
    1.23 +	[ "$1" ] || return
    1.24 +	local dir
    1.25 +	rm -f $1 2>/dev/null
    1.26 +	dir="$1"
    1.27 +	while [ "$dir" != "/" ]; do
    1.28 +		dir="$(dirname $dir)"
    1.29 +		rmdir $dir 2> /dev/null || break
    1.30 +	done
    1.31 +}
    1.32 +
    1.33 +# Remove a single package
    1.34 +remove() {
    1.35 +	altered=""
    1.36 +	for i in $(cd ${root}${installed} ; ls); do
    1.37 +		[ -f ${root}${installed}/$i/receipt ] || continue
    1.38 +		unset_receipt
    1.39 +		. ${root}${installed}/$i/receipt
    1.40 +		case " $(echo $DEPENDS) " in
    1.41 +			*\ $pkg\ *) altered="$altered $i" ;;
    1.42 +		esac
    1.43 +	done
    1.44 +	unset_receipt
    1.45 +	. ${root}${installed}/$pkg/receipt
    1.46 +
    1.47 +	if [ -n "$altered" ]; then
    1.48 +		eval_gettext "The following packages depend on \$PACKAGE:"; echo
    1.49 +		for i in $altered; do
    1.50 +			echo "  $i"
    1.51 +		done
    1.52 +	fi
    1.53 +	refresh=$(cd ${root}${installed} ; grep -sl ^$PACKAGE$ */modifiers)
    1.54 +	if [ -n "$refresh" ]; then
    1.55 +		eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
    1.56 +		for i in $refresh; do
    1.57 +			echo "  ${i%/modifiers}"
    1.58 +		done
    1.59 +	fi
    1.60 +
    1.61 +	# Do we have packages depending on $pkg ?
    1.62 +	if [ "$altered" ]; then
    1.63 +		if [ "$confirm" ]; then
    1.64 +			gettext "Remove packages depending on:"; echo -n " $PACKAGE"
    1.65 +			if ! confirm; then
    1.66 +				gettext "Keeping packages depending on:"; echo " $PACKAGE"
    1.67 +				echo -e "\n" && continue
    1.68 +			fi
    1.69 +		fi
    1.70 +		for i in $altered; do
    1.71 +			if [ -d "${root}${installed}/$i" ]; then
    1.72 +				# TODO: use spk-rm
    1.73 +				echo "tazpkg remove $i --root=$root"
    1.74 +			fi
    1.75 +		done
    1.76 +	fi
    1.77 +
    1.78 +	# Handle pre_remove
    1.79 +	if grep -q ^pre_remove ${root}${installed}/$PACKAGE/receipt; then
    1.80 +		pre_remove $root
    1.81 +	fi
    1.82 +
    1.83 +	# Remove all files
    1.84 +	gettext "Removing all installed files..."
    1.85 +	[ "$verbose" ] && newline
    1.86 +	if [ -f ${root}${installed}/$PACKAGE/modifiers ]; then
    1.87 +	    for file in `cat ${root}${installed}/$PACKAGE/files.list`
    1.88 +	    do
    1.89 +			for mod in `cat ${root}${installed}/$PACKAGE/modifiers`
    1.90 +			do
    1.91 +				[ -f ${root}${installed}/$mod/files.list ] && \
    1.92 +					[ $(grep "^$(echo $file | grepesc)$" ${root}${installed}/$mod/files.list | wc -l) -gt 1 ] \
    1.93 +					&& continue 2
    1.94 +			done
    1.95 +			[ "$verbose" ] && gettext "Removing:"; echo -n " ${root}${file}"
    1.96 +			remove_file ${root}${file}
    1.97 +	    done
    1.98 +	else
    1.99 +		for file in $(cat ${root}${installed}/$PACKAGE/files.list)
   1.100 +		do
   1.101 +			[ "$verbose" ] && gettext "Removing:"; echo -n " ${root}${file}"
   1.102 +			remove_file ${root}${file}
   1.103 +			[ "$verbose" ] && status
   1.104 +		done
   1.105 +	fi
   1.106 +	[ "$verbose" ] || status
   1.107 +
   1.108 +	# Handle post_remove
   1.109 +	if grep -q ^post_remove ${root}${installed}/$PACKAGE/receipt; then
   1.110 +		post_remove $root
   1.111 +	fi
   1.112 +
   1.113 +	# Remove package receipt.
   1.114 +	gettext "Removing package receipt..."
   1.115 +	rm -rf ${root}${installed}/$PACKAGE
   1.116 +	status
   1.117 +	sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
   1.118 +		${root}${PKGS_DB}/installed.$SUM 2> /dev/null
   1.119 +
   1.120 +	# Mofified ?
   1.121 +	if [ "$refresh" ]; then
   1.122 +		if [ "$confirm" ]; then
   1.123 +			gettext "Reinstall packages modified by:"; echo " $PACKAGE"
   1.124 +			if ! confirm; then
   1.125 +				gettext "Keeping packages modified by:"; echo " $PACKAGE"
   1.126 +				echo -e "\n" && continue
   1.127 +			fi
   1.128 +		fi
   1.129 +		for i in $refresh; do
   1.130 +			if [ $(wc -l < ${root}${installed}/$i) -gt 1 ]; then
   1.131 +				gettext "For reinstallation check:"; echo " $installed/$i"
   1.132 +				continue
   1.133 +			fi
   1.134 +			# TODO: use spk-add
   1.135 +			rm -r ${root}${installed}/$i
   1.136 +			tazpkg -gi ${i%/modifiers} --forced --root=$root
   1.137 +		done
   1.138 +	fi
   1.139 +}
   1.140 +
   1.141  #
   1.142  # Commands and exit
   1.143  #
   1.144  
   1.145  case "$1" in
   1.146 -	""|usage|help) usage && exit 0 ;;
   1.147 +	""|usage|help) usage ;;
   1.148  esac
   1.149  
   1.150  #
   1.151 @@ -47,20 +170,31 @@
   1.152  
   1.153  for pkg in $@
   1.154  do
   1.155 -	[ -d "$installed/$pkg" ] || continue
   1.156 +	# Skip options
   1.157 +	case "$pkg" in
   1.158 +		--*) continue
   1.159 +	esac
   1.160 +	# Be sure package is installed
   1.161 +	if [ ! -f "${root}${installed}/$pkg/receipt" ]; then
   1.162 +		echo -n "$(boldify "$pkg") "
   1.163 +		gettext "package is not installed"; newline
   1.164 +		continue
   1.165 +	fi
   1.166  	count=$(($count + 1))
   1.167 -	[ "$count" == 1 ] && echo ""
   1.168 -	gettext "Removing"; echo " $pkg"
   1.169 +	[ "$count" == 1 ] && newline
   1.170 +	boldify $(gettext "Removing"; echo " $pkg")
   1.171  	separator
   1.172  	# Handle --confirm
   1.173  	if [ "$confirm" ]; then
   1.174  		gettext "Confirm uninstallation of"; echo -n " $pkg:"
   1.175  		if ! confirm; then
   1.176  			gettext "Uninstallation cancelled"
   1.177 -			echo -e "\n" && exit 0
   1.178 +			echo -e "\n" && continue
   1.179  		fi
   1.180  	fi
   1.181 -	gettext "TODO"; echo
   1.182 +	remove
   1.183 +	separator
   1.184 +	echo "" && log "Removed package: $pkg"
   1.185  done
   1.186  
   1.187  exit 0