PKGBUILD.install 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. ###################
  2. ## Install Hooks ##
  3. ###################
  4. installOverridenServices() {
  5. UNITDIR=/lib/systemd/system
  6. OVERRIDEDIR=/usr/lib/qubes/init
  7. # Install overriden services only when original exists
  8. for srv in %*; do
  9. if [ -f $UNITDIR/$srv.service ]; then
  10. cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
  11. systemctl is-enabled $srv.service >/dev/null && systemctl --no-reload reenable $srv.service 2>/dev/null
  12. fi
  13. if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then
  14. cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/
  15. systemctl is-enabled $srv.socket >/dev/null && systemctl --no-reload reenable $srv.socket 2>/dev/null
  16. fi
  17. if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then
  18. cp $OVERRIDEDIR/$srv.path /etc/systemd/system/
  19. systemctl is-enabled $srv.path >/dev/null && systemctl --no-reload reenable $srv.path 2>/dev/null
  20. fi
  21. done
  22. systemctl daemon-reload
  23. }
  24. configure_initscripts() {
  25. if [ -e /etc/init/serial.conf ]; then
  26. cp /usr/share/qubes/serial.conf /etc/init/serial.conf
  27. fi
  28. }
  29. configure_iptables() {
  30. if ! grep -q IPTABLES_DATA /etc/sysconfig/iptables-config; then
  31. cat <<EOF >>/etc/sysconfig/iptables-config
  32. ### Automatically added by Qubes:
  33. # Override default rules location on Qubes
  34. IPTABLES_DATA=/etc/sysconfig/iptables.qubes
  35. EOF
  36. fi
  37. if ! grep -q IP6TABLES_DATA /etc/sysconfig/ip6tables-config; then
  38. cat <<EOF >>/etc/sysconfig/ip6tables-config
  39. ### Automatically added by Qubes:
  40. # Override default rules location on Qubes
  41. IP6TABLES_DATA=/etc/sysconfig/ip6tables.qubes
  42. EOF
  43. fi
  44. }
  45. configure_notification-daemon() {
  46. # Enable autostart of notification-daemon when installed
  47. ln -s /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/
  48. }
  49. configure_selinux() {
  50. # SELinux is not enabled on archlinux
  51. #echo "--> Disabling SELinux..."
  52. sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  53. mv /etc/selinux/config.processed /etc/selinux/config
  54. setenforce 0 2>/dev/null
  55. }
  56. configure_networkmanager() {
  57. installOverridenServices ModemManager NetworkManager NetworkManager-wait-online
  58. # Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)
  59. systemctl mask dbus-org.freedesktop.NetworkManager.service 2> /dev/null
  60. # Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811
  61. systemctl enable NetworkManager-dispatcher.service 2> /dev/null
  62. }
  63. configure_cups() {
  64. installOverridenServices cups
  65. }
  66. configure_cronie() {
  67. installOverridenServices crond
  68. }
  69. configure_crony() {
  70. installOverridenServices chronyd
  71. }
  72. ###########################
  73. ## Pre-Install functions ##
  74. ###########################
  75. update_default_user() {
  76. # Make sure there is a qubes group
  77. groupadd --force --system --gid 98 qubes
  78. # Archlinux bash version has a 'bug' when running su -c, /etc/profile is not loaded because bash consider there is no interactive pty when running 'su - user -c' or something like this.
  79. # See https://bugs.archlinux.org/task/31831
  80. id -u 'user' >/dev/null 2>&1 || {
  81. useradd --user-group --create-home --shell /bin/zsh user
  82. }
  83. usermod -a --groups qubes user
  84. }
  85. ## arg 1: the new package version
  86. pre_install() {
  87. echo "Pre install..."
  88. update_default_user
  89. # do this whole %pre thing only when updating for the first time...
  90. mkdir -p /var/lib/qubes
  91. # Backup fstab / But use archlinux defaults (cp instead of mv)
  92. if [ -e /etc/fstab ] ; then
  93. cp /etc/fstab /var/lib/qubes/fstab.orig
  94. fi
  95. # Add qubes core related fstab entries
  96. echo "xen /proc/xen xenfs defaults 0 0" >> /etc/fstab
  97. usermod -p '' root
  98. usermod -L user
  99. }
  100. ## arg 1: the new package version
  101. ## arg 2: the old package version
  102. pre_upgrade() {
  103. # do something here
  104. echo "Pre upgrade..."
  105. update_default_user
  106. }
  107. ############################
  108. ## Post-Install functions ##
  109. ############################
  110. remove_ShowIn () {
  111. if [ -e /etc/xdg/autostart/$1.desktop ]; then
  112. sed -i '/^\(Not\|Only\)ShowIn/d' /etc/xdg/autostart/$1.desktop
  113. fi
  114. }
  115. update_xdgstart () {
  116. # reenable if disabled by some earlier version of package
  117. remove_ShowIn abrt-applet.desktop imsettings-start.desktop
  118. # don't want it at all
  119. for F in deja-dup-monitor krb5-auth-dialog pulseaudio restorecond sealertauto gnome-power-manager gnome-sound-applet gnome-screensaver orca-autostart; do
  120. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  121. remove_ShowIn $F
  122. echo 'NotShowIn=QUBES;' >> /etc/xdg/autostart/$F.desktop
  123. fi
  124. done
  125. # don't want it in DisposableVM
  126. for F in gcm-apply ; do
  127. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  128. remove_ShowIn $F
  129. echo 'NotShowIn=DisposableVM;' >> /etc/xdg/autostart/$F.desktop
  130. fi
  131. done
  132. # want it in AppVM only
  133. for F in gnome-keyring-gpg gnome-keyring-pkcs11 gnome-keyring-secrets gnome-keyring-ssh gnome-settings-daemon user-dirs-update-gtk gsettings-data-convert ; do
  134. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  135. remove_ShowIn $F
  136. echo 'OnlyShowIn=GNOME;AppVM;' >> /etc/xdg/autostart/$F.desktop
  137. fi
  138. done
  139. # remove existing rule to add own later
  140. for F in gpk-update-icon nm-applet ; do
  141. remove_ShowIn $F
  142. done
  143. echo 'OnlyShowIn=GNOME;UpdateableVM;' >> /etc/xdg/autostart/gpk-update-icon.desktop || :
  144. echo 'OnlyShowIn=GNOME;QUBES;' >> /etc/xdg/autostart/nm-applet.desktop || :
  145. }
  146. update_qubesconfig() {
  147. # Create NetworkManager configuration if we do not have it
  148. if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
  149. echo '[main]' > /etc/NetworkManager/NetworkManager.conf
  150. echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
  151. echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
  152. fi
  153. /usr/lib/qubes/qubes-fix-nm-conf.sh
  154. # Remove ip_forward setting from sysctl, so NM will not reset it
  155. # Archlinux now use sysctl.d/ instead of sysctl.conf
  156. #sed 's/^net.ipv4.ip_forward.*/#\0/' -i /etc/sysctl.conf
  157. # Remove old firmware updates link
  158. if [ -L /lib/firmware/updates ]; then
  159. rm -f /lib/firmware/updates
  160. fi
  161. # Yum proxy configuration is fedora specific
  162. #if ! grep -q '/etc/yum\.conf\.d/qubes-proxy\.conf' /etc/yum.conf; then
  163. # echo >> /etc/yum.conf
  164. # echo '# Yum does not support inclusion of config dir...' >> /etc/yum.conf
  165. # echo 'include=file:///etc/yum.conf.d/qubes-proxy.conf' >> /etc/yum.conf
  166. #fi
  167. # Revert 'Prevent unnecessary updates in VMs':
  168. #sed -i -e '/^exclude = kernel/d' /etc/yum.conf
  169. # Location of files which contains list of protected files
  170. mkdir -p /etc/qubes/protected-files.d
  171. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  172. # qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
  173. if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  174. if ! grep -q localhost /etc/hosts; then
  175. cat <<EOF > /etc/hosts
  176. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
  177. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  178. EOF
  179. fi
  180. fi
  181. # Make sure that /etc/sysconfig/ip(|6)tables exists. Otherwise iptales.service
  182. # would not start (even when configured to use another configuration file.
  183. if [ ! -e '/etc/sysconfig/iptables' ]; then
  184. ln -s iptables.qubes /etc/sysconfig/iptables
  185. fi
  186. if [ ! -e '/etc/sysconfig/ip6tables' ]; then
  187. ln -s ip6tables.qubes /etc/sysconfig/ip6tables
  188. fi
  189. # ensure that hostname resolves to 127.0.0.1 resp. ::1 and that /etc/hosts is
  190. # in the form expected by qubes-sysinit.sh
  191. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  192. for ip in '127\.0\.0\.1' '::1'; do
  193. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  194. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  195. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
  196. else
  197. echo "${ip} `hostname`" >> /etc/hosts
  198. fi
  199. done
  200. fi
  201. # Make sure there is a default locale set so gnome-terminal will start
  202. if [ ! -e /etc/locale.conf ] || ! grep -q LANG /etc/locale.conf; then
  203. touch /etc/locale.conf
  204. echo "LANG=en_US.UTF-8" >> /etc/locale.conf
  205. fi
  206. # ... and make sure it is really generated
  207. current_locale=`grep LANG /etc/locale.conf|cut -f 2 -d =`
  208. if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
  209. base=`echo "$current_locale" | cut -f 1 -d .`
  210. charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
  211. [ -n "$charmap" ] && charmap="-f $charmap"
  212. localedef -i $base $charmap $current_locale
  213. fi
  214. }
  215. update_systemd_finalize() {
  216. # Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
  217. if [ -z "`cat /etc/pam.d/su | grep system-login`" ] ; then
  218. echo "Fixing pam.d"
  219. sed '/auth\t\trequired\tpam_unix.so/aauth\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  220. sed '/account\t\trequired\tpam_unix.so/aaccount\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  221. sed '/session\t\trequired\tpam_unix.so/asession\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  222. cp /etc/pam.d/su /etc/pam.d/su-l
  223. fi
  224. # Set default "runlevel"
  225. rm -f /etc/systemd/system/default.target
  226. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  227. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
  228. case "$action" in
  229. (disable)
  230. if [ -f /lib/systemd/system/$unit_name.service ]; then
  231. if ! fgrep -q '[Install]' /lib/systemd/system/$unit_name; then
  232. # forcibly disable
  233. ln -sf /dev/null /etc/systemd/system/$unit_name
  234. fi
  235. fi
  236. ;;
  237. esac
  238. done
  239. # Archlinux specific: ensure tty1 is enabled
  240. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  241. systemctl enable getty\@tty1.service
  242. systemctl daemon-reload
  243. }
  244. ## arg 1: the new package version
  245. post_install() {
  246. update_xdgstart
  247. update_qubesconfig
  248. # do the rest of %post thing only when updating for the first time...
  249. if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  250. cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  251. fi
  252. # Remove most of the udev scripts to speed up the VM boot time
  253. # Just leave the xen* scripts, that are needed if this VM was
  254. # ever used as a net backend (e.g. as a VPN domain in the future)
  255. #echo "--> Removing unnecessary udev scripts..."
  256. mkdir -p /var/lib/qubes/removed-udev-scripts
  257. for f in /etc/udev/rules.d/*
  258. do
  259. if [ $(basename $f) == "xen-backend.rules" ] ; then
  260. continue
  261. fi
  262. if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
  263. continue
  264. fi
  265. if echo $f | grep -q qubes; then
  266. continue
  267. fi
  268. mv $f /var/lib/qubes/removed-udev-scripts/
  269. done
  270. mkdir -p /rw
  271. configure_iptables
  272. configure_notification-daemon
  273. configure_selinux
  274. configure_networkmanager
  275. configure_cups
  276. configure_cronie
  277. configure_crony
  278. systemctl --no-reload preset-all
  279. update_systemd_finalize
  280. glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  281. }
  282. ## arg 1: the new package version
  283. ## arg 2: the old package version
  284. post_upgrade() {
  285. update_xdgstart
  286. update_qubesconfig
  287. configure_iptables
  288. configure_notification-daemon
  289. configure_selinux
  290. configure_networkmanager
  291. configure_cups
  292. configure_cronie
  293. configure_crony
  294. services="qubes-dvm qubes-misc-post qubes-firewall qubes-mount-home"
  295. services="$services qubes-netwatcher qubes-network qubes-sysinit"
  296. services="$services qubes-updates-proxy qubes-qrexec-agent"
  297. for srv in $services; do
  298. systemctl --no-reload preset $srv.service
  299. done
  300. systemctl --no-reload preset qubes-update-check.timer
  301. update_systemd_finalize
  302. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  303. }
  304. ######################
  305. ## Remove functions ##
  306. ######################
  307. ## arg 1: the old package version
  308. pre_remove() {
  309. # no more packages left
  310. if [ -e /var/lib/qubes/fstab.orig ] ; then
  311. mv /var/lib/qubes/fstab.orig /etc/fstab
  312. fi
  313. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  314. if [ -e /var/lib/qubes/serial.orig ] ; then
  315. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  316. fi
  317. }
  318. ## arg 1: the old package version
  319. post_remove() {
  320. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  321. if [ -L /lib/firmware/updates ] ; then
  322. rm /lib/firmware/updates
  323. fi
  324. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-home qubes-netwatcher qubes-network qubes-qrexec-agent; do
  325. systemctl disable $srv.service
  326. done
  327. }