qubes-core-agent.postinst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. #!/bin/bash
  2. # postinst script for core-agent-linux
  3. #
  4. # see: dh_installdeb(1)
  5. set -e
  6. # The postint script may be called in the following ways:
  7. # * <postinst> 'configure' <most-recently-configured-version>
  8. # * <old-postinst> 'abort-upgrade' <new version>
  9. # * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
  10. # <new-version>
  11. # * <postinst> 'abort-remove'
  12. # * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
  13. # <failed-install-package> <version> 'removing'
  14. # <conflicting-package> <version>
  15. #
  16. # For details, see http://www.debian.org/doc/debian-policy/ or
  17. # https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html or
  18. # the debian-policy package
  19. # Directory that modified desktop entry config files are stored in
  20. XDG_CONFIG_QUBES="/usr/share/qubes/xdg"
  21. # Install overriden services only when original exists
  22. installOverridenServices() {
  23. override_dir="${1}"
  24. service="${2}"
  25. retval=1
  26. for unit in ${service}; do
  27. unit="${unit%%.*}"
  28. unit_name="$(basename ${unit})"
  29. if [ -f ${unit}.service ]; then
  30. echo "Installing override for ${unit}.service..."
  31. cp ${override_dir}/${unit_name}.service /etc/systemd/system/
  32. retval=0
  33. fi
  34. if [ -f ${unit}.socket -a -f ${override_dir}/${unit}.socket ]; then
  35. echo "Installing override for ${unit}.socket..."
  36. cp ${override_dir}/${unit_name}.socket /etc/systemd/system/
  37. retval=0
  38. fi
  39. if [ -f ${unit}.path -a -f ${override_dir}/${unit}.path ]; then
  40. echo "Installing override for ${unit}.path..."
  41. cp ${override_dir}/${unit_name}.path /etc/systemd/system/
  42. retval=0
  43. fi
  44. done
  45. return ${retval}
  46. }
  47. reenableNetworkManager() {
  48. # Disable original service to enable overriden one
  49. echo "Disabling original service to enable overriden one..."
  50. disableSystemdUnits ModemManager.service
  51. disableSystemdUnits NetworkManager.service
  52. # Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)
  53. echo "Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)"
  54. systemctl mask dbus-org.freedesktop.NetworkManager.service 2> /dev/null || echo "Could not disable D-BUS activation of NetworkManager"
  55. echo "Re-enabling original service to enable overriden one..."
  56. enableSystemdUnits ModemManager.service
  57. enableSystemdUnits NetworkManager.service
  58. # Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811
  59. echo "Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811"
  60. enableSystemdUnits NetworkManager-dispatcher.service
  61. }
  62. remove_ShowIn() {
  63. if [ -e "${1}" ]; then
  64. sed -i '/^\(Not\|Only\)ShowIn/d' "${1}"
  65. fi
  66. }
  67. showIn() {
  68. desktop_entry="${1}"
  69. shown_in="${2}"
  70. message="${shown_in:-"Shown in All;"}"
  71. desktop_entry_qubes="${XDG_CONFIG_QUBES}/autostart/${desktop_entry##*/}"
  72. # Make sure Qubes autostart directory exists
  73. mkdir -p "${XDG_CONFIG_QUBES}/autostart"
  74. # Desktop entry exists, so move to Qubes directory and modify it
  75. if [ -e "${desktop_entry}" ]; then
  76. echo "Desktop Entry Modification - ${message} ${desktop_entry##*/}..."
  77. cp -pf "${desktop_entry}" "${desktop_entry_qubes}"
  78. remove_ShowIn "${desktop_entry_qubes}"
  79. sed -i '/^X-GNOME-Autostart-enabled.*[fF0]/d' "${desktop_entry_qubes}"
  80. # Will only be '' if shown in all
  81. if [ ! "${shown_in}x" == "x" ]; then
  82. echo "${shown_in}" >> "${desktop_entry_qubes}" || true
  83. fi
  84. # Desktop entry must have been removed, so also remove from Qubes directory
  85. else
  86. echo "Desktop Entry Modification - Remove: ${desktop_entry##*/}..."
  87. rm -f "${desktop_entry_qubes}"
  88. fi
  89. }
  90. changeSystemdStatus() {
  91. unit=${1}
  92. disable=${2-0}
  93. # Check if unit file is currently active (running)
  94. systemctl is-active ${unit} > /dev/null 2>&1 && active=true || unset active
  95. case ${disable} in
  96. 0)
  97. systemctl --quiet enable ${unit} > /dev/null 2>&1 || true
  98. ;;
  99. 1)
  100. if [ $active ]; then
  101. systemctl --quiet stop ${unit} > /dev/null 2>&1 || true
  102. fi
  103. if [ -f /lib/systemd/system/${unit} ]; then
  104. if fgrep -q '[Install]' /lib/systemd/system/${unit}; then
  105. systemctl --quiet disable ${unit} > /dev/null 2>&1 || true
  106. else
  107. # Forcibly disable
  108. ln -sf /dev/null /etc/systemd/system/${unit}
  109. fi
  110. else
  111. systemctl --quiet disable ${unit} > /dev/null 2>&1 || true
  112. fi
  113. ;;
  114. esac
  115. }
  116. # Enable systemd units
  117. enableSystemdUnits() {
  118. for unit in $*; do
  119. changeSystemdStatus ${unit} 0 || true
  120. done
  121. }
  122. # Disable systemd units
  123. disableSystemdUnits() {
  124. for unit in $*; do
  125. changeSystemdStatus ${unit} 1 || true
  126. done
  127. }
  128. # Manually trigger all triggers to automaticatly configure
  129. triggerTriggers() {
  130. path="$(readlink -m ${0})"
  131. triggers="${path/postinst/triggers}"
  132. awk '{sub(/[ \t]*#.*/,"")} NF' ${triggers} | while read line
  133. do
  134. /bin/bash -c "${0} triggered ${line##* }" || true
  135. done
  136. }
  137. case "${1}" in
  138. configure)
  139. # disable some Upstart services
  140. for init in plymouth-shutdown \
  141. prefdm \
  142. splash-manager \
  143. start-ttys \
  144. tty ; do
  145. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  146. done
  147. # Disable sysv init network-manager
  148. disableSystemdUnits network-manager
  149. # Create NetworkManager configuration if we do not have it
  150. if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
  151. echo '[main]' > /etc/NetworkManager/NetworkManager.conf
  152. echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
  153. echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
  154. fi
  155. /usr/lib/qubes/qubes-fix-nm-conf.sh
  156. # Remove old firmware updates link
  157. if [ -L /lib/firmware/updates ]; then
  158. rm -f /lib/firmware/updates
  159. fi
  160. # Location of files which contains list of protected files
  161. PROTECTED_FILE_LIST='/var/lib/qubes/protected-files'
  162. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  163. # in the form expected by qubes-sysinit.sh
  164. if ! grep -q "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  165. for ip in '127\.0\.1\.1' '::1'; do
  166. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  167. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  168. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts || true
  169. else
  170. echo "${ip//\\/} `hostname`" >> /etc/hosts || true
  171. fi
  172. done
  173. fi
  174. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  175. # resolved to 127.0.1.1)
  176. if ! grep -q "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  177. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  178. fi
  179. chown user:user /home_volatile/user
  180. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  181. # Enable Qubes systemd units
  182. enableSystemdUnits \
  183. qubes-sysinit.service \
  184. qubes-misc-post.service \
  185. qubes-netwatcher.service \
  186. qubes-network.service \
  187. qubes-firewall.service \
  188. qubes-updates-proxy.service \
  189. qubes-update-check.timer \
  190. qubes-qrexec-agent.service
  191. # Set default "runlevel"
  192. rm -f /etc/systemd/system/default.target
  193. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  194. # Process all triggers which will set defaults to wanted values
  195. triggerTriggers
  196. disableSystemdUnits \
  197. alsa-store.service \
  198. alsa-restore.service \
  199. auditd.service \
  200. avahi.service \
  201. avahi-daemon.service \
  202. backuppc.service \
  203. cpuspeed.service \
  204. crond.service \
  205. fedora-autorelabel.service \
  206. fedora-autorelabel-mark.service \
  207. ipmi.service \
  208. hwclock-load.service \
  209. hwclock-save.service \
  210. mdmonitor.service \
  211. multipathd.service \
  212. openct.service \
  213. rpcbind.service \
  214. mcelog.service \
  215. fedora-storage-init.service \
  216. fedora-storage-init-late.service \
  217. plymouth-start.service \
  218. plymouth-read-write.service \
  219. plymouth-quit.service \
  220. plymouth-quit-wait.service \
  221. sshd.service \
  222. tcsd.service \
  223. sm-client.service \
  224. sendmail.service \
  225. mdmonitor-takeover.service \
  226. rngd smartd.service \
  227. upower.service \
  228. irqbalance.service \
  229. colord.service
  230. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  231. # Enable other systemd units
  232. enableSystemdUnits \
  233. rsyslog.service \
  234. netfilter-persistent.service
  235. # XXX: TODO: Needs to be implemented still
  236. # These do not exist on debian; maybe a different package name
  237. # ntpd.service \
  238. ;;
  239. abort-upgrade|abort-remove|abort-deconfigure)
  240. exit 0
  241. ;;
  242. triggered)
  243. for trigger in ${2}; do
  244. case "${trigger}" in
  245. # Update Qubes App Menus
  246. /usr/share/applications)
  247. echo "Updating Qubes App Menus..."
  248. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  249. ;;
  250. # Install overriden services only when original exists
  251. /lib/systemd/system/NetworkManager.service | \
  252. /lib/systemd/system/NetworkManager-wait-online.service | \
  253. /lib/systemd/system/ModemManager.service)
  254. UNITDIR=/lib/systemd/system
  255. OVERRIDEDIR=/usr/lib/qubes/init
  256. installOverridenServices "${OVERRIDEDIR}" "${trigger}"
  257. if [ $? -eq 0 ]; then
  258. reenableNetworkManager
  259. fi
  260. ;;
  261. # Enable cups only when it is real Systemd service
  262. /lib/systemd/system/cups.service)
  263. [ -e /lib/systemd/system/cups.service ] && enableSystemdUnits cups.service
  264. ;;
  265. # "Enable haveged service"
  266. /lib/systemd/system/haveged.service)
  267. [ -e /lib/systemd/system/haveged.service ] && enableSystemdUnits haveged.service
  268. ;;
  269. # Install overridden serial.conf init script
  270. /etc/init/serial.conf)
  271. echo "Installing over-ridden serial.conf init script..."
  272. if [ -e /etc/init/serial.conf ]; then
  273. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  274. fi
  275. ;;
  276. # Disable SELinux"
  277. /etc/selinux/config)
  278. echo "Disabling SELinux..."
  279. if [ -e /etc/selinux/config ]; then
  280. sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  281. mv /etc/selinux/config.processed /etc/selinux/config
  282. setenforce 0 2>/dev/null
  283. fi
  284. ;;
  285. # Desktop Entry Modification - Remove existing rules
  286. /etc/xdg/autostart/gpk-update-icon.desktop | \
  287. /etc/xdg/autostart/nm-applet.desktop | \
  288. /etc/xdg/autostart/abrt-applet.desktop | \
  289. /etc/xdg/autostart/notify-osd.desktop)
  290. showIn "${trigger}"
  291. ;;
  292. # Desktop Entry Modification - Not shown in Qubes
  293. /etc/xdg/autostart/pulseaudio.desktop | \
  294. /etc/xdg/autostart/deja-dup-monitor.desktop | \
  295. /etc/xdg/autostart/imsettings-start.desktop | \
  296. /etc/xdg/autostart/krb5-auth-dialog.desktop | \
  297. /etc/xdg/autostart/pulseaudio.desktop | \
  298. /etc/xdg/autostart/restorecond.desktop | \
  299. /etc/xdg/autostart/sealertauto.desktop | \
  300. /etc/xdg/autostart/gnome-power-manager.desktop | \
  301. /etc/xdg/autostart/gnome-sound-applet.desktop | \
  302. /etc/xdg/autostart/gnome-screensaver.desktop | \
  303. /etc/xdg/autostart/orca-autostart.desktop)
  304. showIn "${trigger}" 'NotShowIn=QUBES;'
  305. ;;
  306. # Desktop Entry Modification - Not shown in in DisposableVM
  307. /etc/xdg/autostart/gcm-apply.desktop)
  308. showIn "${trigger}" 'NotShowIn=DisposableVM;'
  309. ;;
  310. # Desktop Entry Modification - Only shown in AppVM
  311. /etc/xdg/autostart/gnome-keyring-gpg.desktop | \
  312. /etc/xdg/autostart/gnome-keyring-pkcs11.desktop | \
  313. /etc/xdg/autostart/gnome-keyring-secrets.desktop | \
  314. /etc/xdg/autostart/gnome-keyring-ssh.desktop | \
  315. /etc/xdg/autostart/gnome-settings-daemon.desktop | \
  316. /etc/xdg/autostart/user-dirs-update-gtk.desktop | \
  317. /etc/xdg/autostart/gsettings-data-convert.desktop)
  318. showIn "${trigger}" 'OnlyShowIn=GNOME;AppVM;'
  319. ;;
  320. # Desktop Entry Modification - Only shown in Gnome & UpdateableVM
  321. /etc/xdg/autostart/gpk-update-icon.desktop)
  322. showIn "${trigger}" 'OnlyShowIn=GNOME;UpdateableVM;'
  323. ;;
  324. # Desktop Entry Modification - Only shown in Gnome & Qubes
  325. /etc/xdg/autostart/nm-applet.desktop)
  326. showIn "${trigger}" 'OnlyShowIn=GNOME;QUBES;'
  327. ;;
  328. *)
  329. echo "postinst called with unknown trigger \`${2}'" >&2
  330. exit 1
  331. ;;
  332. esac
  333. done
  334. ;;
  335. *)
  336. echo "postinst called with unknown argument \`${1}'" >&2
  337. exit 1
  338. ;;
  339. esac
  340. # dh_installdeb will replace this with shell code automatically
  341. # generated by other debhelper scripts.
  342. #DEBHELPER#
  343. exit 0
  344. # vim: set ts=4 sw=4 sts=4 et :