qubes-core 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. yum_proxy_setup=$(/usr/bin/qubesdb-read /qubes-service/yum-proxy-setup 2> /dev/null || /usr/bin/qubesdb-read /qubes-service/updates-proxy-setup 2> /dev/null)
  45. type=$(/usr/bin/qubesdb-read /qubes-vm-type)
  46. if [ "$yum_proxy_setup" != "0" ] || [ -z "$yum_proxy_setup" -a "$type" == "TemplateVM" ]; then
  47. echo proxy=http://10.137.255.254:8082/ > /etc/yum.conf.d/qubes-proxy.conf
  48. else
  49. echo > /etc/yum.conf.d/qubes-proxy.conf
  50. fi
  51. # Set IP address again (besides action in udev rules); this is needed by
  52. # DispVM (to override DispVM-template IP) and in case when qubes-ip was
  53. # called by udev before loading evtchn kernel module - in which case
  54. # qubesdb-read fails
  55. INTERFACE=eth0 /usr/lib/qubes/setup-ip
  56. if [ -e /dev/xvdb ] ; then
  57. # check if private.img (xvdb) is empty - all zeros
  58. private_size_512=`blockdev --getsz /dev/xvdb`
  59. if dd if=/dev/zero bs=512 count=$private_size_512 | diff /dev/xvdb - >/dev/null; then
  60. # the device is empty, create filesystem
  61. echo "--> Virgin boot of the VM: creating filesystem on private.img"
  62. mkfs.ext4 -m 0 -q /dev/xvdb || exit 1
  63. fi
  64. mount /rw
  65. resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed"
  66. if ! [ -d /rw/home ] ; then
  67. echo
  68. echo "--> Virgin boot of the VM: Linking /home to /rw/home"
  69. mkdir -p /rw/config
  70. cat > /rw/config/rc.local <<EOF
  71. #!/bin/sh
  72. # This script will be executed at every VM startup, you can place your own
  73. # custom commands here. This include overriding some configuration in /etc,
  74. # starting services etc.
  75. #
  76. # You need to make this script executable to have it enabled.
  77. # Example for overriding the whole CUPS configuration:
  78. # rm -rf /etc/cups
  79. # ln -s /rw/config/cups /etc/cups
  80. # systemctl --no-block restart cups
  81. EOF
  82. touch /rw/config/qubes-firewall-user-script
  83. cat > /rw/config/qubes-firewall-user-script <<EOF
  84. #!/bin/sh
  85. # This script is called in ProxyVM after firewall every update (configuration
  86. # change, starting some VM etc). This is good place to write own custom
  87. # firewall rules, in addition to autogenerated one. Remember that in most cases
  88. # you'll need to insert the rules at the beginning (iptables -I) to have it
  89. # efective.
  90. #
  91. # You need to make this script executable to have it enabled.
  92. EOF
  93. touch /rw/config/suspend-module-blacklist
  94. cat > /rw/config/suspend-module-blacklist <<EOF
  95. # You can list here modules you want to be unloaded before going to sleep. This
  96. # file is used only if the VM has any PCI device assigned. Modules will be
  97. # automatically loaded after resume.
  98. EOF
  99. mkdir -p /rw/home
  100. cp -a /home.orig/user /rw/home
  101. mkdir -p /rw/usrlocal
  102. cp -a /usr/local.orig/* /rw/usrlocal
  103. touch /var/lib/qubes/first-boot-completed
  104. fi
  105. fi
  106. if [ -L /home ]; then
  107. rm /home
  108. mkdir /home
  109. fi
  110. mount /home
  111. if [ -n "`ls -A /usr/local/lib 2>/dev/null`" -o \
  112. -n "`ls -A /usr/local/lib64 2>/dev/null`" ]; then
  113. ldconfig
  114. fi
  115. [ -x /rw/config/rc.local ] && /rw/config/rc.local
  116. success
  117. echo ""
  118. start_ntpd=$(/usr/bin/qubesdb-read /qubes-service/ntpd 2> /dev/null)
  119. if [ "$start_ntpd" == "1" ]; then
  120. /sbin/service ntpd start
  121. fi
  122. return 0
  123. }
  124. stop()
  125. {
  126. su -c 'mkdir -p /home_volatile/user/.local/share/applications' user
  127. su -c 'cp -a /usr/share/applications/defaults.list /home_volatile/user/.local/share/applications/' user
  128. if [ -r '/home/user/.local/share/applications/defaults.list' ]; then
  129. su -c 'cat /home/user/.local/share/applications/defaults.list >> /home_volatile/user/.local/share/applications/defaults.list' user
  130. fi
  131. return 0
  132. }
  133. case "$1" in
  134. start)
  135. start
  136. ;;
  137. stop)
  138. stop
  139. ;;
  140. *)
  141. echo $"Usage: $0 {start|stop}"
  142. exit 3
  143. ;;
  144. esac
  145. exit $RETVAL