qubes-core-agent.postinst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/bash
  2. # postinst script for core-agent-linux
  3. #
  4. # see: dh_installdeb(1)
  5. set -e
  6. # The postinst 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. debug() {
  20. if [ "${DEBDEBUG}" == "1" ]; then
  21. echo -e "$@"
  22. fi
  23. }
  24. systemdPreload() {
  25. # Debian systemd helper does not yet honour preset, therefore use
  26. # systemctl preset on each unit file (not using preset-all either since
  27. # wheezy does not support it) listed in 75-qubes-vm.preset.
  28. systemctl --no-reload preset-all > /dev/null 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
  29. # Mask any static unit files that are marked to be disabled
  30. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read -r action unit_name; do
  31. case "${action}" in
  32. disable)
  33. if [ -e "/lib/systemd/system/${unit_name}" ]; then
  34. if ! grep -F -q '[Install]' "/lib/systemd/system/${unit_name}"; then
  35. deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
  36. fi
  37. fi
  38. ;;
  39. *)
  40. # preset-all is not available in wheezy; so preset each unit file listed in 75-qubes-vm.preset
  41. if [ "${PRESET_FAILED}" -eq 1 ]; then
  42. systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
  43. fi
  44. ;;
  45. esac
  46. done
  47. systemctl daemon-reload
  48. }
  49. installSerialConf() {
  50. debug "Installing over-ridden serial.conf init script..."
  51. if [ -e /etc/init/serial.conf ]; then
  52. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  53. fi
  54. }
  55. case "${1}" in
  56. configure)
  57. # Initial installation of package only
  58. # ($2 contains version number on update; nothing on initial installation)
  59. if [ -z "${2}" ]; then
  60. debug "FIRST INSTALL..."
  61. # Location of files which contains list of protected files
  62. # shellcheck source=init/functions
  63. . /usr/lib/qubes/init/functions
  64. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  65. # in the form expected by qubes-sysinit.sh
  66. if ! is_protected_file /etc/hostname ; then
  67. for ip in '127\.0\.1\.1' '::1'; do
  68. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  69. sed -i "/^${ip}\s/,+0s/\(\s$(hostname)\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  70. sed -i "s/^${ip}\(\s\|$\).*$/\0 $(hostname)/" /etc/hosts || true
  71. else
  72. echo "${ip//\\/} $(hostname)" >> /etc/hosts || true
  73. fi
  74. done
  75. fi
  76. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  77. # resolved to 127.0.1.1)
  78. if ! is_protected_file /etc/hosts ; then
  79. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s$(hostname)\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  80. fi
  81. # Set default "runlevel"
  82. rm -f /etc/systemd/system/default.target
  83. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  84. # Systemd preload-all
  85. systemdPreload
  86. # Maybe install overridden serial.conf init script
  87. installSerialConf
  88. fi
  89. systemctl reenable haveged
  90. debug "UPDATE..."
  91. # disable some Upstart services
  92. for init in plymouth-shutdown \
  93. prefdm \
  94. splash-manager \
  95. start-ttys \
  96. tty ; do
  97. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  98. done
  99. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  100. if [ ! -L /etc/systemd/system/rpcbind.service ]; then
  101. ln -s /dev/null /etc/systemd/system/rpcbind.service
  102. fi
  103. # Remove old firmware updates link
  104. if [ -L /lib/firmware/updates ]; then
  105. rm -f /lib/firmware/updates
  106. fi
  107. # remove old symlinks
  108. if [ -L /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service ]; then
  109. rm /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service
  110. fi
  111. if [ -L /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service ]; then
  112. rm /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service
  113. fi
  114. if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1; then
  115. dpkg-statoverride --update --add user user 775 /var/lib/qubes/dom0-updates
  116. fi
  117. glib-compile-schemas /usr/share/glib-2.0/schemas || true
  118. # Update Qubes App Menus
  119. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  120. ;;
  121. abort-upgrade|abort-remove|abort-deconfigure)
  122. exit 0
  123. ;;
  124. triggered)
  125. for trigger in ${2}; do
  126. case "${trigger}" in
  127. /usr/share/applications)
  128. debug "Updating Qubes App Menus..."
  129. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  130. ;;
  131. # Install overridden serial.conf init script
  132. /etc/init/serial.conf)
  133. installSerialConf
  134. ;;
  135. esac
  136. done
  137. exit 0
  138. ;;
  139. *)
  140. echo "postinst called with unknown argument \`${1}'" >&2
  141. exit 1
  142. ;;
  143. esac
  144. # dh_installdeb will replace this with shell code automatically
  145. # generated by other debhelper scripts.
  146. #DEBHELPER#
  147. exit 0
  148. # vim: set ts=4 sw=4 sts=4 et :