PKGBUILD.install 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. remove_ShowIn () {
  2. if [ -e /etc/xdg/autostart/$1.desktop ]; then
  3. sed -i '/^\(Not\|Only\)ShowIn/d' /etc/xdg/autostart/$1.desktop
  4. fi
  5. }
  6. update_xdgstart () {
  7. # reenable if disabled by some earlier version of package
  8. remove_ShowIn abrt-applet.desktop imsettings-start.desktop
  9. # don't want it at all
  10. for F in deja-dup-monitor krb5-auth-dialog pulseaudio restorecond sealertauto gnome-power-manager gnome-sound-applet gnome-screensaver orca-autostart; do
  11. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  12. remove_ShowIn $F
  13. echo 'NotShowIn=QUBES;' >> /etc/xdg/autostart/$F.desktop
  14. fi
  15. done
  16. # don't want it in DisposableVM
  17. for F in gcm-apply ; do
  18. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  19. remove_ShowIn $F
  20. echo 'NotShowIn=DisposableVM;' >> /etc/xdg/autostart/$F.desktop
  21. fi
  22. done
  23. # want it in AppVM only
  24. 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
  25. if [ -e /etc/xdg/autostart/$F.desktop ]; then
  26. remove_ShowIn $F
  27. echo 'OnlyShowIn=GNOME;AppVM;' >> /etc/xdg/autostart/$F.desktop
  28. fi
  29. done
  30. # remove existing rule to add own later
  31. for F in gpk-update-icon nm-applet ; do
  32. remove_ShowIn $F
  33. done
  34. echo 'OnlyShowIn=GNOME;UpdateableVM;' >> /etc/xdg/autostart/gpk-update-icon.desktop || :
  35. echo 'OnlyShowIn=GNOME;QUBES;' >> /etc/xdg/autostart/nm-applet.desktop || :
  36. # Enable autostart of notification-daemon when installed
  37. ln -s /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/
  38. }
  39. update_qubesconfig () {
  40. # Create NetworkManager configuration if we do not have it
  41. if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
  42. echo '[main]' > /etc/NetworkManager/NetworkManager.conf
  43. echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
  44. echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
  45. fi
  46. /usr/lib/qubes/qubes-fix-nm-conf.sh
  47. # Remove ip_forward setting from sysctl, so NM will not reset it
  48. # Archlinux now use sysctl.d/ instead of sysctl.conf
  49. # sed 's/^net.ipv4.ip_forward.*/#\0/' -i /etc/sysctl.conf
  50. # Remove old firmware updates link
  51. if [ -L /lib/firmware/updates ]; then
  52. rm -f /lib/firmware/updates
  53. fi
  54. # qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
  55. if ! grep -q localhost /etc/hosts; then
  56. cat <<EOF > /etc/hosts
  57. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
  58. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  59. EOF
  60. fi
  61. # Remove most of the udev scripts to speed up the VM boot time
  62. # Just leave the xen* scripts, that are needed if this VM was
  63. # ever used as a net backend (e.g. as a VPN domain in the future)
  64. #echo "--> Removing unnecessary udev scripts..."
  65. mkdir -p /var/lib/qubes/removed-udev-scripts
  66. for f in /etc/udev/rules.d/*
  67. do
  68. if [ $(basename $f) == "xen-backend.rules" ] ; then
  69. continue
  70. fi
  71. if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
  72. continue
  73. fi
  74. if echo $f | grep -q qubes; then
  75. continue
  76. fi
  77. mv $f /var/lib/qubes/removed-udev-scripts/
  78. done
  79. }
  80. update_systemd() {
  81. echo "Updating systemd configuration for Qubes..."
  82. echo "Enabling tty1"
  83. # Archlinux specific: ensure tty1 is enabled
  84. rm -f /etc/systemd/system/getty.target.wants/getty\@tty*.service
  85. systemctl enable getty\@tty1.service
  86. # Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
  87. if [ -z "`cat /etc/pam.d/su | grep system-login`" ] ; then
  88. echo "Fixing pam.d"
  89. sed '/auth\t\trequired\tpam_unix.so/aauth\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  90. sed '/account\t\trequired\tpam_unix.so/aaccount\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  91. sed '/session\t\trequired\tpam_unix.so/asession\t\tinclude\t\tsystem-login' -i /etc/pam.d/su
  92. cp /etc/pam.d/su /etc/pam.d/su-l
  93. fi
  94. echo "Enabling qubes specific services"
  95. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-netwatcher qubes-network qubes-firewall qubes-yum-proxy qubes-qrexec-agent qubes-ensure-lib-modules; do
  96. if [ -f /lib/systemd/system/$srv.service ]; then
  97. if fgrep -q '[Install]' /lib/systemd/system/$srv.service; then
  98. systemctl enable "$srv"
  99. # 2> /dev/null
  100. else
  101. echo "WARNING: Cannot enable qubes service $srv: unit cannot be installed"
  102. fi
  103. else
  104. echo "WARNING: Cannot enable qubes service $srv: unit does not exists"
  105. fi
  106. done
  107. systemctl enable qubes-update-check.timer 2> /dev/null
  108. UNITDIR=/lib/systemd/system
  109. OVERRIDEDIR=/usr/lib/qubes/init
  110. # Install overriden services only when original exists
  111. for srv in cups NetworkManager NetworkManager-wait-online ntpd chronyd; do
  112. if [ -f $UNITDIR/$srv.service ]; then
  113. cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
  114. fi
  115. if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then
  116. cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/
  117. fi
  118. if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then
  119. cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
  120. fi
  121. done
  122. # Set default "runlevel"
  123. rm -f /etc/systemd/system/default.target
  124. ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
  125. DISABLE_SERVICES="alsa-store alsa-restore auditd avahi avahi-daemon backuppc cpuspeed crond"
  126. DISABLE_SERVICES="$DISABLE_SERVICES fedora-autorelabel fedora-autorelabel-mark ipmi hwclock-load hwclock-save"
  127. DISABLE_SERVICES="$DISABLE_SERVICES mdmonitor multipathd openct rpcbind mcelog fedora-storage-init fedora-storage-init-late"
  128. DISABLE_SERVICES="$DISABLE_SERVICES plymouth-start plymouth-read-write plymouth-quit plymouth-quit-wait"
  129. DISABLE_SERVICES="$DISABLE_SERVICES sshd tcsd sm-client sendmail mdmonitor-takeover"
  130. DISABLE_SERVICES="$DISABLE_SERVICES rngd smartd upower irqbalance colord"
  131. for srv in $DISABLE_SERVICES; do
  132. if [ -f /lib/systemd/system/$srv.service ]; then
  133. if fgrep -q '[Install]' /lib/systemd/system/$srv.service; then
  134. systemctl disable $srv.service 2> /dev/null
  135. else
  136. # forcibly disable
  137. ln -sf /dev/null /etc/systemd/system/$srv.service
  138. fi
  139. fi
  140. done
  141. # Disable original service to enable overriden one
  142. systemctl disable NetworkManager.service 2> /dev/null
  143. # Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)
  144. systemctl mask dbus-org.freedesktop.NetworkManager.service 2> /dev/null
  145. # Enable some services
  146. ENABLE_SERVICES="iptables ip6tables ip6tables rsyslog ntpd haveged"
  147. ENABLE_SERVICES="$ENABLE_SERVICES NetworkManager"
  148. # Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811
  149. ENABLE_SERVICES="$ENABLE_SERVICES NetworkManager-dispatcher"
  150. # Enable cups only when it is real SystemD service
  151. ENABLE_SERVICES="$ENABLE_SERVICES cups"
  152. for srv in $ENABLE_SERVICES; do
  153. if [ -f /lib/systemd/system/$srv.service ]; then
  154. if fgrep -q '[Install]' /lib/systemd/system/$srv.service; then
  155. echo "Enabling service $srv"
  156. systemctl enable "$srv"
  157. # 2> /dev/null
  158. fi
  159. fi
  160. done
  161. }
  162. ## arg 1: the new package version
  163. pre_install() {
  164. echo "Pre install..."
  165. # do this whole %pre thing only when updating for the first time...
  166. mkdir -p /var/lib/qubes
  167. # Backup fstab / But use archlinux defaults (cp instead of mv)
  168. if [ -e /etc/fstab ] ; then
  169. cp /etc/fstab /var/lib/qubes/fstab.orig
  170. fi
  171. # Add qubes core related fstab entries
  172. echo "xen /proc/xen xenfs defaults 0 0" >> /etc/fstab
  173. # Add a qubes group
  174. groupadd --force --system --gid 98 qubes
  175. # 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.
  176. # See https://bugs.archlinux.org/task/31831
  177. useradd --shell /bin/zsh --create-home user
  178. usermod -a --groups qubes user
  179. }
  180. ## arg 1: the new package version
  181. post_install() {
  182. update_xdgstart
  183. update_qubesconfig
  184. update_systemd
  185. # do the rest of %post thing only when updating for the first time...
  186. # Note: serial console wont work this way on archlinux. Maybe better using systemd ?
  187. #if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  188. # cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  189. #fi
  190. # SELinux is not enabled on archlinux
  191. # echo "--> Disabling SELinux..."
  192. # sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  193. # mv /etc/selinux/config.processed /etc/selinux/config
  194. # setenforce 0 2>/dev/null
  195. mkdir -p /rw
  196. }
  197. ## arg 1: the new package version
  198. ## arg 2: the old package version
  199. post_upgrade() {
  200. update_xdgstart
  201. update_systemd
  202. }
  203. ## arg 1: the new package version
  204. ## arg 2: the old package version
  205. pre_upgrade() {
  206. # do something here
  207. echo "Pre upgrade..."
  208. }
  209. ## arg 1: the old package version
  210. pre_remove() {
  211. # no more packages left
  212. if [ -e /var/lib/qubes/fstab.orig ] ; then
  213. mv /var/lib/qubes/fstab.orig /etc/fstab
  214. fi
  215. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  216. if [ -e /var/lib/qubes/serial.orig ] ; then
  217. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  218. fi
  219. }
  220. ## arg 1: the old package version
  221. post_remove() {
  222. /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
  223. if [ -L /lib/firmware/updates ] ; then
  224. rm /lib/firmware/updates
  225. fi
  226. for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-netwatcher qubes-network qubes-firewall qubes-qrexec-agent qubes-yum-proxy qubes-ensure-lib-modules; do
  227. systemctl disable $srv.service
  228. done
  229. systemctl disable qubes-update-check.timer
  230. }