Created
September 16, 2010 13:59
-
-
Save farhaven/582463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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