Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created October 20, 2010 14:56
Show Gist options
  • Save farhaven/636578 to your computer and use it in GitHub Desktop.
Save farhaven/636578 to your computer and use it in GitHub Desktop.
#!/bin/sh
usage(){
cat <<EOF
Usage: $0 [add|del] [-n] pkg
add add pkg to the system
-n don't update already installed pkg
del remove pkg from the system
set \$PKG_ROOT to the root of the file system you want $0 to operate on
EOF
exit 255
}
[ $# -lt 2 ] && usage
op=
update="true"
pkg=
for p in "$@"; do
case "$p" in
add)
op="add"
;;
del)
op="del"
;;
-n)
update="false"
;;
*)
pkg="$p"
;;
esac
done
if [ ! -d "$PKG_ROOT/pkg" ]; then
echo "$PKG_ROOT/pkg does not exist. This most likely means you might now want to install into $PKG_ROOT."
echo "Sleeping 10 seconds, hit ^C to abort."
n=10
while [ $n -gt 0 ]; do
sleep 1
echo -n "."
n=`expr $n - 1`
done
echo
fi
case "$op" in
add)
if [ ! -f "$pkg/data.tar.bz2" ]; then
echo "$pkg/data.tar.bz2 can not be read"
exit 255
fi
if [ -d "$PKG_ROOT/pkg/$pkg" -a "$update" == "false" ]; then
exit 255
fi
mkdir -p "$PKG_ROOT/pkg/`basename $pkg`"
echo "installing $pkg"
if [ -f "$pkg/deps" ]; then
while read d; do
$0 add `dirname $pkg`/`basename "$d"`
done < "$pkg/deps"
fi
bzip2 -dc "$pkg/data.tar.bz2" | tar xvC "$PKG_ROOT/" > "$PKG_ROOT/pkg/`basename $pkg`/files"
exit $?
;;
del)
if [ ! -d "$PKG_ROOT/pkg/$pkg" ]; then
echo "$PKG_ROOT/pkg/$pkg does not exist or is not a directory"
exit 255
fi
if [ ! -e "$PKG_ROOT/pkg/$pkg/files" ]; then
echo "$PKG_ROOT/pkg/$pkg/files does not exist"
fi
tac "$PKG_ROOT/pkg/$pkg/files" | 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_ROOT/pkg/$pkg"
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment