Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appimage-run: unify appimageTools and appimage-run #81833

Merged
merged 6 commits into from Mar 9, 2020

Conversation

bignaux
Copy link
Contributor

@bignaux bignaux commented Mar 5, 2020

Motivation for this change

appimage-run :

  • doesn't patchelf the appimage packer (?) so not using it using appimageTools method would prevent issue.
  • share same unpack/autopatchelf/... needs that appimageTools.
  • separate shell script let me fix with linter ( for example fi missing ), add custom hooks etc.

/home/genesis/tmp/''/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/AppRun: line 101: 10002 Segmentation fault (core dumped) pidof appimaged 2> /dev/null

avoiding AppRun in both would avoid such useless issue, as issue on packer. I'm working on it too.

one goal here is provide an improved appimage-run closer to appimageTools so the first really help to package with the second.

Things done
  • unify both using a common shell script
  • rewrite a clean? cmdline option parsing via getopts
  • unify output of unpacking job
  • simplify appimage-run that it could now be merge in appimageTools (some comment?)
  • shellcheck checked!
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

cc @tilpner
cc @timokau
cc @jtojnar
cc @volth

@bignaux bignaux changed the title [WIP] : unify appimagetool and appimage-run [WIP] : unify appimageTools and appimage-run Mar 6, 2020
@bignaux bignaux changed the title [WIP] : unify appimageTools and appimage-run appimage-run: unify appimageTools and appimage-run Mar 7, 2020
@probonopd
Copy link

Just for the avoidance of doubt, the payload applications inside different AppImages may require the AppRun scripts do do various things, such as setting certain environment variables, in order for them to work. So I don't think there is a "one size fits all" solution to run all the payload applications in all the AppImages out there while ignoring their AppRun scripts.

@bignaux
Copy link
Contributor Author

bignaux commented Mar 7, 2020

