PKGBUILD.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. # Remove ip_forward setting from sysctl, so NM will not reset it
  118. # Archlinux now use sysctl.d/ instead of sysctl.conf
  119. #sed 's/^net.ipv4.ip_forward.*/#\0/' -i /etc/sysctl.conf
  120. # Remove old firmware updates link
  121. if [ -L /lib/firmware/updates ]; then
  122. rm -f /lib/firmware/updates
  123. fi
  124. # Yum proxy configuration is fedora specific
  125. #if ! grep -q '/etc/yum\.conf\.d/qubes-proxy\.conf' /etc/yum.conf; then
  126. # echo >> /etc/yum.conf
  127. # echo '# Yum does not support inclusion of config dir...' >> /etc/yum.conf
  128. # echo 'include=file:///etc/yum.conf.d/qubes-proxy.conf' >> /etc/yum.conf
  129. #fi
  130. # Revert 'Prevent unnecessary updates in VMs':
  131. #sed -i -e '/^exclude = kernel/d' /etc/yum.conf
  132. # Location of files which contains list of protected files
  133. mkdir -p /etc/qubes/protected-files.d
  134. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  135. # qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
  136. if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  137. if ! grep -q localhost /etc/hosts; then
  138. cat <<EOF > /etc/hosts
  139. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
  140. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  141. EOF
  142. fi
  143. fi
  144. # Make sure that /etc/sysconfig/ip(|6)tables exists. Otherwise iptales.service
  145. # would not start (even when configured to use another configuration file.
  146. if [ ! -e '/etc/sysconfig/iptables' ]; then
  147. ln -s iptables.qubes /etc/sysconfig/iptables
  148. fi
  149. if [ ! -e '/etc/sysconfig/ip6tables' ]; then
  150. ln -s ip6tables.qubes /etc/sysconfig/ip6tables
  151. fi
  152. # ensure that hostname resolves to 127.0.0.1 resp. ::1 and that /etc/hosts is
  153. # in the form expected by qubes-sysinit.sh
  154. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  155. for ip in '127\.0\.0\.1' '::1'; do
  156. if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
  157. sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
  158. sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
  159. else
  160. echo "${ip} `hostname`" >> /etc/hosts
  161. fi
  162. done
  163. fi
  164. # Make sure there is a default locale set so gnome-terminal will start
  165. if [ ! -e /etc/locale.conf ] || ! grep -q LANG /etc/locale.conf; then
  166. touch /etc/locale.conf
  167. echo "LANG=en_US.UTF-8" >> /etc/locale.conf
  168. fi
  169. # ... and make sure it is really generated
  170. current_locale=`grep LANG /etc/locale.conf|cut -f 2 -d =`
  171. if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
  172. base=`echo "$current_locale" | cut -f 1 -d .`
  173. charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
  174. [ -n "$charmap" ] && charmap="-f $charmap"
  175. localedef -i $base $charmap $current_locale
  176. fi
  177. }
  178. update_systemd_finalize() {
  179. # Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
  180. if [ -z "`cat /etc/pam.d/su | grep system-login`" ] ; then
  181. echo "Fixing pam.d"
  182. sed '/auth\t\trequired\tpam_unix.so/aauth\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  183. sed '/account\t\trequired\tpam_unix.so/aaccount\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  184. sed '/session\t\trequired\tpam_unix.so/asession\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  185. cp /etc/pam.d/su /etc/pam.d/su-l
  186. fi
  187. # Set default "runlevel"
  188. rm -f /etc/systemd/system/default.target
  189. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  190. grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
  191. case "$action" in
  192. (disable)
  193. if [ -f /lib/systemd/system/$unit_name.service ]; then
  194. if ! fgrep -q '[Install]' /lib/systemd/system/$unit_name; then
  195. # forcibly disable
  196. ln -sf /dev/null /etc/systemd/system/$unit_name
  197. fi
  198. fi
  199. ;;
  200. esac
  201. done
  202. # Archlinux specific: ensure tty1 is enabled
  203. rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
  204. systemctl enable getty\@tty1.service
  205. systemctl daemon-reload
  206. }
  207. ## arg 1: the new package version
  208. post_install() {
  209. update_xdgstart
  210. update_qubesconfig
  211. # do the rest of %post thing only when updating for the first time...
  212. if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  213. cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  214. fi
  215. # Remove most of the udev scripts to speed up the VM boot time
  216. # Just leave the xen* scripts, that are needed if this VM was
  217. # ever used as a net backend (e.g. as a VPN domain in the future)
  218. #echo "--> Removing unnecessary udev scripts..."
  219. mkdir -p /var/lib/qubes/removed-udev-scripts
  220. for f in /etc/udev/rules.d/*
  221. do
  222. if [ $(basename $f) == "xen-backend.rules" ] ; then
  223. continue
  224. fi
  225. if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
  226. continue
  227. fi
  228. if echo $f | grep -q qubes; then
  229. continue
  230. fi
  231. mv $f /var/lib/qubes/removed-udev-scripts/
  232. done
  233. mkdir -p /rw
  234. configure_iptables
  235. configure_notification-daemon
  236. configure_selinux
  237. configure_networkmanager
  238. systemctl --no-reload preset-all
  239. update_systemd_finalize
  240. glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  241. }
  242. ## arg 1: the new package version
  243. ## arg 2: the old package version
  244. post_upgrade() {
  245. update_xdgstart
  246. update_qubesconfig
  247. configure_iptables
  248. configure_notification-daemon
  249. configure_selinux
  250. configure_networkmanager
  251. services="qubes-dvm qubes-misc-post qubes-firewall qubes-mount-dirs"
  252. services="$services qubes-netwatcher qubes-network qubes-sysinit"
  253. services="$services qubes-updates-proxy qubes-qrexec-agent"
  254. for srv in $services; do
  255. systemctl --no-reload preset $srv.service
  256. done
  257. systemctl --no-reload preset qubes-update-check.timer
  258. update_systemd_finalize
  259. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  260. }
  261. ######################
  262. ## Remove functions ##
  263. ######################
  264. ## arg 1: the old package version
  265. pre_remove() {
  266. # no more packages left
  267. if [ -e /var/lib/qubes/fstab.orig ] ; then
  268. mv /var/lib/qubes/fstab.orig /etc/fstab
  269. fi
  270. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  271. if [ -e /var/lib/qubes/serial.orig ] ; then
  272. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  273. fi
  274. }
  275. ## arg 1: the old package version
  276. post_remove() {
  277. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  278. if [ -L /lib/firmware/updates ] ; then
  279. rm /lib/firmware/updates
  280. fi
  281. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-dirs qubes-netwatcher qubes-network qubes-qrexec-agent; do
  282. systemctl disable $srv.service
  283. done
  284. }