qubes-core 4.7 KB

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