qubes-core-agent.postinst 6.3 KB

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