#!/tools/bin/bash NAME=$1 VERSION=$2 if [ -z $NAME ]; then echo "[e] Please provide a package name.">&2 exit 1 fi VERSIONS="/usr/dafuq/packages/$NAME-*" if [ -z $VERSIONS ]; then echo "[e] Cannot find package.">&2 exit 1 fi echo "[i] Available versions:" i=0 for version in $VERSIONS; do echo " [$i] $version" i=$(expr $i + 1) done if [ $i == "1" ]; then VERSION=$VERSIONS elif [ -z $VERSION ]; then echo "[e] Please provide a version number.">&2 exit 1 else VERSION=$(echo $VERSIONS | cut -d" " -f $(expr $VERSION + 1)) if [ -z $VERSION ]; then echo "[e] Incorrect version number.">&2 exit 1 fi fi INSTALLED_VERSIONS=/usr/dafuq/installed/$NAME-* if test -n "$(shopt -s nullglob; echo $INSTALLED_VERSIONS)"; then echo "[e] Following version(s) of package already installed:" for version in $INSTALLED_VERSIONS; do echo " $(echo $version | sed -e "s,/usr/dafuq/installed/,,")" done exit 1 fi echo "[i] Checking for collisions..." MANIFEST=$(tar xfO $VERSION manifest) while read -r line; do linetype=$(echo $line | cut -d":" -f 1) if [ $linetype == "file" ]; then filename=$(echo $line | cut -d" " -f 2) if [ -e $filename ]; then echo "[e] File exists in filesystem: $filename" exit 1 fi fi done <<< "$MANIFEST" echo "[i] Installing..." tar xfp $VERSION -C / --transform 's,^root/,,' --transform 's,^root,,' --show-transformed root/ ln -s $VERSION $(echo $VERSION | sed -e "s,/usr/dafuq/packages/,/usr/dafuq/installed/,") echo "[i] Done."