PKGBUILD.install 11 KB

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