qubes_core 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  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. possibly_run_save_script()
  9. {
  10. ENCODED_SCRIPT=$(xenstore-read qubes_save_script)
  11. if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi
  12. echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64(<STDIN>)' >/tmp/qubes_save_script
  13. chmod 755 /tmp/qubes_save_script
  14. Xorg -config /etc/X11/xorg-preload-apps.conf :0 &
  15. sleep 2
  16. DISPLAY=:0 su - user -c /tmp/qubes_save_script
  17. killall Xorg
  18. }
  19. start()
  20. {
  21. echo -n $"Executing Qubes Core scripts:"
  22. if ! [ -x /usr/bin/xenstore-read ] ; then
  23. echo "ERROR: /usr/bin/xenstore-read not found!"
  24. exit 1
  25. fi
  26. if xenstore-read qubes_save_request 2>/dev/null ; then
  27. ln -sf /home_volatile /home
  28. possibly_run_save_script
  29. touch /etc/this_is_dvm
  30. dmesg -c >/dev/null
  31. free | grep Mem: |
  32. (read a b c d ; xenstore-write device/qubes_used_mem $c)
  33. # we're still running in DispVM template
  34. echo "Waiting for save/restore..."
  35. # ... wait until qubes_restore.c (in Dom0) recreates VM-specific keys
  36. while ! xenstore-read qubes_restore_complete 2>/dev/null ; do
  37. usleep 10
  38. done
  39. echo Back to life.
  40. fi
  41. name=$(/usr/bin/xenstore-read name)
  42. if ! [ -f /etc/this_is_dvm ] ; then
  43. # we don't want to set hostname for DispVM
  44. # because it makes some of the pre-created dotfiles invalid (e.g. .kde/cache-<hostname>)
  45. # (let's be frank: nobody's gonna use xterm on DispVM)
  46. hostname $name
  47. fi
  48. ip=$(/usr/bin/xenstore-read qubes_ip)
  49. netmask=$(/usr/bin/xenstore-read qubes_netmask)
  50. gateway=$(/usr/bin/xenstore-read qubes_gateway)
  51. secondary_dns=$(/usr/bin/xenstore-read qubes_secondary_dns)
  52. if [ x$ip != x ]; then
  53. /sbin/ifconfig eth0 $ip netmask 255.255.255.255 up
  54. /sbin/route add default dev eth0
  55. echo "nameserver $gateway" > /etc/resolv.conf
  56. echo "nameserver $secondary_dns" >> /etc/resolv.conf
  57. fi
  58. if [ -e /dev/xvdb ] ; then
  59. mount /rw
  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. touch /rw/config/rc.local
  65. mkdir -p /rw/home
  66. cp -a /home.orig/user /home
  67. mkdir -p /rw/usrlocal
  68. cp -a /usr/local.orig/* /usr/local
  69. touch /var/lib/qubes/first_boot_completed
  70. fi
  71. fi
  72. MEM_CHANGE_THRESHOLD_KB=30000
  73. MEMINFO_DELAY_USEC=100000
  74. /usr/lib/qubes/meminfo-writer $MEM_CHANGE_THRESHOLD_KB $MEMINFO_DELAY_USEC &
  75. [ -x /rw/config/rc.local ] && /rw/config/rc.local
  76. success
  77. echo ""
  78. return 0
  79. }
  80. stop()
  81. {
  82. return 0
  83. }
  84. case "$1" in
  85. start)
  86. start
  87. ;;
  88. stop)
  89. stop
  90. ;;
  91. *)
  92. echo $"Usage: $0 {start|stop}"
  93. exit 3
  94. ;;
  95. esac
  96. exit $RETVAL