systemd.postinst 5.72 KB
Newer Older
Tollef Fog Heen's avatar
Tollef Fog Heen committed
1 2 3 4
#! /bin/sh

set -e

5
_systemctl() {
6
    if [ -d /run/systemd/system ]; then
7 8 9 10
        systemctl "$@"
    fi
}

11 12 13 14
_update_catalog() {
    journalctl --update-catalog || true
}

15
# Update Message Catalogs database and reload in response to dpkg triggers
16
if [ "$1" = "triggered" ]; then
17 18 19 20 21 22 23 24 25 26 27
    shift
    for trigger in "$@"; do
        case $trigger in
            /usr/lib/systemd/catalog)
                _update_catalog
                ;;
            /etc/init.d)
                _systemctl daemon-reload
                ;;
        esac
    done
28 29 30
    exit 0
fi

31 32 33 34 35
# Cleanup state files from the auto-enabler which we used in wheezy
if dpkg --compare-versions "$2" lt "204-1"; then
    rm -f /var/lib/systemd/enabled-units
    rm -f /var/lib/systemd/run-debian-enable-units
    rm -f /var/lib/systemd/*.symlinks
36 37
fi

38 39
# Do a one-time migration of the local time setting
if dpkg --compare-versions "$2" lt "33-1"; then
Michael Biebl's avatar
Michael Biebl committed
40
    if [ -f /etc/default/rcS ]; then
Michael Biebl's avatar
Michael Biebl committed
41 42 43
        . /etc/default/rcS
    fi
    if [ "$UTC" = "no" ] && [ ! -e /etc/adjtime ]; then
Michael Biebl's avatar
Michael Biebl committed
44
        printf "0.0 0 0.0\n0\nLOCAL" > /etc/adjtime
Michael Biebl's avatar
Michael Biebl committed
45
    fi
Tollef Fog Heen's avatar
Tollef Fog Heen committed
46 47
fi

48
# Do a one-time migration of the TMPTIME setting
49 50 51
if dpkg --compare-versions "$2" lt "204-9"; then
    # Fix up potentially broken tmp.conf, see Debian#738862
    if [ -e /etc/tmpfiles.d/tmp.conf ]; then
52
        sed -i '/^# Clear \/var\/tmp/d' /etc/tmpfiles.d/tmp.conf
53 54 55
        sed -i 's,^\(d /var/tmp\),#\1,g' /etc/tmpfiles.d/tmp.conf
    fi

56 57 58 59 60 61 62
    if [ -f /etc/default/rcS ]; then
        . /etc/default/rcS
    fi
    if [ ! -e /etc/tmpfiles.d/tmp.conf ]; then
        case "$TMPTIME" in
            -*|infinite|infinity)
                cat > /etc/tmpfiles.d/tmp.conf <<EOF
63 64 65 66
# Avoid clearing /tmp by shipping an empty /etc/tmpfiles.d/tmp.conf file
# which overrides /usr/lib/tmpfiles.d/tmp.conf.
# This file was automatically created because of local modifications in
# /etc/default/rcS where TMPTIME was set to infinite.
67 68 69 70 71 72
EOF
                ;;
        esac
    fi
fi

73 74 75 76 77 78 79 80 81 82 83 84 85 86
# Do a one-time migration of the RAMTMP setting
if dpkg --compare-versions "$2" lt "204-8"; then
    if [ -f /etc/default/rcS ]; then
        . /etc/default/rcS
    fi
    if [ -f /etc/default/tmpfs ]; then
        . /etc/default/tmpfs
    fi
    if [ "$RAMTMP" = "yes" ]; then
        # systemctl enable will work even when systemd is not the active PID 1.
        systemctl enable tmp.mount || true
    fi
fi

87 88 89 90
if dpkg --compare-versions "$2" lt "40-1"; then
    # /lib/init/rw has been replaced by /run, so try to remove it on upgrades
    # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=643699
    _systemctl stop lib-init-rw.automount lib-init-rw.mount || true
91 92 93
    if [ -d /lib/init/rw ]; then
        rmdir --ignore-fail-on-non-empty /lib/init/rw || true
    fi
94 95
fi

96
# Create /etc/machine-id
97 98
systemd-machine-id-setup

Michael Biebl's avatar
Michael Biebl committed
99
# Setup system users and groups
Michael Biebl's avatar
Michael Biebl committed
100
addgroup --system systemd-journal
Michael Biebl's avatar
Michael Biebl committed
101 102 103 104 105 106 107

adduser --quiet --system --group --no-create-home --home /run/systemd \
    --gecos "systemd Time Synchronization" systemd-timesync
adduser --quiet --system --group --no-create-home --home /run/systemd/netif \
    --gecos "systemd Network Management" systemd-network
adduser --quiet --system --group --no-create-home --home /run/systemd/resolve \
    --gecos "systemd Resolver" systemd-resolve
108 109
adduser --quiet --system --group --no-create-home --home /run/systemd \
    --gecos "systemd Bus Proxy" systemd-bus-proxy
110

111
# Initial update of the Message Catalogs database
112 113
_update_catalog

114 115 116
# Make systemd-detect-virt utility usable for non-root users
setcap cap_dac_override,cap_sys_ptrace=ep /usr/bin/systemd-detect-virt || true

117 118 119 120
# We don’t ship /var/log/journal currently, so only run the following fix for
# systems where the administrator has explicitly enabled persistent logging by
# creating /var/log/journal.
if [ -d /var/log/journal ]; then
121 122 123 124 125
    # Grant read access to /var/log/journal for members of the adm group
    # via a filesystem ACL. This makes them able to read the journal.
    # Failure is ignored since there might be file systems mounted without
    # ACL support.
    setfacl -R -nm g:adm:rx,d:g:adm:rx /var/log/journal || true
126
fi
127

128 129 130 131 132 133 134 135
if [ -n "$2" ]; then
    _systemctl daemon-reexec || true
    _systemctl try-restart systemd-logind.service || true
    _systemctl try-restart systemd-networkd.service || true
    _systemctl try-restart systemd-resolved.service || true
    _systemctl try-restart systemd-timesyncd.service || true
fi

136 137 138 139 140 141 142 143
# Enable getty and remote-fs.target by default on new installs, and on
# upgrades from old systemd versions (where the symlinks included as deb
# content, and will thus have been removed by dpkg during the upgrade).
if dpkg --compare-versions "$2" lt "214-1"; then
    systemctl enable getty@tty1.service || true
    systemctl enable remote-fs.target || true
fi

144 145 146 147
if dpkg --compare-versions "$2" lt "215-13"; then
    systemctl enable hwclock-save.service || true
fi

148 149 150 151 152 153 154
# Re-run systemctl enable for any service that was enabled when preinst was run.
if dpkg --compare-versions "$2" ge "204"; then
    while read UNIT ; do
        systemctl enable $UNIT || true
    done </run/systemd/was-enabled || true
fi

155 156
# The /dev/log socket and /dev/initctl FIFO have been moved to /run and
# replaced by symlinks. Create the symlinks manually on upgrades as well.
157 158 159
# (https://bugs.debian.org/761340). Note that this will break the current
# journal as we cannot restart it properly (https://bugs.debian.org/771122) so
# this is mostly an one-time upgrade path from wheezy.
160 161 162 163 164 165 166
if dpkg --compare-versions "$2" lt-nl "215-3"; then
    if [ -p /run/systemd/initctl/fifo ] && [ ! -L /dev/initctl ]; then
         ln -sf /run/systemd/initctl/fifo /dev/initctl
    fi
    if [ -S /run/systemd/journal/dev-log ] && [ ! -L /dev/log ]; then
         ln -sf /run/systemd/journal/dev-log /dev/log
    fi
167
    _systemctl try-restart systemd-journald.service || true
168 169
fi

Tollef Fog Heen's avatar
Tollef Fog Heen committed
170
#DEBHELPER#