| 1 |
#!/bin/sh |
| 2 |
# postinst script for polkitd |
| 3 |
# |
| 4 |
# see: dh_installdeb(1) |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
# summary of how this script can be called: |
| 9 |
# * <postinst> `configure' <most-recently-configured-version> |
| 10 |
# * <old-postinst> `abort-upgrade' <new version> |
| 11 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 12 |
# <new-version> |
| 13 |
# * <postinst> `abort-remove' |
| 14 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 15 |
# <failed-install-package> <version> `removing' |
| 16 |
# <conflicting-package> <version> |
| 17 |
# for details, see http://www.debian.org/doc/debian-policy/ or |
| 18 |
# the debian-policy package |
| 19 |
|
| 20 |
reboot_required() { |
| 21 |
echo "Upgrading to this polkitd version requires a reboot, please reboot the system when convenient." >&2 |
| 22 |
|
| 23 |
# Trigger an update notification that recommends a reboot. |
| 24 |
touch /run/reboot-required || true |
| 25 |
|
| 26 |
if ! grep -Fqsx polkitd /run/reboot-required.pkgs; then |
| 27 |
echo polkitd >> /run/reboot-required.pkgs || true |
| 28 |
fi |
| 29 |
} |
| 30 |
|
| 31 |
set_perms() { |
| 32 |
USER=$1 |
| 33 |
GROUP=$2 |
| 34 |
MODE=$3 |
| 35 |
FILE=$4 |
| 36 |
if ! dpkg-statoverride --list "$FILE" > /dev/null 2>&1; then |
| 37 |
chown "$USER:$GROUP" "$FILE" |
| 38 |
chmod "$MODE" "$FILE" |
| 39 |
fi |
| 40 |
} |
| 41 |
|
| 42 |
stop_polkitd () { |
| 43 |
if [ -n "${DPKG_ROOT-}" ]; then |
| 44 |
return |
| 45 |
fi |
| 46 |
|
| 47 |
if [ -d /run/systemd/system ]; then |
| 48 |
deb-systemd-invoke stop polkit.service >/dev/null || true |
| 49 |
else |
| 50 |
# On non-systemd systems, polkitd is started as a traditional D-Bus |
| 51 |
# system service and is not managed by a service manager, so this is |
| 52 |
# the best we can do |
| 53 |
start-stop-daemon --stop --oknodo --quiet --exec /usr/lib/polkit-1/polkitd || true |
| 54 |
fi |
| 55 |
} |
| 56 |
|
| 57 |
case "$1" in |
| 58 |
configure) |
| 59 |
if ! getent passwd polkitd >/dev/null; then |
| 60 |
user_changed=yes |
| 61 |
else |
| 62 |
user_changed= |
| 63 |
fi |
| 64 |
|
| 65 |
# Intentionally not using dh_installsysusers: we need enough control |
| 66 |
# over sequencing to reload dbus-daemon after doing this, but before |
| 67 |
# restarting polkitd |
| 68 |
systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} polkit.conf |
| 69 |
|
| 70 |
# When running with systemd (default) there's no need for SUID anymore |
| 71 |
# as the socket-activated service takes care of privilege escalation safely |
| 72 |
if ! dpkg -s systemd-sysv > /dev/null 2>&1; then |
| 73 |
set_perms root root 4755 /usr/lib/polkit-1/polkit-agent-helper-1 |
| 74 |
fi |
| 75 |
|
| 76 |
# If the polkitd user was newly created or newly added to the polkitd |
| 77 |
# group, the dbus-daemon might not know about that until reloaded. |
| 78 |
# dbus-broker's service has a dbus.service alias, so this will reload |
| 79 |
# either dbus-daemon or dbus-broker, whichever is used. |
| 80 |
if [ -z "${DPKG_ROOT-}" ] && [ -n "$user_changed" ]; then |
| 81 |
invoke-rc.d dbus reload || true |
| 82 |
fi |
| 83 |
|
| 84 |
# begin-remove-after: released:forky |
| 85 |
# If GNOME is already running when upgrading from a pre-socket activated agent |
| 86 |
# version, then the desktop might break, ask for a reboot |
| 87 |
if [ -d /run/systemd/system ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 127~; then |
| 88 |
reboot_required |
| 89 |
fi |
| 90 |
# end-remove-after |
| 91 |
;; |
| 92 |
|
| 93 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 94 |
;; |
| 95 |
|
| 96 |
*) |
| 97 |
echo "postinst called with unknown argument \`$1'" >&2 |
| 98 |
exit 1 |
| 99 |
;; |
| 100 |
esac |
| 101 |
|
| 102 |
# dh_installdeb will replace this with shell code automatically |
| 103 |
# generated by other debhelper scripts. |
| 104 |
|
| 105 |
#DEBHELPER# |
| 106 |
|
| 107 |
# If dpkg renamed a sysadmin-modified /etc/pam.d/polkit-1 to .dpkg-bak, |
| 108 |
# rename it back to the original name so PAM will still load it. |
| 109 |
# (Workaround for missing dpkg feature requested in |
| 110 |
# https://bugs.debian.org/1006655) |
| 111 |
if [ -e /etc/pam.d/polkit-1.dpkg-bak ]; then |
| 112 |
echo "Moving /etc/pam.d/polkit-1.dpkg-bak back to /etc/pam.d/polkit-1 ..." |
| 113 |
mv /etc/pam.d/polkit-1.dpkg-bak /etc/pam.d/polkit-1 |
| 114 |
fi |
| 115 |
|
| 116 |
# On non-systemd systems, polkitd is started as a traditional D-Bus |
| 117 |
# system service and is not managed by a service manager, so the |
| 118 |
# closest thing we can do to a restart operation is to terminate it |
| 119 |
# and let dbus-daemon restart it. |
| 120 |
if ! [ -d /run/systemd/system ]; then |
| 121 |
stop_polkitd |
| 122 |
fi |
| 123 |
|
| 124 |
exit 0 |
| 125 |
|
| 126 |
# vim:set sw=4 sts=4 et: |