qubes-sysinit.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # Location of files which contains list of protected files
  11. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  12. read_service() {
  13. $QDB_READ /qubes-service/$1 2> /dev/null
  14. }
  15. systemd_pkg_version=`systemctl --version|head -n 1`
  16. if ! dmesg | grep -q "$systemd_pkg_version running in system mode."; then
  17. # Ensure we're running right version of systemd (the one started by initrd may be different)
  18. systemctl daemon-reexec
  19. fi
  20. # Wait for xenbus initialization
  21. while [ ! -e /dev/xen/xenbus -a ! -e /proc/xen/xenbus ]; do
  22. sleep 0.1
  23. done
  24. mkdir -p /var/run/qubes
  25. chgrp qubes /var/run/qubes
  26. chmod 0775 /var/run/qubes
  27. mkdir -p /var/run/qubes-service
  28. mkdir -p /var/run/xen-hotplug
  29. # Set permissions to /proc/xen/xenbus, so normal user can talk to xenstore, to
  30. # open vchan connection. Note that new code uses /dev/xen/xenbus (which have
  31. # permissions set by udev), so this probably can go away soon
  32. chmod 666 /proc/xen/xenbus
  33. # Set permissions to /proc/xen/privcmd, so a user in qubes group can access
  34. chmod 660 /proc/xen/privcmd
  35. chgrp qubes /proc/xen/privcmd
  36. [ -e /proc/u2mfn ] || modprobe u2mfn
  37. # Set permissions to files needed by gui-agent
  38. chmod 666 /proc/u2mfn
  39. # Set default services depending on VM type
  40. TYPE=`$QDB_READ /qubes-vm-type 2> /dev/null`
  41. [ "$TYPE" = "AppVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_APPVM && touch /var/run/qubes/this-is-appvm
  42. [ "$TYPE" = "NetVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_NETVM && touch /var/run/qubes/this-is-netvm
  43. [ "$TYPE" = "ProxyVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_PROXYVM && touch /var/run/qubes/this-is-proxyvm
  44. [ "$TYPE" = "TemplateVM" ] && DEFAULT_ENABLED=$DEFAULT_ENABLED_TEMPLATEVM && touch /var/run/qubes/this-is-templatevm
  45. # Enable default services
  46. for srv in $DEFAULT_ENABLED; do
  47. touch /var/run/qubes-service/$srv
  48. done
  49. # Enable services
  50. for srv in `$QDB_LS /qubes-service/ 2>/dev/null |grep ' = 1'|cut -f 1 -d ' '`; do
  51. touch /var/run/qubes-service/$srv
  52. done
  53. # Disable services
  54. for srv in `$QDB_LS /qubes-service/ 2>/dev/null |grep ' = 0'|cut -f 1 -d ' '`; do
  55. rm -f /var/run/qubes-service/$srv
  56. done
  57. # Set the hostname
  58. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  59. name=`$QDB_READ /name`
  60. if [ -n "$name" ]; then
  61. hostname $name
  62. if [ -e /etc/debian_version ]; then
  63. ipv4_localhost_re="127\.0\.1\.1"
  64. else
  65. ipv4_localhost_re="127\.0\.0\.1"
  66. fi
  67. sed -i "s/^\($ipv4_localhost_re\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  68. sed -i "s/^\(::1\(\s.*\)*\s\).*$/\1${name}/" /etc/hosts
  69. fi
  70. fi
  71. # Set the timezone
  72. if ! grep -rq "^/etc/timezone$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  73. timezone=`$QDB_READ /qubes-timezone 2> /dev/null`
  74. if [ -n "$timezone" ]; then
  75. ln -sf ../usr/share/zoneinfo/$timezone /etc/localtime
  76. if [ -e /etc/debian_version ]; then
  77. echo "$timezone" > /etc/timezone
  78. else
  79. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  80. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  81. fi
  82. fi
  83. fi
  84. # Prepare environment for other services
  85. echo > /var/run/qubes-service-environment
  86. debug_mode=`$QDB_READ /qubes-debug-mode 2> /dev/null`
  87. if [ -n "$debug_mode" -a "$debug_mode" -gt 0 ]; then
  88. echo "GUI_OPTS=-vv" >> /var/run/qubes-service-environment
  89. fi
  90. exit 0