Skip to content

Commit

Permalink
initial thepkg
Browse files Browse the repository at this point in the history
  • Loading branch information
denisde4ev committed Jan 12, 2022
1 parent 5639c6e commit ff6e85f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions thepkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
THEPKG_PREFIX=/data/data/com.termux/files/home/0/thepkg/test

log() { printf %s\\n " -> $*"; }
err() { i=$?; printf %s\\n >&2 " x> $*"; exit $i; }

set -ue
<<:
"${THEPKG_PREFIX=/}"\
"${THEPKG_DBPATH=$THEPKG_PREFIX/var/db/thepkg}"\
:
unset pkgname

case $1 in
add)
case $2 in -) set -- add "$(mktemp)"; cat > "$2"; esac
# hope we wont get muliple lines/packages in grep
pkgname=$(
tar tf "$2" | grep -x "${THEPKG_DBPATH#"$THEPKG_PREFIX/"}"'/[^/]*/version'
) || err "Not a valid thepkg package"
pkgname=${pkgname%/version}
pkgname=${pkgname##*/}

[ ! -e "$THEPKG_DBPATH/${pkgname:?}" ] || \
err "The pkg '$pkgname' is already installed"

log "Extracting the pkg '$pkgname'..."
tar xf "$2" -C "$THEPKG_PREFIX"
tar tf "$2" | sort -r >"$THEPKG_PREFIX/$pkgname"/manifest
;;
del)
cd "$THEPKG_PREFIX" || exit
log "Removing the pkg '$2'..."
while IFS= read -r file; do
case $file in
*/)
rmdir "$file" 2>/dev/null||:
;;
*)
rm "$file"
;;
esac
done <"$THEPKG_DBPATH"/"$2"/manifest
rm "$THEPKG_DBPATH"/"$2"/manifest
rmdir "$THEPKG_DBPATH"/"$2"
esac

0 comments on commit ff6e85f

Please sign in to comment.