qubes-core-agent.postinst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  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 ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; 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 ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  78. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  79. fi
  80. chown user:user /home_volatile/user
  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. 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. # Remove old firmware updates link
  100. if [ -L /lib/firmware/updates ]; then
  101. rm -f /lib/firmware/updates
  102. fi
  103. if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1; then
  104. dpkg-statoverride --update --add user user 775 /var/lib/qubes/dom0-updates
  105. fi
  106. # Update Qubes App Menus
  107. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  108. ;;
  109. abort-upgrade|abort-remove|abort-deconfigure)
  110. exit 0
  111. ;;
  112. triggered)
  113. for trigger in ${2}; do
  114. case "${trigger}" in
  115. /usr/share/applications)
  116. debug "Updating Qubes App Menus..."
  117. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  118. ;;
  119. # Install overridden serial.conf init script
  120. /etc/init/serial.conf)
  121. installSerialConf
  122. ;;
  123. esac
  124. done
  125. exit 0
  126. ;;
  127. *)
  128. echo "postinst called with unknown argument \`${1}'" >&2
  129. exit 1
  130. ;;
  131. esac
  132. # dh_installdeb will replace this with shell code automatically
  133. # generated by other debhelper scripts.
  134. #DEBHELPER#
  135. exit 0
  136. # vim: set ts=4 sw=4 sts=4 et :