PKGBUILD.install 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. # Location of files which contains list of protected files
  70. mkdir -p /etc/qubes/protected-files.d
  71. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  72. # qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
  73. if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  74. if ! grep -q localhost /etc/hosts; then
  75. cat <<EOF > /etc/hosts
  76. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
  77. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  78. EOF
  79. fi
  80. fi
  81. # ensure that hostname resolves to 127.0.0.1 resp. ::1 and that /etc/hosts is
  82. # in the form expected by qubes-sysinit.sh
  83. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  84. for ip in '127\.0\.0\.1' '::1'; do
  85. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  86. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  87. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
  88. else
  89. echo "${ip} `hostname`" >> /etc/hosts
  90. fi
  91. done
  92. fi
  93. # Make sure there is a default locale set so gnome-terminal will start
  94. if [ ! -e /etc/locale.conf ] || ! grep -q LANG /etc/locale.conf; then
  95. touch /etc/locale.conf
  96. echo "LANG=en_US.UTF-8" >> /etc/locale.conf
  97. fi
  98. # ... and make sure it is really generated
  99. current_locale=`grep LANG /etc/locale.conf|cut -f 2 -d =`
  100. if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
  101. base=`echo "$current_locale" | cut -f 1 -d .`
  102. charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
  103. [ -n "$charmap" ] && charmap="-f $charmap"
  104. localedef -i $base $charmap $current_locale
  105. fi
  106. }
  107. configure_systemd() {
  108. PRESET_FAILED=0
  109. if [ $1 -eq 1 ]; then
  110. systemctl --no-reload preset-all > /dev/null 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
  111. else
  112. services="qubes-dvm qubes-misc-post qubes-firewall qubes-mount-dirs"
  113. services="$services qubes-netwatcher qubes-network qubes-sysinit"
  114. services="$services qubes-iptables qubes-updates-proxy qubes-qrexec-agent"
  115. services="$services qubes-random-seed"
  116. for srv in $services; do
  117. systemctl --no-reload preset $srv.service
  118. done
  119. systemctl --no-reload preset qubes-update-check.timer
  120. # Upgrade path - now qubes-iptables is used instead
  121. systemctl --no-reload preset iptables.service
  122. systemctl --no-reload preset ip6tables.service
  123. fi
  124. # Set default "runlevel"
  125. rm -f /etc/systemd/system/default.target
  126. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  127. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
  128. case "$action" in
  129. (disable)
  130. if [ -f /lib/systemd/system/$unit_name ]; then
  131. if ! fgrep -q '[Install]' /lib/systemd/system/$unit_name; then
  132. # forcibly disable
  133. ln -sf /dev/null /etc/systemd/system/$unit_name
  134. fi
  135. fi
  136. ;;
  137. *)
  138. # preset-all is not available in fc20; so preset each unit file listed in 75-qubes-vm.preset
  139. if [ $1 -eq 1 -a "${PRESET_FAILED}" -eq 1 ]; then
  140. systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
  141. fi
  142. ;;
  143. esac
  144. done
  145. systemctl daemon-reload
  146. }
  147. update_finalize() {
  148. # Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
  149. if [ -z "`cat /etc/pam.d/su | grep system-login`" ] ; then
  150. echo "Fixing pam.d"
  151. sed '/auth\t\trequired\tpam_unix.so/aauth\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  152. sed '/account\t\trequired\tpam_unix.so/aaccount\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  153. sed '/session\t\trequired\tpam_unix.so/asession\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  154. cp /etc/pam.d/su /etc/pam.d/su-l
  155. fi
  156. # Archlinux specific: ensure tty1 is enabled
  157. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  158. systemctl enable getty\@tty1.service
  159. systemctl daemon-reload
  160. }
  161. ## arg 1: the new package version
  162. post_install() {
  163. update_qubesconfig
  164. # do the rest of %post thing only when updating for the first time...
  165. if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  166. cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  167. fi
  168. # Remove most of the udev scripts to speed up the VM boot time
  169. # Just leave the xen* scripts, that are needed if this VM was
  170. # ever used as a net backend (e.g. as a VPN domain in the future)
  171. #echo "--> Removing unnecessary udev scripts..."
  172. mkdir -p /var/lib/qubes/removed-udev-scripts
  173. for f in /etc/udev/rules.d/*
  174. do
  175. if [ $(basename $f) == "xen-backend.rules" ] ; then
  176. continue
  177. fi
  178. if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
  179. continue
  180. fi
  181. if echo $f | grep -q qubes; then
  182. continue
  183. fi
  184. mv $f /var/lib/qubes/removed-udev-scripts/
  185. done
  186. mkdir -p /rw
  187. configure_notification-daemon
  188. configure_selinux
  189. configure_systemd 0
  190. update_finalize
  191. glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  192. }
  193. ## arg 1: the new package version
  194. ## arg 2: the old package version
  195. post_upgrade() {
  196. update_qubesconfig
  197. configure_notification-daemon
  198. configure_selinux
  199. configure_systemd 1
  200. update_finalize
  201. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  202. }
  203. ######################
  204. ## Remove functions ##
  205. ######################
  206. ## arg 1: the old package version
  207. pre_remove() {
  208. # no more packages left
  209. if [ -e /var/lib/qubes/fstab.orig ] ; then
  210. mv /var/lib/qubes/fstab.orig /etc/fstab
  211. fi
  212. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  213. if [ -e /var/lib/qubes/serial.orig ] ; then
  214. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  215. fi
  216. }
  217. ## arg 1: the old package version
  218. post_remove() {
  219. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  220. if [ -L /lib/firmware/updates ] ; then
  221. rm /lib/firmware/updates
  222. fi
  223. rm -rf /var/lib/qubes/xdg
  224. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-dirs qubes-netwatcher qubes-network qubes-qrexec-agent; do
  225. systemctl disable $srv.service
  226. done
  227. }