From 17ab178cdd30e09eb1368971b26841d24dc6e164 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 22 Aug 2020 23:34:05 +0200 Subject: [PATCH] more improvements - payload now extracts in the right location - payload checks if the file is already extracted - etc. --- .gitignore | 3 +-- posix/preload | 30 +++++++++++++++++++----------- posix/prepare | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 7039b0b..d3745c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -**/pcmi/** -**/badwolf/** +tests/** diff --git a/posix/preload b/posix/preload index a07bd1c..6adafff 100755 --- a/posix/preload +++ b/posix/preload @@ -1,19 +1,27 @@ #!/bin/sh -e # TODO: verify checksum before extracting -# SUM # TODO: extract self without resolving to $0 because it doesn't resolve links -tail -c +"$(expr BYTES + 1)" $0 | lz4 -dc | tar -x -# TODO: remove hardcoded directory -# TODO: use a different extraction path -cd ID -export ORIGIN="$(pwd)" -export LD_LIBRARY_PATH="$ORIGIN/lib" -export PATH="$ORIGIN/bin":$PATH +if [ -z "$XDG_CACHE_HOME" ]; then + destdir=/tmp +else + destdir="$XDG_CACHE_HOME" +fi -#export LD_DEBUG='libs' +if ! [ "$(head -n 1 "$destdir"/ID/checksum 2>/dev/null)" = 'SUM' ]; then + tail -c +BYTES "$0" | lz4 -dc | tar -x -C "$destdir" + echo "SUM" > "$destdir"/ID/checksum +fi + +ORIGIN="$destdir"/ID +LD_LIBRARY_PATH="$ORIGIN/lib" +PATH="$ORIGIN/bin":$PATH +export ORIGIN +export LD_LIBRARY_PATH +export PATH + +# export LD_DEBUG='libs' # TODO: use $0 instead -# FIXME: uses the system's basename -exec bin/"$(basename "$1")" +exec "$destdir"/ID/bin/"$(basename "$1")" diff --git a/posix/prepare b/posix/prepare index dde0a3a..f160d29 100755 --- a/posix/prepare +++ b/posix/prepare @@ -148,7 +148,7 @@ awk '!/^ *#/ && NF' > tpp size="$(wc -c tpp | cut -d " " -f1)" strsize="$(echo "BYTES" | wc -c)" numsize="$(echo "$size" | wc -c)" -normsize="$((size - (strsize - numsize)))" +normsize="$((size - (strsize - numsize) + 1))" sed s/BYTES/"$normsize"/ tpp > tpr cat tpr "$DIRNAME".tar.lz4 > "$DIRNAME".ti