qubes-sysinit.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # Source Qubes library.
  3. . /usr/lib/qubes/init/functions
  4. # List of services enabled by default (in case of absence of qubesdb entry)
  5. DEFAULT_ENABLED_NETVM="network-manager qubes-network qubes-update-check qubes-updates-proxy"
  6. DEFAULT_ENABLED_PROXYVM="meminfo-writer qubes-network qubes-firewall qubes-netwatcher qubes-update-check"
  7. DEFAULT_ENABLED_APPVM="meminfo-writer cups qubes-update-check"
  8. DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_APPVM updates-proxy-setup"
  9. DEFAULT_ENABLED="meminfo-writer"
  10. if systemd_version_changed ; then
  11. # Ensure we're running right version of systemd (the one started by initrd may be different)
  12. systemctl daemon-reexec
  13. fi
  14. # Wait for xenbus initialization
  15. while [ ! -e /dev/xen/xenbus -a ! -e /proc/xen/xenbus ]; do
  16. sleep 0.1
  17. done
  18. mkdir -p /var/run/qubes
  19. chgrp qubes /var/run/qubes
  20. chmod 0775 /var/run/qubes
  21. mkdir -p /var/run/qubes-service
  22. mkdir -p /var/run/xen-hotplug
  23. # Set permissions to /proc/xen/xenbus, so normal user can talk to xenstore, to
  24. # open vchan connection. Note that new code uses /dev/xen/xenbus (which have
  25. # permissions set by udev), so this probably can go away soon
  26. chmod 666 /proc/xen/xenbus
  27. # Set permissions to /proc/xen/privcmd, so a user in qubes group can access
  28. chmod 660 /proc/xen/privcmd
  29. chgrp qubes /proc/xen/privcmd
  30. [ -e /proc/u2mfn ] || modprobe u2mfn
  31. # Set permissions to files needed by gui-agent
  32. chmod 666 /proc/u2mfn
  33. # Set default services depending on VM type
  34. is_appvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_APPVM && touch /var/run/qubes/this-is-appvm
  35. is_netvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_NETVM && touch /var/run/qubes/this-is-netvm
  36. is_proxyvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_PROXYVM && touch /var/run/qubes/this-is-proxyvm
  37. is_templatevm && DEFAULT_ENABLED=$DEFAULT_ENABLED_TEMPLATEVM && touch /var/run/qubes/this-is-templatevm
  38. # Enable default services
  39. for srv in $DEFAULT_ENABLED; do
  40. touch /var/run/qubes-service/$srv
  41. done
  42. # Enable services
  43. for srv in `qubesdb-multiread /qubes-service/ 2>/dev/null |grep ' = 1'|cut -f 1 -d ' '`; do
  44. touch /var/run/qubes-service/$srv
  45. done
  46. # Disable services
  47. for srv in `qubesdb-multiread /qubes-service/ 2>/dev/null |grep ' = 0'|cut -f 1 -d ' '`; do
  48. rm -f /var/run/qubes-service/$srv
  49. done
  50. # Set the hostname
  51. if ! is_protected_file /etc/hostname ; then
  52. name=`qubesdb-read /name`
  53. if [ -n "$name" ]; then
  54. hostname $name
  55. if [ -e /etc/debian_version ]; then
  56. ipv4_localhost_re="127\.0\.1\.1"
  57. else
  58. ipv4_localhost_re="127\.0\.0\.1"
  59. fi
  60. sed -i "s/^\($ipv4_localhost_re\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  61. sed -i "s/^\(::1\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  62. fi
  63. fi
  64. # Set the timezone
  65. if ! is_protected_file /etc/timezone ; then
  66. timezone=`qubesdb-read /qubes-timezone 2> /dev/null`
  67. if [ -n "$timezone" ]; then
  68. ln -sf ../usr/share/zoneinfo/"$timezone" /etc/localtime
  69. if [ -e /etc/debian_version ]; then
  70. echo "$timezone" > /etc/timezone
  71. elif test -d /etc/sysconfig ; then
  72. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  73. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  74. fi
  75. fi
  76. fi
  77. # Prepare environment for other services
  78. echo > /var/run/qubes-service-environment
  79. debug_mode=`qubesdb-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