PKGBUILD.install 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ###########################
  2. ## Pre-Install functions ##
  3. ###########################
  4. update_default_user() {
  5. # Make sure there is a qubes group
  6. groupadd --force --system --gid 98 qubes
  7. # 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.
  8. # See https://bugs.archlinux.org/task/31831
  9. id -u 'user' >/dev/null 2>&1 || {
  10. useradd --user-group --create-home --shell /bin/zsh user
  11. }
  12. usermod -a --groups qubes user
  13. }
  14. ## arg 1: the new package version
  15. pre_install() {
  16. echo "Pre install..."
  17. update_default_user
  18. # do this whole %pre thing only when updating for the first time...
  19. mkdir -p /var/lib/qubes
  20. # Backup fstab / But use archlinux defaults (cp instead of mv)
  21. if [ -e /etc/fstab ] ; then
  22. cp /etc/fstab /var/lib/qubes/fstab.orig
  23. fi
  24. # Add qubes core related fstab entries
  25. echo "xen /proc/xen xenfs defaults 0 0" >> /etc/fstab
  26. usermod -p '' root
  27. usermod -L user
  28. }
  29. ## arg 1: the new package version
  30. ## arg 2: the old package version
  31. pre_upgrade() {
  32. # do something here
  33. echo "Pre upgrade..."
  34. update_default_user
  35. }
  36. ###################
  37. ## Install Hooks ##
  38. ###################
  39. configure_notification-daemon() {
  40. # Enable autostart of notification-daemon when installed
  41. if [ ! -e /etc/xdg/autostart/notification-daemon.desktop ]; then
  42. ln -s /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/
  43. fi
  44. }
  45. configure_selinux() {
  46. # SELinux is not enabled on archlinux
  47. #echo "--> Disabling SELinux..."
  48. echo "SELINUX not enabled on archlinux. skipped."
  49. # sed -e s/^SELINUX=.*$/SELINUX=disabled/ -i /etc/selinux/config
  50. # setenforce 0 2>/dev/null
  51. }
  52. ############################
  53. ## Post-Install functions ##
  54. ############################
  55. update_qubesconfig() {
  56. # Remove ip_forward setting from sysctl, so NM will not reset it
  57. # Archlinux now use sysctl.d/ instead of sysctl.conf
  58. #sed 's/^net.ipv4.ip_forward.*/#\0/' -i /etc/sysctl.conf
  59. # Remove old firmware updates link
  60. if [ -L /lib/firmware/updates ]; then
  61. rm -f /lib/firmware/updates
  62. fi
  63. # Yum proxy configuration is fedora specific
  64. #if ! grep -q '/etc/yum\.conf\.d/qubes-proxy\.conf' /etc/yum.conf; then
  65. # echo >> /etc/yum.conf
  66. # echo '# Yum does not support inclusion of config dir...' >> /etc/yum.conf
  67. # echo 'include=file:///etc/yum.conf.d/qubes-proxy.conf' >> /etc/yum.conf
  68. #fi
  69. # Revert 'Prevent unnecessary updates in VMs':
  70. #sed -i -e '/^exclude = kernel/d' /etc/yum.conf
  71. # Location of files which contains list of protected files
  72. mkdir -p /etc/qubes/protected-files.d
  73. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  74. # qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
  75. if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  76. if ! grep -q localhost /etc/hosts; then
  77. cat <<EOF > /etc/hosts
  78. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
  79. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  80. EOF
  81. fi
  82. fi
  83. # ensure that hostname resolves to 127.0.0.1 resp. ::1 and that /etc/hosts is
  84. # in the form expected by qubes-sysinit.sh
  85. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  86. for ip in '127\.0\.0\.1' '::1'; do
  87. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  88. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  89. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
  90. else
  91. echo "${ip} `hostname`" >> /etc/hosts
  92. fi
  93. done
  94. fi
  95. # Make sure there is a default locale set so gnome-terminal will start
  96. if [ ! -e /etc/locale.conf ] || ! grep -q LANG /etc/locale.conf; then
  97. touch /etc/locale.conf
  98. echo "LANG=en_US.UTF-8" >> /etc/locale.conf
  99. fi
  100. # ... and make sure it is really generated
  101. current_locale=`grep LANG /etc/locale.conf|cut -f 2 -d =`
  102. if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
  103. base=`echo "$current_locale" | cut -f 1 -d .`
  104. charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
  105. [ -n "$charmap" ] && charmap="-f $charmap"
  106. localedef -i $base $charmap $current_locale
  107. fi
  108. }
  109. configure_systemd() {
  110. PRESET_FAILED=0
  111. if [ $1 -eq 1 ]; then
  112. systemctl --no-reload preset-all > /dev/null 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
  113. else
  114. services="qubes-dvm qubes-misc-post qubes-firewall qubes-mount-dirs"
  115. services="$services qubes-netwatcher qubes-network qubes-sysinit"
  116. services="$services qubes-iptables qubes-updates-proxy qubes-qrexec-agent"
  117. services="$services qubes-random-seed"
  118. for srv in $services; do
  119. systemctl --no-reload preset $srv.service
  120. done
  121. systemctl --no-reload preset qubes-update-check.timer
  122. # Upgrade path - now qubes-iptables is used instead
  123. systemctl --no-reload preset iptables.service
  124. systemctl --no-reload preset ip6tables.service
  125. fi
  126. # Set default "runlevel"
  127. rm -f /etc/systemd/system/default.target
  128. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  129. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
  130. case "$action" in
  131. (disable)
  132. if [ -f /lib/systemd/system/$unit_name ]; then
  133. if ! fgrep -q '[Install]' /lib/systemd/system/$unit_name; then
  134. # forcibly disable
  135. ln -sf /dev/null /etc/systemd/system/$unit_name
  136. fi
  137. fi
  138. ;;
  139. *)
  140. # preset-all is not available in fc20; so preset each unit file listed in 75-qubes-vm.preset
  141. if [ $1 -eq 1 -a "${PRESET_FAILED}" -eq 1 ]; then
  142. systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
  143. fi
  144. ;;
  145. esac
  146. done
  147. systemctl daemon-reload
  148. }
  149. update_finalize() {
  150. # Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
  151. if [ -z "`cat /etc/pam.d/su | grep system-login`" ] ; then
  152. echo "Fixing pam.d"
  153. sed '/auth\t\trequired\tpam_unix.so/aauth\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  154. sed '/account\t\trequired\tpam_unix.so/aaccount\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  155. sed '/session\t\trequired\tpam_unix.so/asession\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  156. cp /etc/pam.d/su /etc/pam.d/su-l
  157. fi
  158. # Archlinux specific: ensure tty1 is enabled
  159. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  160. systemctl enable getty\@tty1.service
  161. systemctl daemon-reload
  162. }
  163. ## arg 1: the new package version
  164. post_install() {
  165. update_qubesconfig
  166. # do the rest of %post thing only when updating for the first time...
  167. if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  168. cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  169. fi
  170. # Remove most of the udev scripts to speed up the VM boot time
  171. # Just leave the xen* scripts, that are needed if this VM was
  172. # ever used as a net backend (e.g. as a VPN domain in the future)
  173. #echo "--> Removing unnecessary udev scripts..."
  174. mkdir -p /var/lib/qubes/removed-udev-scripts
  175. for f in /etc/udev/rules.d/*
  176. do
  177. if [ $(basename $f) == "xen-backend.rules" ] ; then
  178. continue
  179. fi
  180. if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
  181. continue
  182. fi
  183. if echo $f | grep -q qubes; then
  184. continue
  185. fi
  186. mv $f /var/lib/qubes/removed-udev-scripts/
  187. done
  188. mkdir -p /rw
  189. configure_notification-daemon
  190. configure_selinux
  191. configure_systemd 0
  192. update_finalize
  193. glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  194. }
  195. ## arg 1: the new package version
  196. ## arg 2: the old package version
  197. post_upgrade() {
  198. update_qubesconfig
  199. configure_notification-daemon
  200. configure_selinux
  201. configure_systemd 1
  202. update_finalize
  203. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  204. }
  205. ######################
  206. ## Remove functions ##
  207. ######################
  208. ## arg 1: the old package version
  209. pre_remove() {
  210. # no more packages left
  211. if [ -e /var/lib/qubes/fstab.orig ] ; then
  212. mv /var/lib/qubes/fstab.orig /etc/fstab
  213. fi
  214. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  215. if [ -e /var/lib/qubes/serial.orig ] ; then
  216. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  217. fi
  218. }
  219. ## arg 1: the old package version
  220. post_remove() {
  221. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  222. if [ -L /lib/firmware/updates ] ; then
  223. rm /lib/firmware/updates
  224. fi
  225. rm -rf /var/lib/qubes/xdg
  226. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-dirs qubes-netwatcher qubes-network qubes-qrexec-agent; do
  227. systemctl disable $srv.service
  228. done
  229. }