appimage: replace radare2+jq with readelf+awk+sha256sum
radare2 does not play nicely with filenames containing spaces https://github.com/radareorg/radare2/issues/16958
This commit is contained in:
parent
d190eca583
commit
9444756222
2 changed files with 86 additions and 73 deletions
|
@ -6,58 +6,55 @@ fi
|
||||||
PATH="@path@:$PATH"
|
PATH="@path@:$PATH"
|
||||||
apprun_opt=true
|
apprun_opt=true
|
||||||
|
|
||||||
#DEBUG=0
|
|
||||||
|
|
||||||
# src : AppImage
|
# src : AppImage
|
||||||
# dest : let's unpack() create the directory
|
# dest : let's unpack() create the directory
|
||||||
unpack() {
|
unpack() {
|
||||||
local src=$1
|
local src="$1"
|
||||||
local out=$2
|
local out="$2"
|
||||||
local appimageSignature=""
|
|
||||||
local appimageType=0
|
|
||||||
|
|
||||||
# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
|
# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
|
||||||
eval "$(r2 -nn -Nqc "p8j 3 @ 8" "$src"|
|
local appimageSignature=$(readelf -h "$src" | awk 'NR==2{print $10$11;}')
|
||||||
jq -r '{appimageSignature: (.[:-1]|implode), appimageType: .[-1]}|
|
local appimageType=$(readelf -h "$src" | awk 'NR==2{print $12;}')
|
||||||
@sh "appimageSignature=\(.appimageSignature) appimageType=\(.appimageType)"')"
|
|
||||||
|
|
||||||
# check AppImage signature
|
# check AppImage signature
|
||||||
if [[ "$appimageSignature" != "AI" ]]; then
|
if [ "$appimageSignature" != "4149" ]; then
|
||||||
echo "Not an appimage."
|
echo "Not an AppImage file"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$appimageType" in
|
case "$appimageType" in
|
||||||
1 ) echo "Uncompress $(basename "$src") of type $appimageType."
|
"01")
|
||||||
mkdir "$out"
|
echo "Uncompress $(basename "$src") of type $appimageType"
|
||||||
pv "$src" | bsdtar -x -C "$out" -f -
|
mkdir "$out"
|
||||||
;;
|
pv "$src" | bsdtar -x -C "$out" -f -
|
||||||
2)
|
;;
|
||||||
# This method avoid issues with non executable appimages,
|
|
||||||
# non-native packer, packer patching and squashfs-root destination prefix.
|
|
||||||
|
|
||||||
# multiarch offset one-liner using same method as AppImage
|
"02")
|
||||||
# see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
|
# This method avoid issues with non executable appimages,
|
||||||
offset=$(r2 -nn -Nqc "pfj.elf_header @ 0" "$src"|\
|
# non-native packer, packer patching and squashfs-root destination prefix.
|
||||||
jq 'map({(.name): .value}) | add | .shoff + (.shnum * .shentsize)')
|
|
||||||
|
|
||||||
echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset."
|
# multiarch offset one-liner using same method as AppImage
|
||||||
unsquashfs -q -d "$out" -o "$offset" "$src"
|
# see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
|
||||||
chmod go-w "$out"
|
offset=$(readelf -h "$src" | awk 'NR==13{e_shoff=$5} NR==18{e_shentsize=$5} NR==19{e_shnum=$5} END{print e_shoff+e_shentsize*e_shnum}')
|
||||||
;;
|
echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset"
|
||||||
|
unsquashfs -q -d "$out" -o "$offset" "$src"
|
||||||
|
chmod go-w "$out"
|
||||||
|
;;
|
||||||
|
|
||||||
# 3) get ready, https://github.com/TheAssassin/type3-runtime
|
# "03")
|
||||||
*) echo Unsupported AppImage Type: "$appimageType"
|
# get ready, https://github.com/TheAssassin/type3-runtime
|
||||||
exit
|
|
||||||
;;
|
*)
|
||||||
|
echo Unsupported AppImage Type: "$appimageType"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
echo "$(basename "$src") is now installed in $out"
|
echo "$(basename "$src") is now installed in $out"
|
||||||
}
|
}
|
||||||
|
|
||||||
apprun() {
|
apprun() {
|
||||||
|
|
||||||
eval "$(rahash2 "$APPIMAGE" -j | jq -r '.[] | @sh "SHA256=\(.hash)"')"
|
SHA256=$(sha256sum "$APPIMAGE" | awk '{print $1}')
|
||||||
echo sha256 = \""$SHA256"\"\;
|
|
||||||
export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256"
|
export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256"
|
||||||
|
|
||||||
#compatibility
|
#compatibility
|
||||||
|
@ -102,27 +99,26 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "x:w:dh" option; do
|
while getopts "x:w:dh" option; do
|
||||||
case "${option}" in
|
case "${option}" in
|
||||||
d) set -x
|
d) set -x
|
||||||
;;
|
;;
|
||||||
x) # eXtract
|
x) # eXtract
|
||||||
unpack_opt=true
|
unpack_opt=true
|
||||||
APPDIR=${OPTARG}
|
APPDIR=${OPTARG}
|
||||||
;;
|
;;
|
||||||
w) # WrapAppImage
|
w) # WrapAppImage
|
||||||
export APPDIR=${OPTARG}
|
export APPDIR=${OPTARG}
|
||||||
wrap_opt=true
|
wrap_opt=true
|
||||||
;;
|
;;
|
||||||
h) usage
|
h) usage
|
||||||
;;
|
;;
|
||||||
*)
|
*) usage
|
||||||
usage
|
;;
|
||||||
;;
|
esac
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
shift "$((OPTIND-1))"
|
||||||
|
|
||||||
if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then
|
if [ -n "$wrap_opt" ] && [ -d "$APPDIR" ]; then
|
||||||
wrap "$@"
|
wrap "$@"
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
|
@ -130,12 +126,12 @@ else
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
|
if [ -n "$unpack_opt" ] && [ -f "$APPIMAGE" ]; then
|
||||||
unpack "$APPIMAGE" "$APPDIR"
|
unpack "$APPIMAGE" "$APPDIR"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
|
if [ -n "$apprun_opt" ] && [ -f "$APPIMAGE" ]; then
|
||||||
apprun
|
apprun
|
||||||
wrap "$@"
|
wrap "$@"
|
||||||
exit
|
exit
|
||||||
|
|
|
@ -1,40 +1,57 @@
|
||||||
{ stdenv, buildFHSUserEnv, writeScript, pkgs
|
{ stdenv
|
||||||
, bash, radare2, jq, squashfsTools, ripgrep
|
, bash
|
||||||
, coreutils, libarchive, file, runtimeShell, pv
|
, binutils-unwrapped
|
||||||
, lib, runCommand }:
|
, coreutils
|
||||||
|
, gawk
|
||||||
|
, libarchive
|
||||||
|
, pv
|
||||||
|
, squashfsTools
|
||||||
|
, buildFHSUserEnv
|
||||||
|
, pkgs
|
||||||
|
}:
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
appimage-exec = pkgs.substituteAll {
|
appimage-exec = pkgs.substituteAll {
|
||||||
src = ./appimage-exec.sh;
|
src = ./appimage-exec.sh;
|
||||||
isExecutable = true;
|
isExecutable = true;
|
||||||
dir = "bin";
|
dir = "bin";
|
||||||
path = with pkgs; lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];
|
path = with pkgs; stdenv.lib.makeBinPath [
|
||||||
|
bash
|
||||||
|
binutils-unwrapped
|
||||||
|
coreutils
|
||||||
|
gawk
|
||||||
|
libarchive
|
||||||
|
pv
|
||||||
|
squashfsTools
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
extract = { name, src }: runCommand "${name}-extracted" {
|
extract = { name, src }: pkgs.runCommand "${name}-extracted" {
|
||||||
buildInputs = [ appimage-exec ];
|
buildInputs = [ appimage-exec ];
|
||||||
} ''
|
} ''
|
||||||
appimage-exec.sh -x $out ${src}
|
appimage-exec.sh -x $out ${src}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# for compatibility, deprecated
|
# for compatibility, deprecated
|
||||||
extractType1 = extract;
|
extractType1 = extract;
|
||||||
extractType2 = extract;
|
extractType2 = extract;
|
||||||
wrapType1 = wrapType2;
|
wrapType1 = wrapType2;
|
||||||
|
|
||||||
wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv (defaultFhsEnvArgs // {
|
wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv
|
||||||
inherit name;
|
(defaultFhsEnvArgs // {
|
||||||
|
inherit name;
|
||||||
|
|
||||||
targetPkgs = pkgs: [ appimage-exec ]
|
targetPkgs = pkgs: [ appimage-exec ]
|
||||||
++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
||||||
|
|
||||||
runScript = "appimage-exec.sh -w ${src}";
|
runScript = "appimage-exec.sh -w ${src}";
|
||||||
} // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage))));
|
} // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage))));
|
||||||
|
|
||||||
wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // {
|
wrapType2 = args@{ name, src, extraPkgs ? pkgs: [ ], ... }: wrapAppImage
|
||||||
inherit name extraPkgs;
|
(args // {
|
||||||
src = extract { inherit name src; };
|
inherit name extraPkgs;
|
||||||
});
|
src = extract { inherit name src; };
|
||||||
|
});
|
||||||
|
|
||||||
defaultFhsEnvArgs = {
|
defaultFhsEnvArgs = {
|
||||||
name = "appimage-env";
|
name = "appimage-env";
|
||||||
|
|
Loading…
Reference in a new issue