File indexing completed on 2024-03-24 05:11:08

0001 #!/bin/bash
0002 
0003 if [ "$SNAP_ARCH" == "amd64" ]; then
0004   ARCH='x86_64-linux-gnu'
0005 elif [ "$SNAP_ARCH" == "armhf" ]; then
0006   ARCH="arm-linux-gnueabihf"
0007 else
0008   ARCH="$SNAP_ARCH-linux-gnu"
0009 fi
0010 
0011 KF5=$SNAP/kf5
0012 if [ ! -d $KF5 ]; then
0013   # This litters the paths a bit by essentially duplicating everything, but
0014   # that seems simplest to have both kf5 and !kf5 work with the same code.
0015   KF5=$SNAP
0016 fi
0017 
0018 if [ ! -d $KF5/usr ]; then
0019   source /etc/os-release
0020   runtime="kde-frameworks-5"
0021   slot="kde-frameworks-5:kde-frameworks-5-slot"
0022   if [ "$VERSION" == "18" ]; then
0023     runtime="kde-frameworks-5-qt-5-14-core18"
0024     slot="kde-frameworks-5-qt-5-14-core18:kde-frameworks-5-qt-5-14-core18-slot"
0025   fi
0026   if [ "$VERSION" == "20" ]; then
0027     runtime="kde-frameworks-5-qt-5-15-3-core20"
0028     slot="kde-frameworks-5-qt-5-15-3-core20:kde-frameworks-5-qt-5-15-3-core20-slot"
0029   fi
0030 
0031   echo "You need to connect this snap to the $runtime snap."
0032   echo ""
0033   echo "You can do this with those commands:"
0034   echo "snap install $runtime"
0035   echo "snap refresh $runtime"
0036   echo "snap connect $SNAP_NAME:kde-frameworks-5-plug $slot"
0037   exit 1
0038 fi
0039 
0040 if [ -n "$KF5_SNAP_COMMON_HOME" ]; then
0041   # https://forum.snapcraft.io/t/home-why-is-it-versioned/9708/2
0042   export HOME=$SNAP_USER_COMMON
0043 fi
0044 
0045 export PATH=$PATH:$SNAP/usr/bin:$SNAP/usr/sbin:$SNAP/usr/games:$KF5/usr/bin:$KF5/usr/sbin:$KF5/usr/games
0046 # https://bugs.launchpad.net/snapcraft/+bug/1661023
0047 # / in the snap is basically ubuntu-core.
0048 export PATH=$PATH:/usr/local/sbin:/usr/local/bin
0049 
0050 export LD_LIBRARY_PATH=$KF5/lib:$KF5/lib/$ARCH:$LD_LIBRARY_PATH
0051 export LD_LIBRARY_PATH=$KF5/usr/lib:$KF5/usr/lib/$ARCH:$LD_LIBRARY_PATH
0052 export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/$ARCH:$LD_LIBRARY_PATH
0053 export LD_LIBRARY_PATH=$SNAP/usr/lib:$SNAP/usr/lib/$ARCH:$LD_LIBRARY_PATH
0054 
0055 # XKB config
0056 export XKB_CONFIG_ROOT=$KF5/usr/share/X11/xkb
0057 
0058 # Mesa Libs
0059 export LD_LIBRARY_PATH=$KF5/usr/lib/$ARCH/mesa:$LD_LIBRARY_PATH
0060 export LD_LIBRARY_PATH=$KF5/usr/lib/$ARCH/mesa-egl:$LD_LIBRARY_PATH
0061 
0062 # libGL Drivers
0063 export LIBGL_DRIVERS_PATH=$KF5/usr/lib/$ARCH/dri
0064 export LD_LIBRARY_PATH=$LIBGL_DRIVERS_PATH:$LD_LIBRARY_PATH
0065 
0066 # Grab proprietary nvidia mount when possible.
0067 # https://bugs.launchpad.net/snappy/+bug/1588192
0068 export LD_LIBRARY_PATH=/var/lib/snapd/lib/gl:$LD_LIBRARY_PATH
0069 
0070 # Pulseaudio plugins
0071 export LD_LIBRARY_PATH=$KF5/usr/lib/$ARCH/pulseaudio:$LD_LIBRARY_PATH
0072 
0073 # Necessary for the SDK to find the translations directory
0074 # FIXME: do we (kde) really need this?
0075 export APP_DIR=$SNAP
0076 
0077 export XDG_CONFIG_DIRS=$SNAP/etc/xdg:$KF5/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}
0078 
0079 export XDG_DATA_DIRS=$SNAP/usr/local/share:$SNAP/usr/share:$KF5/usr/local/share:$KF5/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
0080 
0081 export XDG_DATA_HOME=$SNAP_USER_DATA/.local/share
0082 mkdir -p $XDG_DATA_HOME
0083 
0084 export XDG_CONFIG_HOME=$SNAP_USER_DATA/.config
0085 mkdir -p $XDG_CONFIG_HOME
0086 
0087 if [ -e $SNAP_USER_DATA/.local/config/kdeglobals ]; then
0088   # Migrate legacy path previously (incorrectly) used for configs.
0089   # The current var $HOME/.config is in line with the XDG default.
0090   cp -rv $SNAP_USER_DATA/.local/config/. $XDG_CONFIG_HOME
0091   rm -rv $SNAP_USER_DATA/.local/config/
0092 fi
0093 
0094 export XDG_CACHE_HOME=$SNAP_USER_DATA/.cache
0095 mkdir -p $XDG_CACHE_HOME
0096 
0097 export XDG_RUNTIME_DIR=$SNAP_USER_DATA/.local/var/run/$UID
0098 mkdir -p $XDG_RUNTIME_DIR
0099 chmod 7700 $XDG_RUNTIME_DIR
0100 
0101 # Font Config
0102 export FONTCONFIG_PATH=$KF5/etc/fonts/config.d
0103 export FONTCONFIG_FILE=$XDG_CONFIG_HOME/fontconfig/fonts.conf
0104 
0105 REALHOME=`getent passwd $UID | cut -d ':' -f 6`
0106 # Keep an array of data dirs, for looping through them
0107 IFS=':' read -r -a data_dirs_array <<< "$XDG_DATA_DIRS"
0108 
0109 function make_user_fontconfig {
0110   echo "<fontconfig>"
0111   if [ -d $REALHOME/.local/share/fonts ]; then
0112     echo "  <dir>$REALHOME/.local/share/fonts</dir>"
0113   fi
0114   if [ -d $REALHOME/.fonts ]; then
0115     echo "  <dir>$REALHOME/.fonts</dir>"
0116   fi
0117   for d in "${data_dirs_array[@]}"; do
0118     if [ -d "$d/fonts" ]; then
0119       echo "  <dir>$d/fonts</dir>"
0120     fi
0121   done
0122   echo '  <include ignore_missing="yes">conf.d</include>'
0123   # We need to include this default cachedir first so that caching
0124   # works: without it, fontconfig will try to write to the real user home
0125   # cachedir and be blocked by AppArmor.
0126   echo '  <cachedir prefix="xdg">fontconfig</cachedir>'
0127   if [ -d $REALHOME/.cache/fontconfig ]; then
0128     echo "  <cachedir>$REALHOME/.cache/fontconfig</cachedir>"
0129   fi
0130   echo "</fontconfig>"
0131 }
0132 
0133 # This relies on the desktop, x11, or unity7 interface from what I can tell.
0134 # We'll configure the in-snap fontconfig to look in the outside resoruces,
0135 # the outside resources are made readable by the aforementioned interfaces.
0136 rm -rf $XDG_DATA_HOME/{fontconfig,fonts,fonts-*,themes,.themes}
0137 mkdir -p $XDG_CONFIG_HOME/fontconfig
0138 make_user_fontconfig > $FONTCONFIG_FILE
0139 
0140 # GStreamer
0141 export GST_PLUGIN_PATH_1_0=$SNAP/usr/lib/$ARCH/gstreamer-1.0/:$KF5/usr/lib/$ARCH/gstreamer-1.0/
0142 
0143 # Qt Libs
0144 export LD_LIBRARY_PATH=$KF5/usr/lib/$ARCH/qt5/libs:$LD_LIBRARY_PATH
0145 
0146 # Qt Modules
0147 #
0148 # /usr/lib/arch/ is used for (e.g.) grantlee which uses a hardcoded path on top
0149 # of QT_PLUGIN_PATH (if it didn't have the hardcoded variant this wouldn't work
0150 # outside snaps either...
0151 export QT_PLUGIN_PATH=$QT_PLUGIN_PATH:$SNAP/usr/lib/$ARCH/qt5/plugins:$SNAP/usr/lib/$ARCH/
0152 export QT_PLUGIN_PATH=$QT_PLUGIN_PATH:$KF5/usr/lib/$ARCH/qt5/plugins:$KF5/usr/lib/$ARCH/
0153 export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:$SNAP/usr/lib/$ARCH/qt5/qml
0154 export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:$SNAP/lib/$ARCH
0155 export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:$KF5/usr/lib/$ARCH/qt5/qml
0156 export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:$KF5/lib/$ARCH
0157 
0158 # Qt Webengine
0159 export QTWEBENGINEPROCESS_PATH=$KF5/usr/lib/$ARCH/qt5/libexec/QtWebEngineProcess
0160 
0161 # Removes Qt warning: Could not find a location
0162 # of the system Compose files
0163 export QTCOMPOSE=$KF5/usr/share/X11/locale
0164 export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
0165 
0166 # FIXME: it's unclear if we actually need to force plasma theming, even without
0167 #   gtk integration theme Qt should probably figure out a sane style. Needs
0168 #   testing though.
0169 export KDE_FULL_SESSION=true
0170 export DESKTOP_SESSION=${DESKTOP_SESSION:-/usr/share/xsessions/plasma}
0171 export XDG_SESSION_DESKTOP=${XDG_SESSION_DESKTOP:-KDE}
0172 export XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP:-KDE}
0173 if [[ -z "$QT_QPA_PLATFORMTHEME" ]]; then
0174   gtk_based_desktops=("GNOME" "X-CINNAMON" "UNITY" "MATE" "XFCE" "LXDE" "Pantheon")
0175   for gtk_desktop in "${gtk_based_desktops[@]}"; do
0176     if [[ "$XDG_CURRENT_DESKTOP" == *"$gtk_desktop"* ]]; then
0177       export QT_QPA_PLATFORMTHEME="gtk3"
0178       break
0179     fi
0180   done
0181 fi
0182 export QT_QPA_PLATFORMTHEME=${QT_QPA_PLATFORMTHEME:-snap}
0183 
0184 # KDE specific
0185 ## Do not start slaves through klauncher but fork them directly.
0186 export KDE_FORK_SLAVES=1
0187 ## Neon PATCH! make KIO look for slaves in a dynamic location depending on $SNAP
0188 ## FIXME: should be made a : separated list so we can look in $SNAP and $KF5!
0189 export KF5_LIBEXEC_DIR=$KF5/usr/lib/$ARCH/libexec/kf5
0190 
0191 # Link icons into home so (xcursor) can find its cursor theme.
0192 mkdir -p $HOME/.icons
0193 ln -fs $KF5/usr/share/icons/* $HOME/.icons
0194 
0195 # Make sure QtChooser isn't being terrible to us
0196 export QTCHOOSER_NO_GLOBAL_DIR=1
0197 export QT_SELECT=5
0198 # qtchooser hardcodes reference paths, we'll need to rewrite them properly
0199 [ -d $XDG_CONFIG_HOME/qtchooser ] || mkdir -p $XDG_CONFIG_HOME/qtchooser
0200 echo "$SNAP/usr/lib/qt5/bin" > $XDG_CONFIG_HOME/qtchooser/5.conf
0201 echo "$SNAP/usr/lib/$ARCH" >> $XDG_CONFIG_HOME/qtchooser/5.conf
0202 echo "$SNAP/usr/lib/qt5/bin" > $XDG_CONFIG_HOME/qtchooser/default.conf
0203 echo "$SNAP/usr/lib/$ARCH" >> $XDG_CONFIG_HOME/qtchooser/default.conf
0204 
0205 # This relies on qtbase patch
0206 # 0001-let-qlibraryinfo-fall-back-to-locate-qt.conf-via-XDG.patch
0207 # to make QLibraryInfo look in XDG_* locations for qt.conf. The paths configured
0208 # here are applied to everything that uses QLibraryInfo as final fallback and
0209 # has no XDG_* fallback before that. Currently the most interesting offender
0210 # is QtWebEngine which will not work unless the Data path is correctly set.
0211 cat << EOF > $XDG_CONFIG_HOME/qt.conf
0212 [Paths]
0213 Data = $KF5/usr/share/qt5/
0214 Translations = $KF5/usr/share/qt5/translations
0215 EOF
0216 
0217 # requires `locales, libc-bin` being stage-packages
0218 if [ -e $KF5/usr/share/i18n ]; then
0219   export I18NPATH=$KF5/usr/share/i18n
0220   locpath=$XDG_DATA_HOME/locale
0221   mkdir -p $locpath
0222   export LOCPATH=$locpath:/usr/lib/locale # core snap contains C.UTF-8 already
0223   LC_ALL=C.UTF-8 $SNAP/kf5-locale-gen || exit 1
0224 fi
0225 
0226 exec "$@"