diff --git a/linuxdeploy-plugin-gtk.sh b/linuxdeploy-plugin-gtk.sh index 82c276f..5ec1861 100755 --- a/linuxdeploy-plugin-gtk.sh +++ b/linuxdeploy-plugin-gtk.sh @@ -29,8 +29,7 @@ search_tool() { local tool="$1" local directory="$2" - if command -v "$tool" > /dev/null; then - echo "$tool" + if command -v "$tool"; then return 0 fi @@ -48,9 +47,6 @@ search_tool() { return 0 fi done - - echo "$0: $tool not found, aborting" > /dev/stderr - { exit 1; } } APPDIR= @@ -117,6 +113,9 @@ APPIMAGE_GTK_THEME="${APPIMAGE_GTK_THEME:-"Adwaita:$GTK_THEME_VARIANT"}" # Allow CACHEDIR="$(mktemp --tmpdir --directory .AppRun.XXXXXXXX)" export APPDIR="${APPDIR:-"$(dirname "$(realpath "$0")")"}" # Workaround to run extracted AppImage +export OLDPATH="$PATH" +export PATH="$APPDIR/usr/bin:$PATH" + export GTK_DATA_PREFIX="$APPDIR" export GTK_THEME="$APPIMAGE_GTK_THEME" # Custom themes are broken export GDK_BACKEND=x11 # Crash with Wayland backend on Wayland @@ -151,10 +150,10 @@ if [ -x "$gtk3_immodules_query" ]; then echo "Updating immodules cache in $APPDIR/$gtk3_immodules_cache_file" "$gtk3_immodules_query" > "$APPDIR/$gtk3_immodules_cache_file" else - echo "Warning: gtk-query-immodules-3.0 not found" + echo "WARNING: gtk-query-immodules-3.0 not found" fi if [ ! -f "$APPDIR/$gtk3_immodules_cache_file" ]; then - echo "Warning: immodules.cache file is missing" + echo "WARNING: immodules.cache file is missing" fi echo "Installing GDK PixBufs" @@ -168,17 +167,16 @@ copy_tree "$gdk_pixbuf_binarydir" "$APPDIR/" cat >> "$HOOKFILE" < "\$GDK_PIXBUF_MODULE_FILE" EOF if [ -x "$gdk_pixbuf_query" ]; then echo "Updating pixbuf cache in $APPDIR/$gdk_pixbuf_cache_file" "$gdk_pixbuf_query" > "$APPDIR/$gdk_pixbuf_cache_file" else - echo "Warning: gdk-pixbuf-query-loaders not found" + echo "WARNING: gdk-pixbuf-query-loaders not found" fi if [ ! -f "$APPDIR/$gdk_pixbuf_cache_file" ]; then - echo "Warning: loaders.cache file is missing" + echo "WARNING: loaders.cache file is missing" fi echo "Copying more libraries" @@ -213,3 +211,52 @@ for directory in "${PATCH_ARRAY[@]}"; do patchelf --set-rpath '$ORIGIN/../../../..' "$APPDIR/$file" done < <(find "$directory" -name '*.so' -print0) done + +echo "Add a wrapper for some binaries" +# Note: some files on system must not be started with overrides above +# See https://github.com/linuxdeploy/linuxdeploy-plugin-gtk/issues/11#issuecomment-761788064 +BINDIR="$APPDIR/usr/bin" +EOAFILE="$BINDIR/exec-outside-appimage" +mkdir -p "$BINDIR" +cat > "$EOAFILE" <<\EOF +#! /bin/bash + +export PATH="$OLDPATH" + +unset OLDPATH +unset GTK_DATA_PREFIX +unset GTK_THEME +unset GDK_BACKEND +unset XDG_DATA_DIRS +unset GSETTINGS_SCHEMA_DIR +unset GTK_EXE_PREFIX +unset GTK_PATH +unset GTK_IM_MODULE_DIR +unset GTK_IM_MODULE_FILE +unset GDK_PIXBUF_MODULEDIR +unset GDK_PIXBUF_MODULE_FILE + +# Enter 'if' when '$0' is 'exec-outside-appimage' script itself +# Symbolic links to 'exec-outside-appimage' should not enter in 'if' +app="$(basename "$0")" +if ! command -v "$app" &> /dev/null; then + app="$1" + shift + if [ -z "$app" ]; then + echo "$0: this script requires a command as argument" + exit 1 + elif ! command -v "$app" &> /dev/null; then + echo "'$app' not found in PATH ($PATH)" + exit 1 + fi +fi +"$app" "$@" +EOF +chmod $verbose 755 "$EOAFILE" +EOA_ARRAY=( + "xdg-open" + "eog" +) +for file in "${EOA_ARRAY[@]}"; do + ln $verbose -s "$(basename "$EOAFILE")" "$BINDIR/$file" +done