qubes-core 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash
  2. #
  3. # chkconfig: 345 90 90
  4. # description: Executes Qubes core scripts at VM boot
  5. #
  6. # Source function library.
  7. . /etc/rc.d/init.d/functions
  8. start()
  9. {
  10. echo -n $"Executing Qubes Core scripts:"
  11. # Set permissions to /proc/xen/xenbus, so normal user can access xenstore
  12. chmod 666 /proc/xen/xenbus
  13. # Set permissions to files needed by gui-agent
  14. chmod 666 /proc/u2mfn
  15. mkdir -p /var/run/xen-hotplug
  16. mkdir -p /var/run/qubes
  17. chgrp qubes /var/run/qubes
  18. chmod 0775 /var/run/qubes
  19. # Load random seed from dom0
  20. qubesdb-read /qubes-random-seed | base64 -d > /dev/urandom
  21. qubesdb-rm /qubes-random-seed
  22. # Location of files which contains list of protected files
  23. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  24. # Set the hostname
  25. if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  26. name=$(/usr/bin/qubesdb-read /name)
  27. if ! [ -f /etc/this-is-dvm ] ; then
  28. # we don't want to set hostname for DispVM
  29. # because it makes some of the pre-created dotfiles invalid (e.g. .kde/cache-<hostname>)
  30. # (let's be frank: nobody's gonna use xterm on DispVM)
  31. hostname $name
  32. sed -i "s/^\(127\.0\.0\.1[\t ].*\) \($name \)\?\(.*\)/\1\2 $name/" /etc/hosts
  33. fi
  34. fi
  35. # Set the timezone
  36. if ! grep -rq "^/etc/timezone$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  37. timezone=`/usr/bin/qubesdb-read /qubes-timezone 2> /dev/null`
  38. if [ -n "$timezone" ]; then
  39. ln -f /usr/share/zoneinfo/$timezone /etc/localtime
  40. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  41. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  42. fi
  43. fi
  44. /usr/lib/qubes/update-proxy-configs
  45. # Set IP address again (besides action in udev rules); this is needed by
  46. # DispVM (to override DispVM-template IP) and in case when qubes-ip was
  47. # called by udev before loading evtchn kernel module - in which case
  48. # qubesdb-read fails
  49. INTERFACE=eth0 /usr/lib/qubes/setup-ip
  50. if [ -e /dev/xvdb ] ; then
  51. # check if private.img (xvdb) is empty - all zeros
  52. private_size_512=`blockdev --getsz /dev/xvdb`
  53. if dd if=/dev/zero bs=512 count=$private_size_512 | diff /dev/xvdb - >/dev/null; then
  54. # the device is empty, create filesystem
  55. echo "--> Virgin boot of the VM: creating filesystem on private.img"
  56. mkfs.ext4 -m 0 -q /dev/xvdb || exit 1
  57. fi
  58. mount /rw
  59. resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed"
  60. if ! [ -d /rw/home ] ; then
  61. echo
  62. echo "--> Virgin boot of the VM: Linking /home to /rw/home"
  63. mkdir -p /rw/config
  64. cat > /rw/config/rc.local <<EOF
  65. #!/bin/sh
  66. # This script will be executed at every VM startup, you can place your own
  67. # custom commands here. This include overriding some configuration in /etc,
  68. # starting services etc.
  69. #
  70. # You need to make this script executable to have it enabled.
  71. # Example for overriding the whole CUPS configuration:
  72. # rm -rf /etc/cups
  73. # ln -s /rw/config/cups /etc/cups
  74. # systemctl --no-block restart cups
  75. EOF
  76. touch /rw/config/qubes-firewall-user-script
  77. cat > /rw/config/qubes-firewall-user-script <<EOF
  78. #!/bin/sh
  79. # This script is called in ProxyVM after firewall every update (configuration
  80. # change, starting some VM etc). This is good place to write own custom
  81. # firewall rules, in addition to autogenerated one. Remember that in most cases
  82. # you'll need to insert the rules at the beginning (iptables -I) to have it
  83. # efective.
  84. #
  85. # You need to make this script executable to have it enabled.
  86. EOF
  87. touch /rw/config/suspend-module-blacklist
  88. cat > /rw/config/suspend-module-blacklist <<EOF
  89. # You can list here modules you want to be unloaded before going to sleep. This
  90. # file is used only if the VM has any PCI device assigned. Modules will be
  91. # automatically loaded after resume.
  92. EOF
  93. mkdir -p /rw/home
  94. cp -a /home.orig/user /rw/home
  95. mkdir -p /rw/usrlocal
  96. cp -a /usr/local.orig/* /rw/usrlocal
  97. touch /var/lib/qubes/first-boot-completed
  98. fi
  99. fi
  100. if [ -L /home ]; then
  101. rm /home
  102. mkdir /home
  103. fi
  104. mount /home
  105. if [ -n "`ls -A /usr/local/lib 2>/dev/null`" -o \
  106. -n "`ls -A /usr/local/lib64 2>/dev/null`" ]; then
  107. ldconfig
  108. fi
  109. [ -x /rw/config/rc.local ] && /rw/config/rc.local
  110. success
  111. echo ""
  112. start_ntpd=$(/usr/bin/qubesdb-read /qubes-service/ntpd 2> /dev/null)
  113. if [ "$start_ntpd" == "1" ]; then
  114. /sbin/service ntpd start
  115. fi
  116. return 0
  117. }
  118. stop()
  119. {
  120. su -c 'mkdir -p /home_volatile/user/.local/share/applications' user
  121. su -c 'cp -a /usr/share/applications/defaults.list /home_volatile/user/.local/share/applications/' user
  122. if [ -r '/home/user/.local/share/applications/defaults.list' ]; then
  123. su -c 'cat /home/user/.local/share/applications/defaults.list >> /home_volatile/user/.local/share/applications/defaults.list' user
  124. fi
  125. return 0
  126. }
  127. case "$1" in
  128. start)
  129. start
  130. ;;
  131. stop)
  132. stop
  133. ;;
  134. *)
  135. echo $"Usage: $0 {start|stop}"
  136. exit 3
  137. ;;
  138. esac
  139. exit $RETVAL