qubes-core-appvm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. #
  3. # chkconfig: 345 85 85
  4. # description: Executes Qubes core scripts at AppVM 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. while ! [ -S /tmp/.X11-unix/X0 ]; do sleep 0.5; done
  16. DISPLAY=:0 su - user -c /tmp/qubes-save-script
  17. killall Xorg
  18. }
  19. start()
  20. {
  21. if ! [ -x /usr/bin/xenstore-read ] ; then
  22. echo "ERROR: /usr/bin/xenstore-read not found!"
  23. exit 1
  24. fi
  25. type=$(/usr/bin/xenstore-read qubes-vm-type)
  26. if [ "$type" != "AppVM" -a "$type" != "DisposableVM" -a "$type" != "TemplateVM" ]; then
  27. # This script runs only on AppVMs
  28. return 0
  29. fi
  30. # Start AppVM specific services
  31. start_cups=$(/usr/bin/xenstore-read qubes-service/cups 2> /dev/null)
  32. if [ "$start_cups" != "0" ]; then
  33. /sbin/service cups start
  34. # Allow also notification icon
  35. sed -i -e '/^NotShowIn=.*QUBES/s/;QUBES//' /etc/xdg/autostart/print-applet.desktop
  36. else
  37. # Disable notification icon
  38. sed -i -e '/QUBES/!s/^NotShowIn=.*/\1QUBES;/' /etc/xdg/autostart/print-applet.desktop
  39. fi
  40. echo -n $"Executing Qubes Core scripts for AppVM:"
  41. if xenstore-read qubes-save-request 2>/dev/null ; then
  42. if [ -L /home ]; then
  43. rm /home
  44. mkdir /home
  45. fi
  46. mount --bind /home_volatile /home
  47. touch /etc/this-is-dvm
  48. mount /rw
  49. possibly_run_save_script
  50. umount /rw
  51. dmesg -c >/dev/null
  52. free | grep Mem: |
  53. (read a b c d ; xenstore-write device/qubes-used-mem $c)
  54. # we're still running in DispVM template
  55. echo "Waiting for save/restore..."
  56. # ... wait until qubes-restore.c (in Dom0) recreates VM-specific keys
  57. while ! xenstore-read qubes-restore-complete 2>/dev/null ; do
  58. usleep 10
  59. done
  60. echo Back to life.
  61. fi
  62. start_meminfo_writer=$(/usr/bin/xenstore-read qubes-service/meminfo-writer 2>/dev/null)
  63. if [ "$start_meminfo_writer" != "0" ]; then
  64. MEM_CHANGE_THRESHOLD_KB=30000
  65. MEMINFO_DELAY_USEC=100000
  66. /usr/lib/qubes/meminfo-writer $MEM_CHANGE_THRESHOLD_KB $MEMINFO_DELAY_USEC /var/run/meminfo-writer.pid
  67. fi
  68. success
  69. echo ""
  70. return 0
  71. }
  72. stop()
  73. {
  74. return 0
  75. }
  76. case "$1" in
  77. start)
  78. start
  79. ;;
  80. stop)
  81. stop
  82. ;;
  83. *)
  84. echo $"Usage: $0 {start|stop}"
  85. exit 3
  86. ;;
  87. esac
  88. exit $RETVAL