qubes_core_appvm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. sleep 2
  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. ln -sf /home_volatile /home
  43. possibly_run_save_script
  44. touch /etc/this_is_dvm
  45. dmesg -c >/dev/null
  46. free | grep Mem: |
  47. (read a b c d ; xenstore-write device/qubes_used_mem $c)
  48. # we're still running in DispVM template
  49. echo "Waiting for save/restore..."
  50. # ... wait until qubes_restore.c (in Dom0) recreates VM-specific keys
  51. while ! xenstore-read qubes_restore_complete 2>/dev/null ; do
  52. usleep 10
  53. done
  54. echo Back to life.
  55. fi
  56. start_meminfo_writer=$(/usr/bin/xenstore-read qubes-service/meminfo-writer 2>/dev/null)
  57. if [ "$start_meminfo_writer" != "0" ]; then
  58. MEM_CHANGE_THRESHOLD_KB=30000
  59. MEMINFO_DELAY_USEC=100000
  60. /usr/lib/qubes/meminfo-writer $MEM_CHANGE_THRESHOLD_KB $MEMINFO_DELAY_USEC /var/run/meminfo-writer.pid
  61. fi
  62. success
  63. echo ""
  64. return 0
  65. }
  66. stop()
  67. {
  68. return 0
  69. }
  70. case "$1" in
  71. start)
  72. start
  73. ;;
  74. stop)
  75. stop
  76. ;;
  77. *)
  78. echo $"Usage: $0 {start|stop}"
  79. exit 3
  80. ;;
  81. esac
  82. exit $RETVAL