From 8b26fb15ef1e92071f83a244a286c196da7b0133 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 11 Oct 2019 22:09:44 +0200 Subject: [PATCH] AppImage: handle ARGV0 being empty --- packaging/appimage/select-binary.sh | 46 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/packaging/appimage/select-binary.sh b/packaging/appimage/select-binary.sh index aec87ca78..872d87564 100755 --- a/packaging/appimage/select-binary.sh +++ b/packaging/appimage/select-binary.sh @@ -1,28 +1,38 @@ #!/bin/bash -APPIMAGE_DIR="$(dirname "$(readlink -f "${0}")")" +# variables provided to type 2 AppImages: +# +# APPIMAGE — (Absolute) path to AppImage file (with symlinks resolved) +# +# APPDIR — Path of mountpoint of the SquashFS image contained in the +# AppImage +# +# OWD — Path to working directory at the time the AppImage is called +# +# ARGV0 — Name/path used to execute the script. This corresponds to +# the value you’d normally receive via the argv argument passed to +# your main method. Usually contains the filename or path to the +# AppImage, relative to the current working directory. + # Adopted from AppRun.c -export GSETTINGS_SCHEMA_DIR="$APPIMAGE_DIR/usr/share/glib-2.0/schemas/:$GSETTINGS_SCHEMA_DIR" -export GST_PLUGIN_SYSTEM_PATH="$APPIMAGE_DIR/usr/lib/gstreamer:$GST_PLUGIN_SYSTEM_PATH" -export GST_PLUGIN_SYSTEM_PATH_1_0="$APPIMAGE_DIR/usr/lib/gstreamer-1.0:$GST_PLUGIN_SYSTEM_PATH_1_0" -export LD_LIBRARY_PATH="$APPIMAGE_DIR/usr/lib/:$APPIMAGE_DIR/usr/lib/i386-linux-gnu/:$APPIMAGE_DIR/usr/lib/x86_64-linux-gnu/:$APPIMAGE_DIR/usr/lib32/:$APPIMAGE_DIR/usr/lib64/:$APPIMAGE_DIR/lib/:$APPIMAGE_DIR/lib/i386-linux-gnu/:$APPIMAGE_DIR/lib/x86_64-linux-gnu/:$APPIMAGE_DIR/lib32/:$APPIMAGE_DIR/lib64/:$LD_LIBRARY_PATH" -export PATH="$APPIMAGE_DIR/usr/bin/:$APPIMAGE_DIR/usr/sbin/:$APPIMAGE_DIR/usr/games/:$APPIMAGE_DIR/bin/:$APPIMAGE_DIR/sbin/:$PATH" -export PERLLIB="$APPIMAGE_DIR/usr/share/perl5/:$APPIMAGE_DIR/usr/lib/perl5/:$PERLLIB" +export GSETTINGS_SCHEMA_DIR="$APPDIR/usr/share/glib-2.0/schemas/:$GSETTINGS_SCHEMA_DIR" +export GST_PLUGIN_SYSTEM_PATH="$APPDIR/usr/lib/gstreamer:$GST_PLUGIN_SYSTEM_PATH" +export GST_PLUGIN_SYSTEM_PATH_1_0="$APPDIR/usr/lib/gstreamer-1.0:$GST_PLUGIN_SYSTEM_PATH_1_0" +export LD_LIBRARY_PATH="$APPDIR/usr/lib/:$APPDIR/usr/lib/i386-linux-gnu/:$APPDIR/usr/lib/x86_64-linux-gnu/:$APPDIR/usr/lib32/:$APPDIR/usr/lib64/:$APPDIR/lib/:$APPDIR/lib/i386-linux-gnu/:$APPDIR/lib/x86_64-linux-gnu/:$APPDIR/lib32/:$APPDIR/lib64/:$LD_LIBRARY_PATH" +export PATH="$APPDIR/usr/bin/:$APPDIR/usr/sbin/:$APPDIR/usr/games/:$APPDIR/bin/:$APPDIR/sbin/:$PATH" +export PERLLIB="$APPDIR/usr/share/perl5/:$APPDIR/usr/lib/perl5/:$PERLLIB" export PYTHONDONTWRITEBYTECODE=1 -export PYTHONHOME="$APPIMAGE_DIR/usr/" -export PYTHONPATH="$APPIMAGE_DIR/usr/share/pyshared/:$PYTHONPATH" -export QT_PLUGIN_PATH="$APPIMAGE_DIR/usr/lib/qt4/plugins/:$APPIMAGE_DIR/usr/lib/i386-linux-gnu/qt4/plugins/:$APPIMAGE_DIR/usr/lib/x86_64-linux-gnu/qt4/plugins/:$APPIMAGE_DIR/usr/lib32/qt4/plugins/:$APPIMAGE_DIR/usr/lib64/qt4/plugins/:$APPIMAGE_DIR/usr/lib/qt5/plugins/:$APPIMAGE_DIR/usr/lib/i386-linux-gnu/qt5/plugins/:$APPIMAGE_DIR/usr/lib/x86_64-linux-gnu/qt5/plugins/:$APPIMAGE_DIR/usr/lib32/qt5/plugins/:$APPIMAGE_DIR/usr/lib64/qt5/plugins/:$QT_PLUGIN_PATH" -export XDG_DATA_DIRS="$APPIMAGE_DIR/usr/share/:/usr/local/share/:/usr/share" +export PYTHONHOME="$APPDIR/usr/" +export PYTHONPATH="$APPDIR/usr/share/pyshared/:$PYTHONPATH" +export QT_PLUGIN_PATH="$APPDIR/usr/lib/qt4/plugins/:$APPDIR/usr/lib/i386-linux-gnu/qt4/plugins/:$APPDIR/usr/lib/x86_64-linux-gnu/qt4/plugins/:$APPDIR/usr/lib32/qt4/plugins/:$APPDIR/usr/lib64/qt4/plugins/:$APPDIR/usr/lib/qt5/plugins/:$APPDIR/usr/lib/i386-linux-gnu/qt5/plugins/:$APPDIR/usr/lib/x86_64-linux-gnu/qt5/plugins/:$APPDIR/usr/lib32/qt5/plugins/:$APPDIR/usr/lib64/qt5/plugins/:$QT_PLUGIN_PATH" +export XDG_DATA_DIRS="$APPDIR/usr/share/:/usr/local/share/:/usr/share" -# Get binary to run from executable's name: symlink the AppImage to -# e.g. "mkvmerge", execute that symlink & mkvmerge will be run from -# inside the AppImage. If no such binary exists, fall back to the GUI. -if [ ! -z $APPIMAGE ] ; then +if [ ! -z $ARGV0 ] ; then BINARY_NAME="$(basename "$ARGV0")" - if [ -e "$APPIMAGE_DIR/usr/bin/$BINARY_NAME" ] ; then - exec "$APPIMAGE_DIR/usr/bin/$BINARY_NAME" "$@" + if [ -e "$APPDIR/usr/bin/$BINARY_NAME" ] ; then + exec "$APPDIR/usr/bin/$BINARY_NAME" "$@" fi fi -exec "$APPIMAGE_DIR/usr/bin/mkvtoolnix-gui" "$@" +exec "$APPDIR/usr/bin/mkvtoolnix-gui" "$@"