qubes-sysinit.sh 2.4 KB

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