qubes-core-agent.postinst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 action unit_name; do
  31. case "${action}" in
  32. disable)
  33. if [ -e "/lib/systemd/system/${unit_name}" ]; then
  34. if ! fgrep -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. . /usr/lib/qubes/init/functions
  63. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  64. # in the form expected by qubes-sysinit.sh
  65. if ! is_protected_file /etc/hostname ; then
  66. for ip in '127\.0\.1\.1' '::1'; do
  67. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  68. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  69. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts || true
  70. else
  71. echo "${ip//\\/} `hostname`" >> /etc/hosts || true
  72. fi
  73. done
  74. fi
  75. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  76. # resolved to 127.0.1.1)
  77. if ! is_protected_file /etc/hosts ; then
  78. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  79. fi
  80. # Set default "runlevel"
  81. rm -f /etc/systemd/system/default.target
  82. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  83. # Systemd preload-all
  84. systemdPreload
  85. # Maybe install overridden serial.conf init script
  86. installSerialConf
  87. fi
  88. systemctl reenable haveged
  89. debug "UPDATE..."
  90. # disable some Upstart services
  91. for init in plymouth-shutdown \
  92. prefdm \
  93. splash-manager \
  94. start-ttys \
  95. tty ; do
  96. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  97. done
  98. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  99. if [ ! -L /etc/systemd/system/rpcbind.service ]; then
  100. ln -s /dev/null /etc/systemd/system/rpcbind.service
  101. fi
  102. # Remove old firmware updates link
  103. if [ -L /lib/firmware/updates ]; then
  104. rm -f /lib/firmware/updates
  105. fi
  106. # remove old symlinks
  107. if [ -L /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service ]; then
  108. rm /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service
  109. fi
  110. if [ -L /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service ]; then
  111. rm /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service
  112. fi
  113. if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1; then
  114. dpkg-statoverride --update --add user user 775 /var/lib/qubes/dom0-updates
  115. fi
  116. glib-compile-schemas /usr/share/glib-2.0/schemas || true
  117. # Update Qubes App Menus
  118. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  119. ;;
  120. abort-upgrade|abort-remove|abort-deconfigure)
  121. exit 0
  122. ;;
  123. triggered)
  124. for trigger in ${2}; do
  125. case "${trigger}" in
  126. /usr/share/applications)
  127. debug "Updating Qubes App Menus..."
  128. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  129. ;;
  130. # Install overridden serial.conf init script
  131. /etc/init/serial.conf)
  132. installSerialConf
  133. ;;
  134. esac
  135. done
  136. exit 0
  137. ;;
  138. *)
  139. echo "postinst called with unknown argument \`${1}'" >&2
  140. exit 1
  141. ;;
  142. esac
  143. # dh_installdeb will replace this with shell code automatically
  144. # generated by other debhelper scripts.
  145. #DEBHELPER#
  146. exit 0
  147. # vim: set ts=4 sw=4 sts=4 et :