prepare-dvm.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. possibly_run_save_script()
  3. {
  4. ENCODED_SCRIPT=$(qubesdb-read /qubes-save-script)
  5. if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi
  6. echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64(<STDIN>)' >/tmp/qubes-save-script
  7. chmod 755 /tmp/qubes-save-script
  8. Xorg -config /etc/X11/xorg-preload-apps.conf :0 &
  9. while ! [ -S /tmp/.X11-unix/X0 ]; do sleep 0.5; done
  10. DISPLAY=:0 su - user -c /tmp/qubes-save-script
  11. killall Xorg
  12. }
  13. if qubesdb-read /qubes-save-request 2>/dev/null ; then
  14. if [ -L /home ]; then
  15. rm /home
  16. mkdir /home
  17. fi
  18. mount --bind /home_volatile /home
  19. touch /etc/this-is-dvm
  20. mount /rw
  21. possibly_run_save_script
  22. umount /rw
  23. dmesg -c >/dev/null
  24. free | grep Mem: |
  25. (read a b c d ; qubesdb-write /qubes-used-mem $c)
  26. # give dom0 time to read some entries, when done it will shutdown qubesdb,
  27. # so wait for it
  28. qubesdb-watch /stop-qubesdb
  29. # just to make sure
  30. systemctl stop qubes-db.service
  31. # we're still running in DispVM template
  32. echo "Waiting for save/restore..."
  33. # the service will start only after successful restore
  34. systemctl start qubes-db.service
  35. echo Back to life.
  36. fi