diff --git a/src/appimage/AppRun b/src/appimage/AppRun index 9692414f..abc24cb9 100755 --- a/src/appimage/AppRun +++ b/src/appimage/AppRun @@ -1,176 +1,198 @@ #! /usr/bin/env bash this_dir="$(readlink -f "$(dirname "$0")")" if [ "$1" = "--debug" ]; then shift set -x else set -e fi if [ -f "${APPDIR}/GnuPG-VS-Desktop-VERSION" ]; then myname="GnuPG VS-Desktop "$(cat "${APPDIR}/GnuPG-VS-Desktop-VERSION") else myname="GnuPG Desktop "$(cat "${APPDIR}/GnuPG-Desktop-VERSION") fi if [ "$1" = "--help" -o "$1" = "--version" ]; then echo "$myname" if [ "$1" = "--help" ]; then cat <&2 exit 2 fi fi exit 0 fi export PATH="${APPDIR}/usr/bin:${PATH}" export XDG_DATA_DIRS="${APPDIR}/usr/share:${XDG_DATA_DIRS:-/usr/share}:/usr/share" export XDG_CONFIG_DIRS="${APPDIR}/usr/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}:/etc/xdg" # Avoid problems due to caller set ld.so envvars. if [ -n "$LD_PRELOAD" ]; then _gnupg_save_LD_PRELOAD="$LD_PRELOAD" LD_PRELOAD= fi if [ -n "$LD_LIBRARY_PATH" ]; then _gnupg_save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_LIBRARY_PATH= fi # Allow GnuPG config scripts to detect the appimage install. We can't # rely on APPDIR because other appimages might come with their own # gnupg version. Change the value to "vsd" for a GnuPG VS-Desktop build. if [ -f "${APPDIR}/GnuPG-VS-Desktop-VERSION" ]; then _gnupg_appimage=vsd prestart_snippet=/etc/gnupg-vsd/apprun.pre-start.sh else _gnupg_appimage=generic prestart_snippet=/etc/gnupg/apprun.pre-start.sh fi export _gnupg_appimage if [ -z "$SHELL" ]; then SHELL="$(grep '/bash$' /etc/shells 2>/dev/null)" if [ -z "$SHELL" ]; then export SHELL=/bin/bash fi fi mycleanup () { if [ -n $"gnupg_SETUPINIFILE" ]; then rm -f $"gnupg_SETUPINIFILE" fi } gnupg_SETUPINIFILE= trap mycleanup 0 INT QUIT if [ "$1" = "-c" -o "$1" = "-i" ]; then shift if [ ! -x "$SHELL" ]; then echo "error: no shell found" >&2 exit 2 fi if [ -n "$1" ]; then pgm=/usr/bin/env pgmargs="$@" else export gnupg_SETUPINIFILE SHELL if [ ${_gnupg_appimage} = vsd ]; then - if [ $(id -u) -eq 0 -a ! -d /etc/gnupg-vsd ]; then - echo "no global configuration - installing default" >&2 - mkdir /etc/gnupg-vsd - cp -R "${APPDIR}"/usr/share/gnupg/conf/gnupg-vsd/* /etc/gnupg-vsd/ + if [ $(id -u) -eq 0 ]; then + dotcfg="/etc/gnupg-vsd/.config-by-appimage" + docopy=yes + if [ ! -d /etc/gnupg-vsd ]; then + echo "no global configuration - installing default" >&2 + mkdir /etc/gnupg-vsd + elif [ -f $dotcfg -a "$(head -1 $dotcfg )" = "$myname" ]; then + docopy=no + else + echo "updating global configuration" >&2 + fi + if [ $docopy = yes ]; then + for f in "${APPDIR}"/usr/share/gnupg/conf/gnupg-vsd/* ; do + t="/etc/gnupg-vsd/${f##*/}" + if [ -d "$t" ]; then + cp -R "$f" /etc/gnupg-vsd/ + elif [ -f "$t" ]; then + cp "$t" "$t.old" + cp "$f" "$t" + cmp -s "$t" "$t.old" && rm "$t.old" + else + cp "$f" "$t" + fi + done + echo "$myname" >$dotcfg + fi fi fi if echo "$SHELL" | grep '/bash$' >/dev/null 2>&1; then pgm="${APPDIR}/start-shell" pgmargs= gnupg_SETUPINIFILE="/tmp/gnupg-tmp.$(id -u).$$.ini" else pgm="$SHELL" pgmargs="-i" fi echo Welcome to "$myname"\! >&2 echo "(type \"exit\" to leave)" >&2 echo "" >&2 fi else if [ $(id -u) -eq 0 ]; then echo "error: the GUI may not be run by root" >&2 exit 2 fi # Ignore the optional --gui option if [ "$1" = "--gui" ]; then shift fi if [ -x "${this_dir}/usr/bin/kleopatra" ];then pgm="${this_dir}/usr/bin/kleopatra" pgmargs="$@" else echo "Kleopatra not found" >&2 exit 2 fi fi # The admin may tweak this script by creating a snippet to be sourced # here. For example, this can be used to set a different per user # GNUPGHOME so that the entire installation will be separate from the # system's standard configuration. if [ -f $prestart_snippet ]; then . $prestart_snippet fi # In vsd mode create a .gnupg-vsd so that we use a dedicated homedir # in for VSD. This is important on Linux because there gpg is a # standard tool and a .gnupg is often in active use. if [ ${_gnupg_appimage} = vsd -a -z "$GNUPGHOME" ]; then GNUPGHOME="$HOME/.gnupg-vsd" export GNUPGHOME if [ ! -d "$GNUPGHOME" ]; then mkdir "$GNUPGHOME" chmod 700 "$GNUPGHOME" fi # Create a script so that external programs have a way to figure # out information on this AppImage instance. We don't fail on # write error so that it is usable also in read-only environments. cat > "$GNUPGHOME"/run-gpgconf <&2