mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(appimage): catalog AppImages start without proot (#3077)
* fix(appimage): catalog AppImages start without proot * fix(appimage): cache cleanup does not follow symlinked entries * fix(appimage): keep unpacked copies in use and track subsecond changes * fix(appimage): extract native images through an open descriptor --------- Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
1 parent
39debda0b0
commit
cf44aaed14
4 files changed
+246
-5
No files matched your search
@@ -9,6 +9,40 @@ if [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
3|62) exec /usr/local/bin/droiddeck-fex run --mode on -- "$image" "$@" ;;
|
||||
esac
|
||||
fi
|
||||
if [ -n "${DDNATV_ROOT:-}" ]; then
|
||||
image=$(realpath -- "$image") || exit 127
|
||||
cache=${XDG_CACHE_HOME:-${HOME:-/root}/.cache}/droiddeck-appimage
|
||||
mkdir -p "$cache" || exit 1
|
||||
exec 9>"$cache/.lock"
|
||||
flock 9 || exit 1
|
||||
state() { printf '%s\n%s' "$1" "$(TZ=UTC0 stat -Lc '%s %y' -- "$1" 2>/dev/null)"; }
|
||||
for dir in "$cache"/*/; do
|
||||
dir=${dir%/}
|
||||
[ ! -L "$dir" ] && [ -f "$dir/source" ] || continue
|
||||
[ "$(cat "$dir/source")" = "$(state "$(head -n 1 "$dir/source")")" ] && continue
|
||||
(flock -n 7 && rm -rf -- "${dir:?}") 7<"$dir/source"
|
||||
done
|
||||
find "$cache" -mindepth 1 -maxdepth 1 -name '.unpack.*' -mmin +60 -exec rm -rf -- {} + 2>/dev/null
|
||||
source=$(state "$image")
|
||||
unpacked=$cache/$(printf '%s' "$source" | md5sum | cut -c1-16)
|
||||
if [ "$(cat "$unpacked/source" 2>/dev/null)" != "$source" ] || [ ! -e "$unpacked/squashfs-root/AppRun" ]; then
|
||||
echo "== appimage: unpacking $image"
|
||||
work=$(mktemp -d "$cache/.unpack.XXXXXX") || exit 1
|
||||
if ! (cd "$work" && /usr/local/bin/droiddeck-fex extract "$image") || [ ! -e "$work/squashfs-root/AppRun" ]; then
|
||||
rm -rf -- "${work:?}"
|
||||
echo "droiddeck-appimage-exec: could not unpack $image" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' "$source" > "$work/source"
|
||||
rm -rf -- "${unpacked:?}"
|
||||
mv -- "$work" "$unpacked" || exit 1
|
||||
fi
|
||||
exec 8<"$unpacked/source"
|
||||
flock -s 8 || exit 1
|
||||
exec 9>&-
|
||||
export APPIMAGE=$image APPDIR=$unpacked/squashfs-root ARGV0=$image OWD=$PWD
|
||||
exec "$APPDIR/AppRun" "$@"
|
||||
fi
|
||||
if [ -x /usr/local/lib/droiddeck/uruntime ]; then
|
||||
export TARGET_APPIMAGE=$image
|
||||
exec /usr/local/lib/droiddeck/uruntime "$@"
|
||||
|
||||
@@ -851,8 +851,12 @@ def extract(image):
|
||||
clear_extracted()
|
||||
x86 = elf_arch(image) in X86.values()
|
||||
if os.access(URUNTIME, os.X_OK):
|
||||
run = subprocess.run([URUNTIME, "--appimage-extract"], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
env=dict(os.environ, TARGET_APPIMAGE=image))
|
||||
with open(image, "rb") as source:
|
||||
native = bool(os.environ.get("DDNATV_ROOT"))
|
||||
target = "/proc/self/fd/%d" % source.fileno() if native else image
|
||||
run = subprocess.run([URUNTIME, "--appimage-extract"], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
env=dict(os.environ, TARGET_APPIMAGE=target),
|
||||
pass_fds=(source.fileno(),) if native else ())
|
||||
errors = run.stderr.decode("utf-8", "replace")
|
||||
sys.stderr.write(errors)
|
||||
status = run.returncode
|
||||
@@ -882,7 +886,17 @@ def extract(image):
|
||||
want_fex()
|
||||
return 0
|
||||
say("unsquashfs could not extract it (status %d)" % status)
|
||||
elif fex is None:
|
||||
seven = shutil.which("7z")
|
||||
if seven:
|
||||
clear_extracted()
|
||||
status = subprocess.call([seven, "x", "-tSquashFS", "-y", "-osquashfs-root", image], stdout=subprocess.DEVNULL)
|
||||
if status == 0 and extracted():
|
||||
if x86:
|
||||
want_fex()
|
||||
return 0
|
||||
say("7-Zip could not extract it (status %d)" % status)
|
||||
clear_extracted()
|
||||
elif fex is None and not unsquashfs:
|
||||
say("this AppImage could not be unpacked here: no AppImage runtime for ARM64, no FEX yet and no unsquashfs")
|
||||
return 1
|
||||
|
||||
|
||||
Reference in new issue
Block a user