qubes-core-agent.postinst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #!/bin/bash
  2. # postinst script for core-agent-linux
  3. #
  4. # see: dh_installdeb(1)
  5. set -e
  6. # The postint 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. # Directory that modified desktop entry config files are stored in
  20. XDG_CONFIG_QUBES="/usr/share/qubes/xdg"
  21. remove_ShowIn() {
  22. if [ -e "${1}" ]; then
  23. sed -i '/^\(Not\|Only\)ShowIn/d' "${1}"
  24. fi
  25. }
  26. showIn() {
  27. desktop_entry="${1}"
  28. shown_in="${2}"
  29. message="${shown_in:-"Shown in All;"}"
  30. desktop_entry_qubes="${XDG_CONFIG_QUBES}/autostart/${desktop_entry##*/}"
  31. # Make sure Qubes autostart directory exists
  32. mkdir -p "${XDG_CONFIG_QUBES}/autostart"
  33. # Desktop entry exists, so move to Qubes directory and modify it
  34. if [ -e "${desktop_entry}" ]; then
  35. echo "Desktop Entry Modification - ${message} ${desktop_entry##*/}..."
  36. cp -pf "${desktop_entry}" "${desktop_entry_qubes}"
  37. remove_ShowIn "${desktop_entry_qubes}"
  38. sed -i '/^X-GNOME-Autostart-enabled.*[fF0]/d' "${desktop_entry_qubes}"
  39. # Will only be '' if shown in all
  40. if [ ! "${shown_in}x" == "x" ]; then
  41. echo "${shown_in}" >> "${desktop_entry_qubes}" || true
  42. fi
  43. # Desktop entry must have been removed, so also remove from Qubes directory
  44. else
  45. echo "Desktop Entry Modification - Remove: ${desktop_entry##*/}..."
  46. rm -f "${desktop_entry_qubes}"
  47. fi
  48. }
  49. systemdPreload() {
  50. # Debian systemd helper does not yet honour preset, therefore use
  51. # systemctl preset on each unit file (not using preset-all either since
  52. # wheezy does not support it) listed in 75-qubes-vm.preset.
  53. systemctl --no-reload preset-all > /dev/null 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
  54. # Mask any static unit files that are marked to be disabled
  55. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
  56. case "${action}" in
  57. disable)
  58. if [ -e "/lib/systemd/system/${unit_name}" ]; then
  59. if ! fgrep -q '[Install]' "/lib/systemd/system/${unit_name}"; then
  60. deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
  61. fi
  62. fi
  63. ;;
  64. *)
  65. # preset-all is not available in wheezy; so preset each unit file listed in 75-qubes-vm.preset
  66. if [ "${PRESET_FAILED}" -eq 1 ]; then
  67. systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
  68. fi
  69. ;;
  70. esac
  71. done
  72. systemctl daemon-reload
  73. }
  74. # Manually trigger all triggers to automaticatly configure
  75. triggerTriggers() {
  76. path="$(readlink -m ${0})"
  77. triggers="${path/postinst/triggers}"
  78. awk '{sub(/[ \t]*#.*/,"")} NF' ${triggers} | while read line
  79. do
  80. /bin/bash -c "${0} triggered ${line##* }" || true
  81. done
  82. }
  83. case "${1}" in
  84. configure)
  85. # disable some Upstart services
  86. for init in plymouth-shutdown \
  87. prefdm \
  88. splash-manager \
  89. start-ttys \
  90. tty ; do
  91. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  92. done
  93. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  94. # Create NetworkManager configuration if we do not have it
  95. if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
  96. echo '[main]' > /etc/NetworkManager/NetworkManager.conf
  97. echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
  98. echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
  99. fi
  100. /usr/lib/qubes/qubes-fix-nm-conf.sh
  101. # make sure locale is really generated
  102. current_locale=`grep 'LANG\|LC_ALL' /etc/default/locale|head -n 1|cut -f 2 -d =`
  103. if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
  104. base=`echo "$current_locale" | cut -f 1 -d .`
  105. charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
  106. [ -n "$charmap" ] && charmap="-f $charmap"
  107. localedef -i $base $charmap $current_locale
  108. fi
  109. # Remove old firmware updates link
  110. if [ -L /lib/firmware/updates ]; then
  111. rm -f /lib/firmware/updates
  112. fi
  113. # Location of files which contains list of protected files
  114. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  115. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  116. # in the form expected by qubes-sysinit.sh
  117. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  118. for ip in '127\.0\.1\.1' '::1'; do
  119. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  120. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  121. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts || true
  122. else
  123. echo "${ip//\\/} `hostname`" >> /etc/hosts || true
  124. fi
  125. done
  126. fi
  127. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  128. # resolved to 127.0.1.1)
  129. if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  130. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts || true
  131. fi
  132. chown user:user /home_volatile/user
  133. if ! dpkg-statoverride --list /var/lib/qubes/dom0-updates >/dev/null 2>&1; then
  134. dpkg-statoverride --update --add user user 775 /var/lib/qubes/dom0-updates
  135. fi
  136. # Set default "runlevel"
  137. rm -f /etc/systemd/system/default.target
  138. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  139. ## Systemd preload-all
  140. systemdPreload
  141. ## Process all triggers which will set defaults to wanted values
  142. triggerTriggers
  143. ;;
  144. abort-upgrade|abort-remove|abort-deconfigure)
  145. exit 0
  146. ;;
  147. triggered)
  148. for trigger in ${2}; do
  149. case "${trigger}" in
  150. # Update Qubes App Menus
  151. /usr/share/applications)
  152. echo "Updating Qubes App Menus..."
  153. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  154. ## Systemd preload-all
  155. #systemdPreload
  156. ;;
  157. # Install overridden serial.conf init script
  158. /etc/init/serial.conf)
  159. echo "Installing over-ridden serial.conf init script..."
  160. if [ -e /etc/init/serial.conf ]; then
  161. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  162. fi
  163. ;;
  164. # Disable SELinux"
  165. /etc/selinux/config)
  166. echo "Disabling SELinux..."
  167. if [ -e /etc/selinux/config ]; then
  168. sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  169. mv /etc/selinux/config.processed /etc/selinux/config
  170. setenforce 0 2>/dev/null
  171. fi
  172. ;;
  173. # Desktop Entry Modification - Remove existing rules
  174. /etc/xdg/autostart/gpk-update-icon.desktop | \
  175. /etc/xdg/autostart/nm-applet.desktop | \
  176. /etc/xdg/autostart/abrt-applet.desktop | \
  177. /etc/xdg/autostart/notify-osd.desktop)
  178. showIn "${trigger}"
  179. ;;
  180. # Desktop Entry Modification - Not shown in Qubes
  181. /etc/xdg/autostart/pulseaudio.desktop | \
  182. /etc/xdg/autostart/deja-dup-monitor.desktop | \
  183. /etc/xdg/autostart/imsettings-start.desktop | \
  184. /etc/xdg/autostart/krb5-auth-dialog.desktop | \
  185. /etc/xdg/autostart/pulseaudio.desktop | \
  186. /etc/xdg/autostart/restorecond.desktop | \
  187. /etc/xdg/autostart/sealertauto.desktop | \
  188. /etc/xdg/autostart/gnome-power-manager.desktop | \
  189. /etc/xdg/autostart/gnome-sound-applet.desktop | \
  190. /etc/xdg/autostart/gnome-screensaver.desktop | \
  191. /etc/xdg/autostart/orca-autostart.desktop)
  192. showIn "${trigger}" 'NotShowIn=QUBES;'
  193. ;;
  194. # Desktop Entry Modification - Not shown in in DisposableVM
  195. /etc/xdg/autostart/gcm-apply.desktop)
  196. showIn "${trigger}" 'NotShowIn=DisposableVM;'
  197. ;;
  198. # Desktop Entry Modification - Only shown in AppVM
  199. /etc/xdg/autostart/gnome-keyring-gpg.desktop | \
  200. /etc/xdg/autostart/gnome-keyring-pkcs11.desktop | \
  201. /etc/xdg/autostart/gnome-keyring-secrets.desktop | \
  202. /etc/xdg/autostart/gnome-keyring-ssh.desktop | \
  203. /etc/xdg/autostart/gnome-settings-daemon.desktop | \
  204. /etc/xdg/autostart/user-dirs-update-gtk.desktop | \
  205. /etc/xdg/autostart/gsettings-data-convert.desktop)
  206. showIn "${trigger}" 'OnlyShowIn=GNOME;AppVM;'
  207. ;;
  208. # Desktop Entry Modification - Only shown in Gnome & UpdateableVM
  209. /etc/xdg/autostart/gpk-update-icon.desktop)
  210. showIn "${trigger}" 'OnlyShowIn=GNOME;UpdateableVM;'
  211. ;;
  212. # Desktop Entry Modification - Only shown in Gnome & Qubes
  213. /etc/xdg/autostart/nm-applet.desktop)
  214. showIn "${trigger}" 'OnlyShowIn=GNOME;QUBES;'
  215. ;;
  216. *)
  217. echo "postinst called with unknown trigger \`${2}'" >&2
  218. exit 1
  219. ;;
  220. esac
  221. done
  222. exit 0
  223. ;;
  224. *)
  225. echo "postinst called with unknown argument \`${1}'" >&2
  226. exit 1
  227. ;;
  228. esac
  229. # dh_installdeb will replace this with shell code automatically
  230. # generated by other debhelper scripts.
  231. #DEBHELPER#
  232. exit 0
  233. # vim: set ts=4 sw=4 sts=4 et :