Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created September 16, 2010 13:59
Show Gist options
  • Save farhaven/582463 to your computer and use it in GitHub Desktop.
Save farhaven/582463 to your computer and use it in GitHub Desktop.
#!/bin/sh
usage(){
cat <<EOF
Usage: $0 [add|del] pkg
add add pkg to the system
del remove pkg from the system
EOF
exit 255
}
[ $# -lt 2 ] && usage
case "$1" in
add)
if [ ! -f "$2.tar.bz2" ]; then
echo "$2.tar.bz2 can not be read"
exit 255
fi
mkdir -p "/pkg/$2"
echo "installing $2"
bzip2 -dc "$2.tar.bz2" | tar xvC / > "/pkg/$2/files"
exit $?
;;
del)
if [ ! -d "/pkg/$2" ]; then
echo "/pkg/$2 does not exist or is not a directory"
exit 255
fi
if [ ! -e "/pkg/$2/files" ]; then
echo "/pkg/$2/files does not exist"
fi
tac "$tmp" | while read f; do
f="/$f"
if [ ! -d "$f" ]; then
rm "$f"
elif [ `find "$f" | wc -l` -eq 0 ]; then
rm -r "$f"
fi
done
rm -rf "/pkg/$2"
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment