qubes-sysinit.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. # List of services enabled by default (in case of absence of xenstore entry)
  3. DEFAULT_ENABLED_NETVM="network-manager qubes-network qubes-update-check qubes-updates-proxy"
  4. DEFAULT_ENABLED_PROXYVM="meminfo-writer qubes-network qubes-firewall qubes-netwatcher qubes-update-check"
  5. DEFAULT_ENABLED_APPVM="meminfo-writer cups qubes-update-check"
  6. DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_APPVM updates-proxy-setup"
  7. DEFAULT_ENABLED="meminfo-writer"
  8. XS_READ=/usr/bin/xenstore-read
  9. [ -x /usr/sbin/xenstore-read ] && XS_READ=/usr/sbin/xenstore-read
  10. XS_LS=/usr/bin/xenstore-ls
  11. [ -x /usr/sbin/xenstore-read ] && XS_LS=/usr/sbin/xenstore-ls
  12. read_service() {
  13. $XS_READ qubes-service/$1 2> /dev/null
  14. }
  15. systemd_pkg_version=`systemctl --version|head -n 1`
  16. if ! dmesg | grep -q "$systemd_pkg_version running in system mode."; then
  17. # Ensure we're running right version of systemd (the one started by initrd may be different)
  18. systemctl daemon-reexec
  19. fi
  20. # Wait for evtchn initialization
  21. while [ ! -e /proc/xen/xenbus ]; do
  22. sleep 0.1
  23. done
  24. mkdir -p /var/run/qubes
  25. mkdir -p /var/run/qubes-service
  26. mkdir -p /var/run/xen-hotplug
  27. # Set permissions to /proc/xen/xenbus, so normal user can use xenstore-read
  28. chmod 666 /proc/xen/xenbus
  29. # Set permissions to files needed to listen at vchan
  30. chmod 666 /proc/u2mfn
  31. # Set default services depending on VM type
  32. TYPE=`$XS_READ qubes-vm-type 2> /dev/null`
  33. [ "$TYPE" = "AppVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_APPVM
  34. [ "$TYPE" = "NetVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_NETVM
  35. [ "$TYPE" = "ProxyVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_PROXYVM
  36. [ "$TYPE" = "TemplateVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_TEMPLATEVM
  37. # Enable default services
  38. for srv in $DEFAULT_ENABLED; do
  39. touch /var/run/qubes-service/$srv
  40. done
  41. # Enable services
  42. for srv in `$XS_LS qubes-service 2>/dev/null |grep ' = "1"'|cut -f 1 -d ' '`; do
  43. touch /var/run/qubes-service/$srv
  44. done
  45. # Disable services
  46. for srv in `$XS_LS qubes-service 2>/dev/null |grep ' = "0"'|cut -f 1 -d ' '`; do
  47. rm -f /var/run/qubes-service/$srv
  48. done
  49. # Set the hostname
  50. name=`$XS_READ name`
  51. if [ -n "$name" ]; then
  52. hostname $name
  53. sed -i "s/^\(127\.0\.0\.1 .*\) \($name \)\?\(.*\)/\1\2 $name/" /etc/hosts
  54. fi
  55. timezone=`$XS_READ qubes-timezone 2> /dev/null`
  56. if [ -n "$timezone" ]; then
  57. ln -f /usr/share/zoneinfo/$timezone /etc/localtime
  58. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  59. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  60. fi
  61. # Prepare environment for other services
  62. echo > /var/run/qubes-service-environment
  63. debug_mode=`$XS_READ qubes-debug-mode 2> /dev/null`
  64. if [ -n "$debug_mode" -a "$debug_mode" -gt 0 ]; then
  65. echo "GUI_OPTS=-vv" >> /var/run/qubes-service-environment
  66. fi
  67. exit 0