Basic functionality.

master
q3k 2012-11-19 13:24:39 +01:00
commit 6276eafcbf
3 changed files with 158 additions and 0 deletions

58
bin/dafuq-install Executable file
View File

@ -0,0 +1,58 @@
#!/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."

46
bin/dafuq-make Executable file
View File

@ -0,0 +1,46 @@
#!/tools/bin/bash
NAME=$1
DESTDIR=/tmp/dafuq/$NAME/root
INSTALLCMD="make install DESTDIR=$DESTDIR"
if [ ! -z "$2" ]; then
INSTALLCMD=$(echo "$2" | sed -e "s:%DESTDIR%:$DESTDIR:g")
echo "[i] Custom installation command: $INSTALLCMD"
fi
rm -rf /tmp/dafuq/$NAME 2>/dev/null
echo "[i] Packaging $NAME..."
mkdir -p $DESTDIR
echo "[i] Making..."
/tools/bin/bash -c "$INSTALLCMD"
echo "[i] Taking note of directories..."
PKG_DIRS=$(find $DESTDIR -type d)
PKG_DIRS_CREATE=""
for dir in $PKG_DIRS; do
dir_root=$(echo $dir | sed -e "s:$DESTDIR::g")
if [ ! -e $dir_root ]; then
PKG_DIRS_CREATE="$PKG_DIRS_CREATE $dir_root"
fi
done
echo "[i] Taking note of files..."
PKG_FILES=$(find $DESTDIR -type f -o -type l)
echo "[i] Creating manifest..."
PKG_MANIFEST="/tmp/dafuq/$NAME/manifest"
echo "name: $NAME" >> $PKG_MANIFEST
echo "installcmd: $INSTALLCMD" >> $PKG_MANIFEST
echo "built: $(date)" >> $PKG_MANIFEST
for dir in $PKG_DIRS_CREATE; do
echo "dir: $dir" >> $PKG_MANIFEST
done
for f in $PKG_FILES; do
echo "file: $(echo $f | sed -e "s:$DESTDIR::g") $(sha256sum $f | cut -d" " -f 1) $(stat -c "%a %U:%G" $f)" >> $PKG_MANIFEST
done
echo "[i] Compressing package..."
tar cJf /usr/dafuq/packages/$NAME.tar.xz -C /tmp/dafuq/$NAME manifest root
echo "[i] Cleaning up..."
rm -rf /tmp/dafuq/$NAME 2>/dev/null
echo "[i] Done."

54
bin/dafuq-remove Executable file
View File

@ -0,0 +1,54 @@
#!/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/installed/$NAME-*"
if [ -z $VERSIONS ]; then
echo "[e] Cannot find package.">&2
exit 1
fi
echo "[i] Installed 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
echo "[i] Removing files..."
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 "[w] File missing from filesystem: $filename"
exit 1
fi
rm $filename
fi
done <<< "$MANIFEST"
while read -r line; do
linetype=$(echo $line | cut -d":" -f 1)
if [ $linetype == "dir" ]; then
rmdir $(echo $line | cut -d" " -f 2)
fi
done <<< "$MANIFEST"
rm $(echo $VERSION | sed -e "s,/usr/dafuq/packages/,/usr/dafuq/installed/,")
echo "[i] Done."