@@ -11,10 +11,10 @@ if [ "$DEBUG" != "" ]; then
1111 verbose=" --verbose"
1212fi
1313
14- script= $( readlink -f " $0 " )
14+ SCRIPT= " $( basename " $( readlink -f " $0 " ) " ) "
1515
1616show_usage () {
17- echo " Usage: $script --appdir <path to AppDir>"
17+ echo " Usage: $SCRIPT --appdir <path to AppDir>"
1818 echo
1919 echo " Bundles resources for applications that use GTK into an AppDir"
2020 echo
@@ -38,13 +38,13 @@ variable_is_true() {
3838get_pkgconf_variable () {
3939 local variable=" $1 "
4040 local library=" $2 "
41- local default_path =" $3 "
41+ local default_value =" $3 "
4242
43- path =" $( " $PKG_CONFIG " --variable=" $variable " " $library " ) "
44- if [ -n " $path " ]; then
45- echo " $path "
46- elif [ -n " $default_path " ]; then
47- echo " $default_path "
43+ pkgconfig_ret =" $( " $PKG_CONFIG " --variable=" $variable " " $library " ) "
44+ if [ -n " $pkgconfig_ret " ]; then
45+ echo " $pkgconfig_ret "
46+ elif [ -n " $default_value " ]; then
47+ echo " $default_value "
4848 else
4949 echo " $0 : there is no '$variable ' variable for '$library ' library." > /dev/stderr
5050 echo " Please check the '$library .pc' file is present in \$ PKG_CONFIG_PATH (you may need to install the appropriate -dev/-devel package)." > /dev/stderr
@@ -62,6 +62,44 @@ copy_tree() {
6262 done
6363}
6464
65+ copy_lib_tree () {
66+ # The source lib directory could be /usr/lib, /usr/lib64, or /usr/lib/x86_64-linux-gnu
67+ # Therefore, when copying lib directories, we need to transform that target path
68+ # to a consistent /usr/lib
69+ local src=(" ${@: 1: $# -1} " )
70+ local dst=" ${*: $# } "
71+
72+ for elem in " ${src[@]} " ; do
73+ mkdir -p " ${dst::- 1}${elem/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
74+ pushd " $LD_GTK_LIBRARY_PATH "
75+ cp " $( realpath --relative-to=" $LD_GTK_LIBRARY_PATH " " $elem " ) " --archive --parents --target-directory=" $dst /usr/lib" $verbose
76+ popd
77+ done
78+ }
79+
80+ get_triplet_path () {
81+ if command -v dpkg-architecture > /dev/null; then
82+ echo " /usr/lib/$( dpkg-architecture -qDEB_HOST_MULTIARCH) "
83+ fi
84+ }
85+
86+
87+
88+ search_library_path () {
89+ PATH_ARRAY=(
90+ " $( get_triplet_path) "
91+ " /usr/lib64"
92+ " /usr/lib"
93+ )
94+
95+ for path in " ${PATH_ARRAY[@]} " ; do
96+ if [ -d " $path " ]; then
97+ echo " $path "
98+ return 0
99+ fi
100+ done
101+ }
102+
65103search_tool () {
66104 local tool=" $1 "
67105 local directory=" $2 "
@@ -71,7 +109,8 @@ search_tool() {
71109 fi
72110
73111 PATH_ARRAY=(
74- " /usr/lib/$( uname -m) -linux-gnu/$directory /$tool "
112+ " $( get_triplet_path) /$directory /$tool "
113+ " /usr/lib64/$directory /$tool "
75114 " /usr/lib/$directory /$tool "
76115 " /usr/bin/$tool "
77116 " /usr/bin/$tool -64"
@@ -119,10 +158,19 @@ if [ "$APPDIR" == "" ]; then
119158 exit 1
120159fi
121160
161+ APPDIR=" $( realpath " $APPDIR " ) "
122162mkdir -p " $APPDIR "
123163# make lib64 writable again.
124164chmod +w " $APPDIR " /usr/lib64 || true
125165
166+ . /etc/os-release
167+ if [ " $ID " = " debian" ] || [ " $ID " = " ubuntu" ]; then
168+ if ! command -v dpkg-architecture & > /dev/null; then
169+ echo -e " $0 : dpkg-architecture not found.\nInstall dpkg-dev then re-run the plugin."
170+ exit 1
171+ fi
172+ fi
173+
126174if command -v pkgconf > /dev/null; then
127175 PKG_CONFIG=" pkgconf"
128176elif command -v pkg-config > /dev/null; then
132180 exit 1
133181fi
134182
183+ # GTK's library path *must not* have a trailing slash for later parameter substitution to work properly
184+ LD_GTK_LIBRARY_PATH=" $( realpath " ${LD_GTK_LIBRARY_PATH:- $(search_library_path)} " ) "
185+
135186if ! command -v find & > /dev/null && ! type find & > /dev/null; then
136187 echo -e " $0 : find not found.\nInstall findutils then re-run the plugin."
137188 exit 1
@@ -178,13 +229,21 @@ mkdir -p "$HOOKSDIR"
178229cat > " $HOOKFILE " << \EOF
179230#! /usr/bin/env bash
180231
181- gsettings get org.gnome.desktop.interface gtk-theme 2> /dev/null | grep -qi "dark" && GTK_THEME_VARIANT="dark" || GTK_THEME_VARIANT="light"
232+ COLOR_SCHEME="$( dbus-send --session --dest=org.freedesktop.portal.Desktop --type=method_call --print-reply --reply-timeout=1000 /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read ' string:org.freedesktop.appearance' ' string:color-scheme' 2> /dev/null | tail -n1 | cut -b35- | cut -d' ' -f2 || printf ' ' ) "
233+ if [ -z "$COLOR_SCHEME " ]; then
234+ COLOR_SCHEME="$( gsettings get org.gnome.desktop.interface color-scheme 2> /dev/null || printf ' ' ) "
235+ fi
236+ case "$COLOR_SCHEME " in
237+ "1"|"'prefer-dark'") GTK_THEME_VARIANT="dark";;
238+ "2"|"'prefer-light'") GTK_THEME_VARIANT="light";;
239+ *) GTK_THEME_VARIANT="light";;
240+ esac
182241APPIMAGE_GTK_THEME="${APPIMAGE_GTK_THEME:- " Adwaita:$GTK_THEME_VARIANT " } " # Allow user to override theme (discouraged)
183242
184243export APPDIR="${APPDIR:- " $( dirname " $( realpath " $0 " ) " ) " } " # Workaround to run extracted AppImage
185244export GTK_DATA_PREFIX="$APPDIR "
186245export GTK_THEME="$APPIMAGE_GTK_THEME " # Custom themes are broken
187- export GDK_BACKEND=" ${GDK_BACKEND :- x11} " # Crash with Wayland backend on Wayland - We tested it without it and ended up with this: https://github.com/tauri-apps/tauri/issues/8541
246+ # export GDK_BACKEND=x11 # Monitor this closely. AppImage used to crash on Wayland!
188247export XDG_DATA_DIRS="$APPDIR /usr/share:/usr/share:$XDG_DATA_DIRS " # g_get_system_data_dirs() from GLib
189248EOF
190249
@@ -197,47 +256,67 @@ cat >> "$HOOKFILE" <<EOF
197256export GSETTINGS_SCHEMA_DIR="\$ APPDIR/$glib_schemasdir "
198257EOF
199258
259+ echo " Installing GIRepository Typelibs"
260+ gi_typelibsdir=" $( get_pkgconf_variable " typelibdir" " gobject-introspection-1.0" " $LD_GTK_LIBRARY_PATH /girepository-1.0" ) "
261+ copy_lib_tree " $gi_typelibsdir " " $APPDIR /"
262+ cat >> " $HOOKFILE " << EOF
263+ export GI_TYPELIB_PATH="\$ APPDIR/${gi_typelibsdir/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
264+ EOF
265+
266+ echo " Installing Gio modules"
267+ gio_moduledir=" $( get_pkgconf_variable " giomoduledir" " gio-2.0" " $LD_GTK_LIBRARY_PATH /gio/modules" ) "
268+ copy_lib_tree " $gio_moduledir " " $APPDIR /"
269+ gio_querymodules=" $( search_tool " gio-querymodules" " glib-2.0" ) "
270+ if [ -x " $gio_querymodules " ]; then
271+ " $gio_querymodules " " $APPDIR /${gio_moduledir/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
272+ else
273+ echo " WARNING: gio-querymodules not found"
274+ fi
275+ cat >> " $HOOKFILE " << EOF
276+ export GIO_MODULE_DIR="\$ APPDIR/${gio_moduledir/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
277+ EOF
278+
200279case " $DEPLOY_GTK_VERSION " in
201280 2)
202281 # https://github.com/linuxdeploy/linuxdeploy-plugin-gtk/pull/20#issuecomment-826354261
203282 echo " WARNING: Gtk+2 applications are not fully supported by this plugin"
204283 ;;
205284 3)
206285 echo " Installing GTK 3.0 modules"
207- gtk3_exec_prefix=" $( get_pkgconf_variable " exec_prefix" " gtk+-3.0" ) "
208- gtk3_libdir=" $( get_pkgconf_variable " libdir" " gtk+-3.0" ) /gtk-3.0"
209- # gtk3_path="$gtk3_libdir/modules" export GTK_PATH="\$APPDIR/$gtk3_path "
210- gtk3_immodulesdir=" $gtk3_libdir /$( get_pkgconf_variable " gtk_binary_version" " gtk+-3.0" ) /immodules"
211- gtk3_printbackendsdir=" $gtk3_libdir /$( get_pkgconf_variable " gtk_binary_version" " gtk+-3.0" ) /printbackends"
286+ gtk3_exec_prefix=" $( get_pkgconf_variable " exec_prefix" " gtk+-3.0" " /usr " ) "
287+ gtk3_libdir=" $( get_pkgconf_variable " libdir" " gtk+-3.0" " $LD_GTK_LIBRARY_PATH " ) /gtk-3.0"
288+ gtk3_path=" $gtk3_libdir "
289+ gtk3_immodulesdir=" $gtk3_libdir /$( get_pkgconf_variable " gtk_binary_version" " gtk+-3.0" " 3.0.0 " ) /immodules"
290+ gtk3_printbackendsdir=" $gtk3_libdir /$( get_pkgconf_variable " gtk_binary_version" " gtk+-3.0" " 3.0.0 " ) /printbackends"
212291 gtk3_immodules_cache_file=" $( dirname " $gtk3_immodulesdir " ) /immodules.cache"
213292 gtk3_immodules_query=" $( search_tool " gtk-query-immodules-3.0" " libgtk-3-0" ) "
214- copy_tree " $gtk3_libdir " " $APPDIR /"
293+ copy_lib_tree " $gtk3_libdir " " $APPDIR /"
215294 cat >> " $HOOKFILE " << EOF
216295export GTK_EXE_PREFIX="\$ APPDIR/$gtk3_exec_prefix "
217- export GTK_PATH="\$ APPDIR/$gtk3_libdir :/usr/lib64/gtk-3.0:/usr/lib/x86_64-linux-gnu/gtk-3.0"
218- export GTK_IM_MODULE_FILE="\$ APPDIR/$gtk3_immodules_cache_file "
219-
296+ export GTK_PATH="\$ APPDIR/${gtk3_path/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
297+ export GTK_IM_MODULE_FILE="\$ APPDIR/${gtk3_immodules_cache_file/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
220298EOF
299+
221300 if [ -x " $gtk3_immodules_query " ]; then
222- echo " Updating immodules cache in $APPDIR /$gtk3_immodules_cache_file "
223- " $gtk3_immodules_query " > " $APPDIR /$gtk3_immodules_cache_file "
301+ echo " Updating immodules cache in $APPDIR /${ gtk3_immodules_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
302+ " $gtk3_immodules_query " > " $APPDIR /${ gtk3_immodules_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
224303 else
225304 echo " WARNING: gtk-query-immodules-3.0 not found"
226305 fi
227- if [ ! -f " $APPDIR /$gtk3_immodules_cache_file " ]; then
306+ if [ ! -f " $APPDIR /${ gtk3_immodules_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} " ]; then
228307 echo " WARNING: immodules.cache file is missing"
229308 fi
230- sed -i " s|$gtk3_libdir /3.0.0/immodules/||g" " $APPDIR /$gtk3_immodules_cache_file "
309+ sed -i " s|$gtk3_libdir /3.0.0/immodules/||g" " $APPDIR /${ gtk3_immodules_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
231310 ;;
232311 4)
233312 echo " Installing GTK 4.0 modules"
234313 gtk4_exec_prefix=" $( get_pkgconf_variable " exec_prefix" " gtk4" " /usr" ) "
235314 gtk4_libdir=" $( get_pkgconf_variable " libdir" " gtk4" ) /gtk-4.0"
236- gtk4_path=" $gtk4_libdir /modules "
237- copy_tree " $gtk4_libdir " " $APPDIR /"
315+ gtk4_path=" $gtk4_libdir "
316+ copy_lib_tree " $gtk4_libdir " " $APPDIR /"
238317 cat >> " $HOOKFILE " << EOF
239318export GTK_EXE_PREFIX="\$ APPDIR/$gtk4_exec_prefix "
240- export GTK_PATH="\$ APPDIR/$gtk4_path "
319+ export GTK_PATH="\$ APPDIR/${ gtk4_path/ $LD_GTK_LIBRARY_PATH // usr / lib} "
241320EOF
242321 ;;
243322 * )
@@ -247,39 +326,43 @@ EOF
247326esac
248327
249328echo " Installing GDK PixBufs"
250- gdk_libdir=" $( get_pkgconf_variable " libdir" " gdk-pixbuf-2.0" ) "
251- gdk_pixbuf_binarydir=" $( get_pkgconf_variable " gdk_pixbuf_binarydir" " gdk-pixbuf-2.0" ) "
252- gdk_pixbuf_cache_file=" $( get_pkgconf_variable " gdk_pixbuf_cache_file" " gdk-pixbuf-2.0" ) "
253- gdk_pixbuf_moduledir=" $( get_pkgconf_variable " gdk_pixbuf_moduledir" " gdk-pixbuf-2.0" ) "
329+ gdk_libdir=" $( get_pkgconf_variable " libdir" " gdk-pixbuf-2.0" " $LD_GTK_LIBRARY_PATH " ) "
330+ gdk_pixbuf_binarydir=" $( get_pkgconf_variable " gdk_pixbuf_binarydir" " gdk-pixbuf-2.0" " $gdk_libdir /gdk-pixbuf-2.0/2.10.0 " ) "
331+ gdk_pixbuf_cache_file=" $( get_pkgconf_variable " gdk_pixbuf_cache_file" " gdk-pixbuf-2.0" " $gdk_pixbuf_binarydir /loaders.cache " ) "
332+ gdk_pixbuf_moduledir=" $( get_pkgconf_variable " gdk_pixbuf_moduledir" " gdk-pixbuf-2.0" " $gdk_pixbuf_binarydir /loaders " ) "
254333# Note: gdk_pixbuf_query_loaders variable is not defined on some systems
255334gdk_pixbuf_query=" $( search_tool " gdk-pixbuf-query-loaders" " gdk-pixbuf-2.0" ) "
256- copy_tree " $gdk_pixbuf_binarydir " " $APPDIR /"
335+ if [ -d " $gdk_pixbuf_binarydir " ]; then
336+ copy_lib_tree " $gdk_pixbuf_binarydir " " $APPDIR /"
257337cat >> " $HOOKFILE " << EOF
258- export GDK_PIXBUF_MODULE_FILE="\$ APPDIR/$gdk_pixbuf_cache_file "
338+ export GDK_PIXBUF_MODULE_FILE="\$ APPDIR/${ gdk_pixbuf_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
259339EOF
260340if [ -x " $gdk_pixbuf_query " ]; then
261- echo " Updating pixbuf cache in $APPDIR /$gdk_pixbuf_cache_file "
262- " $gdk_pixbuf_query " > " $APPDIR /$gdk_pixbuf_cache_file "
341+ echo " Updating pixbuf cache in $APPDIR /${ gdk_pixbuf_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
342+ " $gdk_pixbuf_query " > " $APPDIR /${ gdk_pixbuf_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} "
263343else
264344 echo " WARNING: gdk-pixbuf-query-loaders not found"
265345fi
266- if [ ! -f " $APPDIR /$gdk_pixbuf_cache_file " ]; then
346+ if [ ! -f " $APPDIR /${ gdk_pixbuf_cache_file/ $LD_GTK_LIBRARY_PATH // usr / lib} " ]; then
267347 echo " WARNING: loaders.cache file is missing"
268348fi
269- sed -i " s|$gdk_pixbuf_moduledir /||g" " $APPDIR /$gdk_pixbuf_cache_file "
349+ sed -i " s|$gdk_pixbuf_moduledir /||g" " $APPDIR /${gdk_pixbuf_cache_file/ $LD_GTK_LIBRARY_PATH // usr/ lib} "
350+ else
351+ echo " WARNING: $gdk_pixbuf_binarydir not found, not bundling gdk-pixbuf loaders"
352+ fi
270353
271354echo " Copying more libraries"
272- gobject_libdir=" $( get_pkgconf_variable " libdir" " gobject-2.0" ) "
273- gio_libdir=" $( get_pkgconf_variable " libdir" " gio-2.0" ) "
274- librsvg_libdir=" $( get_pkgconf_variable " libdir" " librsvg-2.0" ) "
275- pango_libdir=" $( get_pkgconf_variable " libdir" " pango" ) "
276- pangocairo_libdir=" $( get_pkgconf_variable " libdir" " pangocairo" ) "
277- pangoft2_libdir=" $( get_pkgconf_variable " libdir" " pangoft2" ) "
355+ gobject_libdir=" $( get_pkgconf_variable " libdir" " gobject-2.0" " $LD_GTK_LIBRARY_PATH " ) "
356+ gio_libdir=" $( get_pkgconf_variable " libdir" " gio-2.0" " $LD_GTK_LIBRARY_PATH " ) "
357+ librsvg_libdir=" $( get_pkgconf_variable " libdir" " librsvg-2.0" " $LD_GTK_LIBRARY_PATH " ) "
358+ pango_libdir=" $( get_pkgconf_variable " libdir" " pango" " $LD_GTK_LIBRARY_PATH " ) "
359+ pangocairo_libdir=" $( get_pkgconf_variable " libdir" " pangocairo" " $LD_GTK_LIBRARY_PATH " ) "
360+ pangoft2_libdir=" $( get_pkgconf_variable " libdir" " pangoft2" " $LD_GTK_LIBRARY_PATH " ) "
278361FIND_ARRAY=(
279- " $gdk_libdir " " libgdk_pixbuf-*.so*"
280- " $gobject_libdir " " libgobject-*.so*"
281- " $gio_libdir " " libgio-*.so*"
282- " $librsvg_libdir " " librsvg-*.so*"
362+ " $gdk_libdir " " libgdk_pixbuf-*.so*"
363+ " $gobject_libdir " " libgobject-*.so*"
364+ " $gio_libdir " " libgio-*.so*"
365+ " $librsvg_libdir " " librsvg-*.so*"
283366 " $pango_libdir " " libpango-*.so*"
284367 " $pangocairo_libdir " " libpangocairo-*.so*"
285368 " $pangoft2_libdir " " libpangoft2-*.so*"
@@ -305,22 +388,13 @@ PATCH_ARRAY=(
305388)
306389for directory in " ${PATCH_ARRAY[@]} " ; do
307390 while IFS= read -r -d ' ' file; do
308- ln $verbose -s " ${file/ \/ usr \/ lib \/ / } " " $APPDIR /usr/lib"
391+ ln $verbose -sf " ${file/ $LD_GTK_LIBRARY_PATH \/ / } " " $APPDIR /usr/lib"
309392 done < <( find " $directory " -name ' *.so' -print0)
310393done
311394
312395# set write permission on lib64 again to make it deletable.
313396chmod +w " $APPDIR " /usr/lib64 || true
314397
315- # We have to copy the files first to not get permission errors when we assign gio_extras_dir
316- find /usr/lib* -name libgiognutls.so -exec mkdir -p " $APPDIR " /" $( dirname ' {}' ) " \; -exec cp --parents ' {}' " $APPDIR /" \; || true
317- # related files that we seemingly don't need:
318- # libgiolibproxy.so - libgiognomeproxy.so - glib-pacrunner
319-
320- gio_extras_dir=$( find " $APPDIR " /usr/lib* -name libgiognutls.so -exec dirname ' {}' \; 2> /dev/null)
321- cat >> " $HOOKFILE " << EOF
322- export GIO_EXTRA_MODULES="\$ APPDIR/${gio_extras_dir# " $APPDIR " / } "
323- EOF
324398
325399# binary patch absolute paths in libwebkit files
326400find " $APPDIR " /usr/lib* -name ' libwebkit*' -exec sed -i -e " s|/usr|././|g" ' {}' \;
0 commit comments