To help people figure out what AppRun setup in the env, i start write some appimage-run hook, here an example :

    [genesis@genlaptop:~/tmp]$ appimage-run pcloud
    sha256 = "37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6";
    pcloud installed in /home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root
    ./AppRun: ligne 141: grep : commande introuvable
    ./AppRun: ligne 142: grep : commande introuvable
    exec=/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/pcloud
    Down: Everything Downloaded| Up: Everything Uploaded, status is LOGIN_REQUIRED
    Update for linux-x64-prod-v1.7.2 is not available
    diff /tmp/tmp.lBqONdMRR5 /tmp/tmp.YxPdJZftPm
     
    [genesis@genlaptop:~/tmp]$ diff /tmp/tmp.lBqONdMRR5 /tmp/tmp.YxPdJZftPm
    18a19
    > GSETTINGS_SCHEMA_DIR=/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/share/glib-2.0/schemas:
    32c33
    < LD_LIBRARY_PATH=/run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:/run/opengl-driver/lib:/run/opengl-driver-32/lib
    ---
    > LD_LIBRARY_PATH=/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:/run/opengl-driver/lib:/run/opengl-driver-32/lib
    53c54
    < PATH=/nix/store/wicywbih6vklw00gzrmyw5m8gvwhm6rn-diffutils-3.7/bin:/nix/store/l69pbxhsy8z3z7gymlhm88bsx5h53938-strace-5.5/bin:/nix/store/cipina59rj22f8rv8lv1311hnc1d64xv-ripgrep-11.0.2/bin:/nix/store/d7wqn6pn23m6ijj4qxmnyya7313vx4lc-file-5.38/bin:/nix/store/n3kmvnsy2yd4m347mynk35mvy8mfjf8d-radare2-4.2.1/bin:/nix/store/dv602dl9y4aks8w6w2dvfm13pzxrh7v2-libarchive-3.4.2/bin:/nix/store/2bdlpp1xvl971l25h8l9d4664jd8z8ad-jq-1.6-bin/bin:/nix/store/ix2bqs08pknlarlqbdpm7mcfdxk01xy1-squashfs-4.4/bin:/nix/store/xmdf059nf5a1763w21gpc7ifizwk4b3p-coreutils-8.31/bin:/nix/store/8gy2bmpz3qawxr3g8hqhfgkf32wb0wfl-bash-4.4-p23/bin:/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/bin
    ---
    > PATH=/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root:/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/sbin:/nix/store/wicywbih6vklw00gzrmyw5m8gvwhm6rn-diffutils-3.7/bin:/nix/store/l69pbxhsy8z3z7gymlhm88bsx5h53938-strace-5.5/bin:/nix/store/cipina59rj22f8rv8lv1311hnc1d64xv-ripgrep-11.0.2/bin:/nix/store/d7wqn6pn23m6ijj4qxmnyya7313vx4lc-file-5.38/bin:/nix/store/n3kmvnsy2yd4m347mynk35mvy8mfjf8d-radare2-4.2.1/bin:/nix/store/dv602dl9y4aks8w6w2dvfm13pzxrh7v2-libarchive-3.4.2/bin:/nix/store/2bdlpp1xvl971l25h8l9d4664jd8z8ad-jq-1.6-bin/bin:/nix/store/ix2bqs08pknlarlqbdpm7mcfdxk01xy1-squashfs-4.4/bin:/nix/store/xmdf059nf5a1763w21gpc7ifizwk4b3p-coreutils-8.31/bin:/nix/store/8gy2bmpz3qawxr3g8hqhfgkf32wb0wfl-bash-4.4-p23/bin:/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/bin
    63c64
    < SHLVL=2
    ---
    > SHLVL=3
    78c79
    < XDG_DATA_DIRS=/nix/store/kiwkgczbi8c2v9i5gy9x8vrrcmsvn3xd-qterminal-0.14.1/share:/nix/store/vxdlw8naw28f0df414vkadyd8g35vqs0-lxqt-runner-0.14.1/share:/nix/store/q1yjvfwy959jgajs0ijib3ndk3w5khds-lxqt-session-0.14.1/share:/home/genesis/.nix-profile/share:/etc/profiles/per-user/genesis/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share:/nix/store/q1yjvfwy959jgajs0ijib3ndk3w5khds-lxqt-session-0.14.1/share
    ---
    > XDG_DATA_DIRS=/home/genesis/.cache/appimage-run/37e15e46f3c5fb6958c22c752050f4effc096745afb3c4f6a97a5c98607bfbe6/squashfs-root/usr/share/:./share/:/usr/share/gnome:/usr/local/share/:/usr/share/:/nix/store/kiwkgczbi8c2v9i5gy9x8vrrcmsvn3xd-qterminal-0.14.1/share:/nix/store/vxdlw8naw28f0df414vkadyd8g35vqs0-lxqt-runner-0.14.1/share:/nix/store/q1yjvfwy959jgajs0ijib3ndk3w5khds-lxqt-session-0.14.1/share:/home/genesis/.nix-profile/share:/etc/profiles/per-user/genesis/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share:/nix/store/q1yjvfwy959jgajs0ijib3ndk3w5khds-lxqt-session-0.14.1/share:/usr/share/gnome/:/usr/local/share/:/usr/share/
     

@probonopd
Copy link

I don't quite understand what you are doing there but you seem to have a plan ;-)

@bignaux
Copy link
Contributor Author

bignaux commented Mar 7, 2020

@probonopd : in order to make binaries working on an appimage, we have often to patchelf/patchshebang them with our nixos tools. To use the autopatch* , we have to move them in the right directories so we change the structure of the appimage anyway. I first remove the need to use the packer in a previous PR, then in this, i turn some nix to make easily the fixing of an appimage.

Edit : here i don't yet make any change to how the stuff runs currently. I try to keep really mirrored features exept removing /squashfs-root/ in appimage-run cache directories allowing by unsquashfs instead of packer extract feature option.

@timokau
Copy link
Member

timokau commented Mar 8, 2020

This sounds good to me in principle, but I don't know enough about appimage to actually review.

@bignaux
Copy link
Contributor Author

bignaux commented Mar 8, 2020

@timokau : could it be you missed add "$@" to 19e075b#diff-ae84e7b07459c504b804db2a1f54636dR51 ?
and that @tilpner count on exec to not wrapping the next exec in an else case ? I'd like provide a better way to override the exec argument, perhaps letting people provide rarun2 options on cmd options and add some option in wrapAppImage() to override the runScript ?

@timokau
Copy link
Member

timokau commented Mar 8, 2020

Yeah, looks like I missed that. Good catch!

@bignaux
Copy link
Contributor Author

bignaux commented Mar 8, 2020

Thanks @timokau , i don't touch that immediatly since it's the current behavior. i really think we would enjoy something like i said, but i'd like to listen people feeling.

