qubes-sysinit.sh 2.4 KB

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