qubes-sysinit.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. # List of services enabled by default (in case of absence of qubesdb 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. QDB_READ=qubesdb-read
  9. QDB_LS=qubesdb-multiread
  10. read_service() {
  11. $QDB_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 /dev/xen/xenbus ]; do
  20. sleep 0.1
  21. done
  22. mkdir -p /var/run/qubes
  23. chgrp qubes /var/run/qubes
  24. chmod 0775 /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 talk to xenstore, to
  28. # open vchan connection. Note that new code uses /dev/xen/xenbus (which have
  29. # permissions set by udev), so this probably can go away soon
  30. chmod 666 /proc/xen/xenbus
  31. # Set permissions to /proc/xen/privcmd, so a user in qubes group can access
  32. chmod 660 /proc/xen/privcmd
  33. chgrp qubes /proc/xen/privcmd
  34. [ -e /proc/u2mfn ] || modprobe u2mfn
  35. # Set permissions to files needed by gui-agent
  36. chmod 666 /proc/u2mfn
  37. # Set default services depending on VM type
  38. TYPE=`$QDB_READ /qubes-vm-type 2> /dev/null`
  39. [ "$TYPE" = "AppVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_APPVM
  40. [ "$TYPE" = "NetVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_NETVM
  41. [ "$TYPE" = "ProxyVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_PROXYVM
  42. [ "$TYPE" = "TemplateVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_TEMPLATEVM
  43. # Enable default services
  44. for srv in $DEFAULT_ENABLED; do
  45. touch /var/run/qubes-service/$srv
  46. done
  47. # Enable services
  48. for srv in `$QDB_LS /qubes-service/ 2>/dev/null |grep ' = 1'|cut -f 1 -d ' '`; do
  49. touch /var/run/qubes-service/$srv
  50. done
  51. # Disable services
  52. for srv in `$QDB_LS /qubes-service/ 2>/dev/null |grep ' = 0'|cut -f 1 -d ' '`; do
  53. rm -f /var/run/qubes-service/$srv
  54. done
  55. # Set the hostname
  56. name=`$QDB_READ /name`
  57. if [ -n "$name" ]; then
  58. hostname $name
  59. if [ -e /etc/debian_version ]; then
  60. ipv4_localhost_re="127\.0\.1\.1"
  61. else
  62. ipv4_localhost_re="127\.0\.0\.1"
  63. fi
  64. sed -i "s/^\($ipv4_localhost_re\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  65. sed -i "s/^\(::1\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  66. fi
  67. timezone=`$QDB_READ /qubes-timezone 2> /dev/null`
  68. if [ -n "$timezone" ]; then
  69. cp -p /usr/share/zoneinfo/$timezone /etc/localtime
  70. if [ -e /etc/debian_version ]; then
  71. echo "$timezone" > /etc/timezone
  72. else
  73. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  74. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  75. fi
  76. fi
  77. # Prepare environment for other services
  78. echo > /var/run/qubes-service-environment
  79. debug_mode=`$QDB_READ /qubes-debug-mode 2> /dev/null`
  80. if [ -n "$debug_mode" -a "$debug_mode" -gt 0 ]; then
  81. echo "GUI_OPTS=-vv" >> /var/run/qubes-service-environment
  82. fi
  83. exit 0