apk-tools Code
Brought to you by:
ncopa
#!/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
cd $ROOT
sha1sum -c $APKDB/$pkgv.sha1 | awk -F : '/OK$/ {print $1}' |
while read i ; do
[ "$vflag" ] && echo "<<< $i"
rm "$i"
done
sort -r $APKDB/$pkgv.list | while read i ; do
p=`beautify_path "$ROOT//$i"`
[ -d "$p" ] && rmdir "$p" 2>/dev/null && [ "$vflag" ] && echo "<<< $p"
done
# 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="-v";;
--) 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" ] && echo "removing $1" >&2
uninstall $1
fi
shift
done