qubes-sysinit.sh 2.6 KB

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