wrap() {

  rarun2 setenv=APPIMAGE_SILENT_INSTALL=1 chdir="$APPDIR" program=./AppRun "$@"
}

@bignaux
Copy link
Contributor Author

bignaux commented Mar 8, 2020

with this last commit, appimage-run doesn't need special (and hidden) option to run the script, so default behavior is how appimage-run users use it, so now it's easier to understand and hack.

Edit, so now, you can even do that :
appimage-run -w /home/genesis/.cache/appimage-run/0447c38529b8b443e93a1724c370b944dbaf7490c8a42495d2ac2d41ee76f7a3/

This illustrate that we can now improve the wrap() for both in same time.

local appimageType=0

# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
eval "$(r2 "$src" -nn -Nqc "p8j 3 @ 8" |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just extract 3 bytes at file offset 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and it could be done with hexdump or xdd or dd. but here there is a homogeneity with r2+jq for carving elf file by design choice.


# multiarch offset one-liner using same method as AppImage
# see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
offset=$(r2 "$src" -nn -Nqc "pfj.elf_header @ 0" |\
Copy link
Member

@Mic92 Mic92 Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not having a radare2 as an dependency would be nice, it might be good enough for now, given that getting this sort of information might be hard to extract using other tools.

Copy link
Contributor Author

@bignaux bignaux Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already discussed and merge on previous PR.

Copy link
Member

@tilpner tilpner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still haven't done any actual testing


apprun() {

eval "$(rahash2 "$APPIMAGE" -j | jq -r '.[] | @sh "SHA256=\(.hash)"')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference/advantage to sha256="$(sha256sum "$APPIMAGE")"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to do homogeneity here around r2+jq, so despite the way that you can easily change the hash algo, not an immediate interest. But people reading the script to modify would perhaps be more interesting to use rarun2 and others tools in radare2 if they see some subliminal examples around the code ....

Comment on lines +69 to +70
else echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
fi
else
echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed

fi

PATH="@path@:$PATH"
apprun_opt=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never changed from true, and could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but i thought to remove the -w option and rely on $1 type, then appimage-run <appimage|appimage directory> , but i'd more interested to do that after discussion how to write a useful wrap() function. i make test with rarun2 and will come with proposal. For now thanks to close the PR here, look if you would merge appimage-run in appimageTools, and finish wrapTypeX removing .

PATH="@path@:$PATH"
apprun_opt=true

#DEBUG=0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a left-over?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more or less, the work is not yet finish, but i hope the step by step would help people understand the way i try to refactoring this stuff.

#DEBUG=0

# src : AppImage
# dest : let's unpack() create the directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# dest : let's unpack() create the directory
# out : target directory, assumed to not exist yet


case "$appimageType" in
1 ) echo "Uncompress $(basename "$src") of type $appimageType."
mkdir "$out"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps pass -p to handle $out existing already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could not do that for unsquashfs, so i prefer not. the latest directory should not exist, that's a limitation of unsquashfs -d .

src = ./appimage-exec.sh;
isExecutable = true;
dir = "bin";
path = with pkgs; lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path = with pkgs; lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];
path = lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];

*) echo "Unsupported AppImage Type: $appimageType";;
esac
'';
appimage-exec = pkgs.substituteAll {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
appimage-exec = pkgs.substituteAll {
appimage-exec = substituteAll {

@@ -0,0 +1,142 @@
#!@shell@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a .sh suffix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's better to set in nixpkgs with the prefix, then it has no prefix when we use it through the wrapper.

wrap() {

cd "$APPDIR" || exit
# quite same in appimageTools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment loses its meaning after this PR is merged

@Mic92 Mic92 merged commit 115a8e8 into NixOS:master Mar 9, 2020
@Mic92
Copy link
Member

Mic92 commented Mar 9, 2020

@tilpner sorry. I saw your review too late after I already tested and merged it.

dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Mar 9, 2020
appimage-run: unify appimageTools and appimage-run
(cherry picked from commit 115a8e8)
@bignaux bignaux deleted the appimage-run branch March 10, 2020 17:47
cd $APPDIR
exec ./AppRun "$@"
'';
runScript = "appimage-exec.sh -w ${src}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a -- to prevent appimage-exec.sh from stealing further hyphenated arguments intended for the real executable: #128927

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants