qubes-core-agent.postinst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. is_static() {
  25. [ -f "/lib/sytemd/system/$1" ] && ! grep -q '^[[].nstall]' "/lib/systemd/system/$1"
  26. }
  27. is_masked() {
  28. if [ ! -L /etc/systemd/system/"$1" ]
  29. then
  30. return 1
  31. fi
  32. target=$(readlink /etc/systemd/system/"$1" 2>/dev/null || :)
  33. if [ "$target" = "/dev/null" ]
  34. then
  35. return 0
  36. fi
  37. return 1
  38. }
  39. mask() {
  40. ln -sf /dev/null /etc/systemd/system/"$1"
  41. }
  42. unmask() {
  43. if ! is_masked "$1"
  44. then
  45. return 0
  46. fi
  47. rm -f /etc/systemd/system/"$1"
  48. }
  49. preset_units() {
  50. local represet=
  51. while read -r action unit_name
  52. do
  53. if [ "$action" = "#" ] && [ "$unit_name" = "Units below this line will be re-preset on package upgrade" ]
  54. then
  55. represet=1
  56. continue
  57. fi
  58. echo "$action $unit_name" | grep -q '^[[:space:]]*[^#;]' || continue
  59. if [ -z "$action" ] || [ -z "$unit_name" ]; then
  60. continue
  61. fi
  62. if [ "$2" = "initial" ] || [ "$represet" = "1" ]
  63. then
  64. if [ "$action" = "disable" ] && is_static "$unit_name"
  65. then
  66. if ! is_masked "$unit_name"
  67. then
  68. # We must effectively mask these units, even if they are static.
  69. deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
  70. fi
  71. elif [ "$action" = "enable" ] && is_static "$unit_name"
  72. then
  73. if is_masked "$unit_name"
  74. then
  75. # We masked this static unit before, now we unmask it.
  76. deb-systemd-helper unmask "${unit_name}" > /dev/null 2>&1 || true
  77. fi
  78. systemctl --no-reload preset "$unit_name" >/dev/null 2>&1 || :
  79. else
  80. systemctl --no-reload preset "$unit_name" >/dev/null 2>&1 || :
  81. fi
  82. fi
  83. done < "$1"
  84. systemctl daemon-reload
  85. }
  86. installSerialConf() {
  87. debug "Installing over-ridden serial.conf init script..."
  88. if [ -e /etc/init/serial.conf ]; then
  89. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  90. fi
  91. }
  92. case "${1}" in
  93. configure)
  94. # Initial installation of package only
  95. # ($2 contains version number on update; nothing on initial installation)
  96. if [ -z "${2}" ]; then
  97. debug "FIRST INSTALL..."
  98. # Location of files which contains list of protected files
  99. # shellcheck source=init/functions
  100. . /usr/lib/qubes/init/functions
  101. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  102. # in the form expected by qubes-sysinit.sh
  103. if ! is_protected_file /etc/hostname ; then
  104. for ip in '127\.0\.1\.1' '::1'; do
  105. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  106. sed -i "/^${ip}\s/,+0s/\(\s$(hostname)\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  107. sed -i "s/^${ip}\(\s\|$\).*$/\0 $(hostname)/" /etc/hosts || true
  108. else
  109. echo "${ip//\\/} $(hostname)" >> /etc/hosts || true
  110. fi
  111. done
  112. fi
  113. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  114. # resolved to 127.0.1.1)
  115. if ! is_protected_file /etc/hosts ; then
  116. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s$(hostname)\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  117. fi
  118. # Set default "runlevel"
  119. rm -f /etc/systemd/system/default.target
  120. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  121. # Systemd preload-all
  122. preset_units /lib/systemd/system-preset/75-qubes-vm.preset initial
  123. # Maybe install overridden serial.conf init script
  124. installSerialConf
  125. else
  126. preset_units /lib/systemd/system-preset/75-qubes-vm.preset upgrade
  127. fi
  128. systemctl reenable haveged
  129. chgrp user /var/lib/qubes/dom0-updates
  130. debug "UPDATE..."
  131. # disable some Upstart services
  132. for init in plymouth-shutdown \
  133. prefdm \
  134. splash-manager \
  135. start-ttys \
  136. tty ; do
  137. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  138. done
  139. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  140. if [ ! -L /etc/systemd/system/rpcbind.service ]; then
  141. ln -s /dev/null /etc/systemd/system/rpcbind.service
  142. fi
  143. # Remove old firmware updates link
  144. if [ -L /lib/firmware/updates ]; then
  145. rm -f /lib/firmware/updates
  146. fi
  147. # convert /usr/local symlink to a mount point
  148. if [ -L /usr/local ]; then
  149. rm -f /usr/local
  150. mkdir /usr/local
  151. mount /usr/local || :
  152. fi
  153. # remove old symlinks
  154. if [ -L /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service ]; then
  155. rm /etc/systemd/system/sysinit.target.wants/qubes-random-seed.service
  156. fi
  157. if [ -L /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service ]; then
  158. rm /etc/systemd/system/multi-user.target.wants/qubes-mount-home.service
  159. fi
  160. if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1; then
  161. dpkg-statoverride --update --add user user 775 /var/lib/qubes/dom0-updates
  162. fi
  163. glib-compile-schemas /usr/share/glib-2.0/schemas || true
  164. if ! [ -r /etc/dconf/profile/user ]; then
  165. mkdir -p /etc/dconf/profile
  166. echo "user-db:user" >> /etc/dconf/profile/user
  167. echo "system-db:local" >> /etc/dconf/profile/user
  168. fi
  169. if [ -x /usr/bin/dconf ]; then
  170. dconf update
  171. fi
  172. # tell dom0 about installed updates (applications, features etc)
  173. /etc/qubes-rpc/qubes.PostInstall || true
  174. ;;
  175. abort-upgrade|abort-remove|abort-deconfigure)
  176. exit 0
  177. ;;
  178. triggered)
  179. for trigger in ${2}; do
  180. case "${trigger}" in
  181. /usr/share/applications)
  182. debug "Updating Qubes App Menus and advertising features..."
  183. /etc/qubes-rpc/qubes.PostInstall || true
  184. ;;
  185. # Install overridden serial.conf init script
  186. /etc/init/serial.conf)
  187. installSerialConf
  188. ;;
  189. esac
  190. done
  191. exit 0
  192. ;;
  193. *)
  194. echo "postinst called with unknown argument \`${1}'" >&2
  195. exit 1
  196. ;;
  197. esac
  198. # dh_installdeb will replace this with shell code automatically
  199. # generated by other debhelper scripts.
  200. #DEBHELPER#
  201. exit 0
  202. # vim: set ts=4 sw=4 sts=4 et :