PKGBUILD.install 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 abrt-aplet if disabled by some earlier version of package
  8. remove_ShowIn abrt-applet.desktop
  9. # don't want it at all
  10. for F in deja-dup-monitor imsettings-start 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. # 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.
  174. # See https://bugs.archlinux.org/task/31831
  175. useradd --shell /bin/zsh --create-home user
  176. }
  177. ## arg 1: the new package version
  178. post_install() {
  179. update_xdgstart
  180. update_qubesconfig
  181. update_systemd
  182. # do the rest of %post thing only when updating for the first time...
  183. # Note: serial console wont work this way on archlinux. Maybe better using systemd ?
  184. #if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
  185. # cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  186. #fi
  187. # SELinux is not enabled on archlinux
  188. # echo "--> Disabling SELinux..."
  189. # sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  190. # mv /etc/selinux/config.processed /etc/selinux/config
  191. # setenforce 0 2>/dev/null
  192. mkdir -p /rw
  193. }
  194. ## arg 1: the new package version
  195. ## arg 2: the old package version
  196. post_upgrade() {
  197. update_xdgstart
  198. update_systemd
  199. }
  200. ## arg 1: the new package version
  201. ## arg 2: the old package version
  202. pre_upgrade() {
  203. # do something here
  204. echo "Pre upgrade..."
  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. 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
  224. systemctl disable $srv.service
  225. done
  226. systemctl disable qubes-update-check.timer
  227. }