spiegel-keyman/linux/debian/ibus-keyman.postinst
Eberhard Beilharz 0040373d21
feat(linux): Try to start ibus after installation
This change deals with restarting ibus in the post-install script.

Also, on Ubuntu 21.10 Impish there are two `ibus-daemon` processes
running for the current user. One of them has the `--xim` flag
and is the one we care about. This change improves the detection
that ibus is running in the post installation script.
2022-02-07 20:07:55 +01:00

74 lines
2.1 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
! 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
;;
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