qubes-core-agent.postinst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. # Install overriden services only when original exists
  22. installOverridenServices() {
  23. override_dir="${1}"
  24. service="${2}"
  25. retval=1
  26. for unit in ${service}; do
  27. unit="${unit%%.*}"
  28. unit_name="$(basename ${unit})"
  29. if [ -f ${unit}.service ]; then
  30. echo "Installing override for ${unit}.service..."
  31. cp ${override_dir}/${unit_name}.service /etc/systemd/system/
  32. retval=0
  33. fi
  34. if [ -f ${unit}.socket -a -f ${override_dir}/${unit}.socket ]; then
  35. echo "Installing override for ${unit}.socket..."
  36. cp ${override_dir}/${unit_name}.socket /etc/systemd/system/
  37. retval=0
  38. fi
  39. if [ -f ${unit}.path -a -f ${override_dir}/${unit}.path ]; then
  40. echo "Installing override for ${unit}.path..."
  41. cp ${override_dir}/${unit_name}.path /etc/systemd/system/
  42. retval=0
  43. fi
  44. done
  45. return ${retval}
  46. }
  47. reenableNetworkManager() {
  48. # Disable original service to enable overriden one
  49. echo "Disabling original service to enable overriden one..."
  50. disableSystemdUnits ModemManager.service
  51. disableSystemdUnits NetworkManager.service
  52. # Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)
  53. echo "Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)"
  54. systemctl mask dbus-org.freedesktop.NetworkManager.service 2> /dev/null || echo "Could not disable D-BUS activation of NetworkManager"
  55. echo "Re-enabling original service to enable overriden one..."
  56. enableSystemdUnits ModemManager.service
  57. enableSystemdUnits NetworkManager.service
  58. # Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811
  59. echo "Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811"
  60. enableSystemdUnits NetworkManager-dispatcher.service
  61. }
  62. remove_ShowIn() {
  63. if [ -e "${1}" ]; then
  64. sed -i '/^\(Not\|Only\)ShowIn/d' "${1}"
  65. fi
  66. }
  67. showIn() {
  68. desktop_entry="${1}"
  69. shown_in="${2}"
  70. message="${shown_in:-"Shown in All;"}"
  71. desktop_entry_qubes="${XDG_CONFIG_QUBES}/autostart/${desktop_entry##*/}"
  72. # Make sure Qubes autostart directory exists
  73. mkdir -p "${XDG_CONFIG_QUBES}/autostart"
  74. # Desktop entry exists, so move to Qubes directory and modify it
  75. if [ -e "${desktop_entry}" ]; then
  76. echo "Desktop Entry Modification - ${message} ${desktop_entry##*/}..."
  77. cp -pf "${desktop_entry}" "${desktop_entry_qubes}"
  78. remove_ShowIn "${desktop_entry_qubes}"
  79. sed -i '/^X-GNOME-Autostart-enabled.*[fF0]/d' "${desktop_entry_qubes}"
  80. # Will only be '' if shown in all
  81. if [ ! "${shown_in}x" == "x" ]; then
  82. echo "${shown_in}" >> "${desktop_entry_qubes}" || true
  83. fi
  84. # Desktop entry must have been removed, so also remove from Qubes directory
  85. else
  86. echo "Desktop Entry Modification - Remove: ${desktop_entry##*/}..."
  87. rm -f "${desktop_entry_qubes}"
  88. fi
  89. }
  90. setArrayAsGlobal() {
  91. local array="$1"
  92. local export_as="$2"
  93. local code=$(declare -p "$array")
  94. local replaced="${code/$array/$export_as}"
  95. eval ${replaced/declare -/declare -g}
  96. }
  97. systemdInfo() {
  98. unit=${1}
  99. return_global_var=${2}
  100. declare -A INFO=()
  101. while read line; do
  102. INFO[${line%%=*}]="${line##*=}"
  103. done < <(systemctl show ${unit} 2> /dev/null)
  104. setArrayAsGlobal INFO $return_global_var
  105. return ${#INFO[@]}
  106. }
  107. displayFailedStatus() {
  108. action=${1}
  109. unit=${2}
  110. # Only display if there are results. In chroot environmnet there will be
  111. # no results to 'systemctl show' command
  112. systemdInfo ${unit} info || {
  113. echo
  114. echo "==================================================="
  115. echo "FAILED: systemd ${action} ${unit}"
  116. echo "==================================================="
  117. echo " LoadState = ${info[LoadState]}"
  118. echo " LoadError = ${info[LoadError]}"
  119. echo " ActiveState = ${info[ActiveState]}"
  120. echo " SubState = ${info[SubState]}"
  121. echo "UnitFileState = ${info[UnitFileState]}"
  122. echo
  123. }
  124. }
  125. # Disable systemd units
  126. disableSystemdUnits() {
  127. for unit in $*; do
  128. systemctl is-enabled ${unit} > /dev/null 2>&1 && {
  129. echo "Disabling ${unit}..."
  130. systemctl is-active ${unit} > /dev/null 2>&1 && {
  131. systemctl stop ${unit} > /dev/null 2>&1 || displayFailedStatus stop ${unit}
  132. }
  133. if [ -f /lib/systemd/system/${unit} ]; then
  134. if fgrep -q '[Install]' /lib/systemd/system/${unit}; then
  135. systemctl disable ${unit} > /dev/null 2>&1 || displayFailedStatus disable ${unit}
  136. else
  137. echo "Masking service: ${unit}"
  138. systemctl mask ${unit}
  139. fi
  140. else
  141. systemctl disable ${unit} > /dev/null 2>&1 || displayFailedStatus disable ${unit}
  142. fi
  143. } || {
  144. echo "It appears ${unit} is already disabled!"
  145. #displayFailedStatus is-disabled ${unit}
  146. }
  147. done
  148. }
  149. # Enable systemd units
  150. enableSystemdUnits() {
  151. for unit in $*; do
  152. systemctl is-enabled ${unit} > /dev/null 2>&1 && {
  153. echo "It appears ${unit} is already enabled!"
  154. #displayFailedStatus is-enabled ${unit}
  155. } || {
  156. echo "Enabling: ${unit}..."
  157. systemctl enable ${unit} > /dev/null 2>&1 && {
  158. systemctl start ${unit} > /dev/null 2>&1 || displayFailedStatus start ${unit}
  159. } || {
  160. echo "Could not enable: ${unit}"
  161. displayFailedStatus enable ${unit}
  162. }
  163. }
  164. done
  165. }
  166. # Manually trigger all triggers to automaticatly configure
  167. triggerTriggers() {
  168. path="$(readlink -m ${0})"
  169. triggers="${path/postinst/triggers}"
  170. awk '{sub(/[ \t]*#.*/,"")} NF' ${triggers} | while read line
  171. do
  172. /bin/bash -c "${0} triggered ${line##* }" || true
  173. done
  174. }
  175. case "${1}" in
  176. configure)
  177. # disable some Upstart services
  178. for init in plymouth-shutdown \
  179. prefdm \
  180. splash-manager \
  181. start-ttys \
  182. tty ; do
  183. dpkg-divert --divert /etc/init/${init}.conf.qubes-disabled --package qubes-core-agent --rename --add /etc/init/${init}.conf
  184. done
  185. # Create NetworkManager configuration if we do not have it
  186. if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
  187. echo '[main]' > /etc/NetworkManager/NetworkManager.conf
  188. echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
  189. echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
  190. fi
  191. # Remove old firmware updates link
  192. if [ -L /lib/firmware/updates ]; then
  193. rm -f /lib/firmware/updates
  194. fi
  195. #if ! grep -q '/etc/yum\.conf\.d/qubes-proxy\.conf' /etc/yum.conf; then
  196. # echo >> /etc/yum.conf
  197. # echo '# Yum does not support inclusion of config dir...' >> /etc/yum.conf
  198. # echo 'include=file:///etc/yum.conf.d/qubes-proxy.conf' >> /etc/yum.conf
  199. #fi
  200. # Revert 'Prevent unnecessary updates in VMs':
  201. #sed -i -e '/^exclude = kernel/d' /etc/yum.conf
  202. # ensure that hostname resolves to 127.0.1.1 resp. ::1 and that /etc/hosts is
  203. # in the form expected by qubes-sysinit.sh
  204. for ip in '127\.0\.1\.1' '::1'; do
  205. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  206. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  207. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
  208. else
  209. echo "${ip//\\/} `hostname`" >> /etc/hosts
  210. fi
  211. done
  212. # remove hostname from 127.0.0.1 line (in debian the hostname is by default
  213. # resolved to 127.0.1.1)
  214. sed -i "/^127\.0\.0\.1\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  215. chown user:user /home_volatile/user
  216. #if [ "${1}" != 1 ] ; then
  217. # # do the rest of %post thing only when updating for the first time...
  218. # exit 0
  219. #fi
  220. dpkg-divert --divert /etc/init/serial.conf.qubes-orig --package qubes-core-agent --rename --add /etc/init/serial.conf
  221. # XXX: TODO: Needs to be implemented still
  222. #rm -f /etc/mtab
  223. #echo "--> Removing HWADDR setting from /etc/sysconfig/network-scripts/ifcfg-eth0"
  224. #mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.orig
  225. #grep -v HWADDR /etc/sysconfig/network-scripts/ifcfg-eth0.orig > /etc/sysconfig/network-scripts/ifcfg-eth0
  226. # Enable Qubes systemd units
  227. enableSystemdUnits \
  228. qubes-sysinit.service \
  229. qubes-misc-post.service \
  230. qubes-netwatcher.service \
  231. qubes-network.service \
  232. qubes-firewall.service \
  233. qubes-updates-proxy.service \
  234. qubes-update-check.timer \
  235. qubes-qrexec-agent.service
  236. # Set default "runlevel"
  237. rm -f /etc/systemd/system/default.target
  238. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  239. # Copy ip(|6)tables into place if they do not already exist in filesystem.
  240. # This prevents conflict with iptables-service with fc21 and also put config
  241. # in proper place for debian
  242. mkdir -p '/etc/iptables'
  243. if [ ! -f '/etc/iptables/rules.v4' ]; then
  244. cp -p /usr/lib/qubes/init/iptables /etc/iptables/rules.v4
  245. fi
  246. if [ ! -f '/etc/iptables/rules.v6' ]; then
  247. cp -p /usr/lib/qubes/init/ip6tables /etc/iptables/rules.v6
  248. fi
  249. # Process all triggers which will set defaults to wanted values
  250. triggerTriggers
  251. disableSystemdUnits \
  252. alsa-store.service \
  253. alsa-restore.service \
  254. auditd.service \
  255. avahi.service \
  256. avahi-daemon.service \
  257. backuppc.service \
  258. cpuspeed.service \
  259. crond.service \
  260. fedora-autorelabel.service \
  261. fedora-autorelabel-mark.service \
  262. ipmi.service \
  263. hwclock-load.service \
  264. hwclock-save.service \
  265. mdmonitor.service \
  266. multipathd.service \
  267. openct.service \
  268. rpcbind.service \
  269. mcelog.service \
  270. fedora-storage-init.service \
  271. fedora-storage-init-late.service \
  272. plymouth-start.service \
  273. plymouth-read-write.service \
  274. plymouth-quit.service \
  275. plymouth-quit-wait.service \
  276. sshd.service \
  277. tcsd.service \
  278. sm-client.service \
  279. sendmail.service \
  280. mdmonitor-takeover.service \
  281. rngd smartd.service \
  282. upower.service \
  283. irqbalance.service \
  284. colord.service
  285. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  286. # Enable other systemd units
  287. enableSystemdUnits \
  288. rsyslog.service
  289. # XXX: TODO: Needs to be implemented still
  290. # These do not exist on debian; maybe a different package name
  291. # iptables.service \
  292. # ntpd.service \
  293. # ip6tables.service \
  294. ;;
  295. abort-upgrade|abort-remove|abort-deconfigure)
  296. exit 0
  297. ;;
  298. triggered)
  299. for trigger in ${2}; do
  300. case "${trigger}" in
  301. # Update Qubes App Menus
  302. /usr/share/applications)
  303. echo "Updating Qubes App Menus..."
  304. /usr/lib/qubes/qubes-trigger-sync-appmenus.sh || true
  305. ;;
  306. # Install overriden services only when original exists
  307. /lib/systemd/system/NetworkManager.service | \
  308. /lib/systemd/system/NetworkManager-wait-online.service | \
  309. /lib/systemd/system/ModemManager.service)
  310. UNITDIR=/lib/systemd/system
  311. OVERRIDEDIR=/usr/lib/qubes/init
  312. installOverridenServices "${OVERRIDEDIR}" "${trigger}"
  313. if [ $? -eq 0 ]; then
  314. reenableNetworkManager
  315. fi
  316. ;;
  317. # Enable cups only when it is real Systemd service
  318. /lib/systemd/system/cups.service)
  319. echo "Enabling cups"
  320. [ -e /lib/systemd/system/cups.service ] && enableSystemdUnits cups.service
  321. ;;
  322. # "Enable haveged service"
  323. /lib/systemd/system/haveged.service)
  324. echo "Enabling haveged service"
  325. enableSystemdUnits haveged.service
  326. ;;
  327. # Install overridden serial.conf init script
  328. /etc/init/serial.conf)
  329. echo "Installing over-ridden serial.conf init script..."
  330. if [ -e /etc/init/serial.conf ]; then
  331. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  332. fi
  333. ;;
  334. # Disable SELinux"
  335. /etc/selinux/config)
  336. echo "Disabling SELinux..."
  337. if [ -e /etc/selinux/config ]; then
  338. sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  339. mv /etc/selinux/config.processed /etc/selinux/config
  340. setenforce 0 2>/dev/null
  341. fi
  342. ;;
  343. # Desktop Entry Modification - Remove existing rules
  344. /etc/xdg/autostart/gpk-update-icon.desktop | \
  345. /etc/xdg/autostart/nm-applet.desktop | \
  346. /etc/xdg/autostart/abrt-applet.desktop | \
  347. /etc/xdg/autostart/notify-osd.desktop)
  348. showIn "${trigger}"
  349. ;;
  350. # Desktop Entry Modification - Not shown in Qubes
  351. /etc/xdg/autostart/pulseaudio.desktop | \
  352. /etc/xdg/autostart/deja-dup-monitor.desktop | \
  353. /etc/xdg/autostart/imsettings-start.desktop | \
  354. /etc/xdg/autostart/krb5-auth-dialog.desktop | \
  355. /etc/xdg/autostart/pulseaudio.desktop | \
  356. /etc/xdg/autostart/restorecond.desktop | \
  357. /etc/xdg/autostart/sealertauto.desktop | \
  358. /etc/xdg/autostart/gnome-power-manager.desktop | \
  359. /etc/xdg/autostart/gnome-sound-applet.desktop | \
  360. /etc/xdg/autostart/gnome-screensaver.desktop | \
  361. /etc/xdg/autostart/orca-autostart.desktop)
  362. showIn "${trigger}" 'NotShowIn=QUBES;'
  363. ;;
  364. # Desktop Entry Modification - Not shown in in DisposableVM
  365. /etc/xdg/autostart/gcm-apply.desktop)
  366. showIn "${trigger}" 'NotShowIn=DisposableVM;'
  367. ;;
  368. # Desktop Entry Modification - Only shown in AppVM
  369. /etc/xdg/autostart/gnome-keyring-gpg.desktop | \
  370. /etc/xdg/autostart/gnome-keyring-pkcs11.desktop | \
  371. /etc/xdg/autostart/gnome-keyring-secrets.desktop | \
  372. /etc/xdg/autostart/gnome-keyring-ssh.desktop | \
  373. /etc/xdg/autostart/gnome-settings-daemon.desktop | \
  374. /etc/xdg/autostart/user-dirs-update-gtk.desktop | \
  375. /etc/xdg/autostart/gsettings-data-convert.desktop)
  376. showIn "${trigger}" 'OnlyShowIn=GNOME;AppVM;'
  377. ;;
  378. # Desktop Entry Modification - Only shown in Gnome & UpdateableVM
  379. /etc/xdg/autostart/gpk-update-icon.desktop)
  380. showIn "${trigger}" 'OnlyShowIn=GNOME;UpdateableVM;'
  381. ;;
  382. # Desktop Entry Modification - Only shown in Gnome & Qubes
  383. /etc/xdg/autostart/nm-applet.desktop)
  384. showIn "${trigger}" 'OnlyShowIn=GNOME;QUBES;'
  385. ;;
  386. *)
  387. echo "postinst called with unknown trigger \`${2}'" >&2
  388. exit 1
  389. ;;
  390. esac
  391. done
  392. exit 0
  393. ;;
  394. *)
  395. echo "postinst called with unknown argument \`${1}'" >&2
  396. exit 1
  397. ;;
  398. esac
  399. # dh_installdeb will replace this with shell code automatically
  400. # generated by other debhelper scripts.
  401. #DEBHELPER#
  402. exit 0
  403. # vim: set ts=4 sw=4 sts=4 et :