[go: up one dir, main page]

Menu

[r4]: / trunk / apk_delete  Maximize  Restore  History

Download this file

71 lines (56 with data), 1.2 kB

#!/bin/sh

VERSION=0.0.9

. ${APKLIBS:="/lib/apk"}/apkfuncs.sh

usage() {
	echo "apk_delete $VERSION" >&2
	echo "usage: apk_delete [ -v ] PACKAGE ..." 2>&1
	exit 1
}

beautify_path() {
	echo $1 | sed 's:/\./::g; s://:/:g'
}

uninstall() {
	local pkgv i p dirs
	pkgv=$1
	decompress_meta $pkgv
	while read i ; do
		p=`beautify_path "$ROOT//$i"`
		if [ -d $p ] ; then
			# save the dir names so we can remove for later
			# it makes no sense removing dirs before files
			dirs="$dirs $p"
		else 
			# here we could check against the sha1 sum to make
			# sure the file is not changed
			rm "$p"
		fi
	done < $APKDB/$pkgv.list

	# remove the dirs
	for i in $dirs; do
		# the dirs is probably not empty so skipp error message
		rmdir $i 2>/dev/null
	done

	# remove the meta files
	rm $APKDB/$pkgv.*
}


set -- `getopt v "$@"`
[ $# -lt 1 ] && exit 1	# getopt failed

while [ $# -gt 0 ] ; do
	case "$1" in
		-v)	vflag=on;;
		--)	shift; break;;
		-*)	usage;;
		*)	break;;		# terminate while loop
	esac
	shift
done


while [ $# -gt 0 ] ; do
	if ! all_installed | grep "^$1" >/dev/null ; then
		echo "$1 not installed" >&2
		exit 1
	else
		[ "$vflag" = "on" ] && echo "removing $1" >&2
		uninstall $1
	fi
	shift
done