spiegel-keyman/linux/debian/ibus-keyman.postinst
Eberhard Beilharz 9d1004b9ec
chore(linux): Fix ibus-keyman.postinst script
When installing ibus-keyman it could happen that we got an (ignored)
error "user name does not exist". This change tries to work around
this problem.
2022-09-02 18:05:52 +02:00

76 lines
2.2 KiB
Bash

#!/bin/sh
set -e
case "$1" in
configure)
# if don't have sudo and ps then don't attempt to restart ibus
if which sudo > /dev/null && which ps > /dev/null; then
# check for gnome-shell as it works differently
! gspid=`ps -C gnome-shell -o pid=|head -n 1`
if [ "x$gspid" != "x" ]; then
# gnome-shell has multiple ibus-daemon processes and needs exit instead of restart
is_gnome_shell=1
else
is_gnome_shell=0
fi
# Restart IBus if it is running
! ibuspid=`ps -C ibus-daemon -o pid=|head -n 1`
if [ "x$ibuspid" != "x" ]; then
if [ "x$is_gnome_shell" = "x1" ]; then
ibususers=`ps -C ibus-daemon -o user=|grep -v gdm|uniq`
for ibususer in $ibususers; do
sudo -H -u "$ibususer" ibus exit || true
sleep 1s
done
else
ibususers=`ps -C ibus-daemon -o user=|uniq`
for ibususer in $ibususers; do
sudo -H -u "$ibususer" ibus restart || true
sleep 1s
done
fi
fi
# Verify that it's running now
if [ ! -z $SUDO_USER ] && id $SUDO_USER > /dev/null 2>/dev/null; then
! ibusdaemon=$(ps --user $SUDO_USER -o s= -o cmd | grep --regexp="^[^ZT] ibus-daemon .*--xim.*")
if [ "x$ibusdaemon" = "x" ]; then
# otherwise try to start it for the user installing the package
if [ "x$is_gnome_shell" = "x1" ]; then
for session in $(loginctl show-user ${SUDO_USER} -p Sessions --value); do
case $(loginctl show-session ${session} -p Type --value) in
wayland) sudo -H -u "${SUDO_USER}" -i WAYLAND_DISPLAY=wayland-0 -- ibus-daemon -d -r --xim --panel disable;;
x11) sudo -H -u "${SUDO_USER}" -- ibus-daemon -d -r --xim --panel disable;;
*) ;;
esac
done
else
sudo -H -u "${SUDO_USER}" -- ibus-daemon -d -r --xim
fi
fi
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
exit 0
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0