-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
qubes-core-agent.postinst
executable file
·239 lines (201 loc) · 7.94 KB
/
qubes-core-agent.postinst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash --
# postinst script for core-agent-linux
#
# see: dh_installdeb(1)
set -e
# The postinst script may be called in the following ways:
# * <postinst> 'configure' <most-recently-configured-version>
# * <old-postinst> 'abort-upgrade' <new version>
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
# <new-version>
# * <postinst> 'abort-remove'
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
# <failed-install-package> <version> 'removing'
# <conflicting-package> <version>
#
# For details, see http://www.debian.org/doc/debian-policy/ or
# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html or
# the debian-policy package
debug () {
if [ "${DEBDEBUG}" == "1" ]; then
echo -e "$@"
fi
}
# FIXME: add user units support to is_static()/is_masked()/mask()/unmask() functions
is_static () {
[ -f "/lib/systemd/system/$1" ] && ! grep -q '^[[].nstall]' "/lib/systemd/system/$1"
}
is_masked () {
if [ ! -L /etc/systemd/system/"$1" ]
then
return 1
fi
target=$(readlink /etc/systemd/system/"$1" 2>/dev/null || :)
if [ "$target" = "/dev/null" ]
then
return 0
fi
return 1
}
preset_units () {
local represet=
# shellcheck disable=SC2206
local extra_opts=( $3 )
while read -r action unit_name
do
if [ "$action" = "#" ] && [ "$unit_name" = "Units below this line will be re-preset on package upgrade" ]
then
represet=1
continue
fi
echo "$action $unit_name" | grep -q '^[[:space:]]*[^#;]' || continue
if [ -z "$action" ] || [ -z "$unit_name" ]; then
continue
fi
if [ "$2" = "initial" ] || [ "$represet" = "1" ]
then
if [ "$action" = "disable" ] && is_static "$unit_name"
then
if ! is_masked "$unit_name"
then
# We must effectively mask these units, even if they are static.
deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
fi
elif [ "$action" = "enable" ] && is_static "$unit_name"
then
if is_masked "$unit_name"
then
# We masked this static unit before, now we unmask it.
deb-systemd-helper unmask "${unit_name}" > /dev/null 2>&1 || true
fi
systemctl --no-reload "${extra_opts[@]}" preset "$unit_name" >/dev/null 2>&1 || :
else
systemctl --no-reload "${extra_opts[@]}" preset "$unit_name" >/dev/null 2>&1 || :
fi
fi
done < "$1"
systemctl daemon-reload >/dev/null 2>&1 || :
}
installSerialConf () {
debug "Installing over-ridden serial.conf init script..."
if [ -e /etc/init/serial.conf ]; then
cp /usr/share/qubes/serial.conf /etc/init/serial.conf
fi
}
case "${1}" in
configure)
# Initial installation of package only
# ($2 contains version number on update; nothing on initial installation)
if [ -z "${2}" ]; then
debug "FIRST INSTALL..."
# Location of files which contains list of protected files
# shellcheck source=init/functions
. /usr/lib/qubes/init/functions
# ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
# in the form expected by qubes-sysinit.sh
hostname=$(hostname)
if ! is_protected_file /etc/hostname ; then
for ip in '127\.0\.1\.1' '::1'; do
if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
sed -i "/^${ip}\s/,+0s/\(\s$hostname\)\+\(\s\|$\)/\2/g" /etc/hosts || true
sed -i "s/^${ip}\(\s\|$\).*$/\0 $hostname/" /etc/hosts || true
else
echo "${ip//\\/} $hostname" >> /etc/hosts || true
fi
done
fi
# remove hostname from 127.0.0.1 line (in debian the hostname is by default
# resolved to 127.0.1.1)
if ! is_protected_file /etc/hosts ; then
sed -i "/^127\.0\.0\.1\s/,+0s/\(\s$hostname\)\+\(\s\|$\)/\2/g" /etc/hosts || true
fi
# Set default "runlevel"
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
# Systemd preload-all
preset_units /lib/systemd/system-preset/75-qubes-vm.preset initial
# Maybe install overridden serial.conf init script
installSerialConf
else
preset_units /lib/systemd/system-preset/75-qubes-vm.preset upgrade
fi
systemctl reenable haveged || :
chgrp qubes /var/lib/qubes/dom0-updates
debug "UPDATE..."
# disable some Upstart services
for init in plymouth-shutdown \
prefdm \
splash-manager \
start-ttys \
tty ; do
dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
done
dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
if [ ! -L /etc/systemd/system/rpcbind.service ]; then
ln -s /dev/null /etc/systemd/system/rpcbind.service
fi
# Remove old firmware updates link
if [ -L /lib/firmware/updates ]; then
rm -f /lib/firmware/updates
fi
# convert /usr/local symlink to a mount point
if [ -L /usr/local ]; then
rm -f /usr/local
mkdir /usr/local
mount /usr/local || :
fi
# remove old symlinks
if [ -L /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service ]; then
rm /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service
fi
if [ -L /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service ]; then
rm /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service
fi
if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1 && { user=$(qubesdb-read /default-user) || user=user;} ; then
dpkg-statoverride --update --add -- "$user" qubes 775 /var/lib/qubes/dom0-updates
fi
glib-compile-schemas /usr/share/glib-2.0/schemas || true
if ! [ -r /etc/dconf/profile/user ]; then
mkdir -p /etc/dconf/profile
echo "user-db:user" >> /etc/dconf/profile/user
echo "system-db:local" >> /etc/dconf/profile/user
fi
if [ -x /usr/bin/dconf ]; then
dconf update
fi
/usr/lib/qubes/set-default-text-editor
# tell dom0 about installed updates (applications, features etc)
/etc/qubes-rpc/qubes.PostInstall || true
;;
abort-upgrade|abort-remove|abort-deconfigure)
exit 0
;;
triggered)
post_install_done=
for trigger in ${2}; do
case "${trigger}" in
/usr/share/applications|/etc/qubes/post-install.d|/etc/qubes-rpc)
debug "Updating Qubes App Menus and advertising features..."
if [ -z "$post_install_done" ]; then
/etc/qubes-rpc/qubes.PostInstall || true
post_install_done=1
fi
;;
# Install overridden serial.conf init script
/etc/init/serial.conf)
installSerialConf
;;
esac
done
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
# vim: set ts=4 sw=4 sts=4 et :