qubes-core 5.0 KB

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