prepare-dvm.sh 936 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  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. DISPLAY=:0 su - user -c /tmp/qubes-save-script
  9. }
  10. if true; then
  11. echo user | /bin/sh /etc/qubes-rpc/qubes.WaitForSession
  12. possibly_run_save_script
  13. umount /rw
  14. dmesg -c >/dev/null
  15. qubesdb-watch /qubes-restore-complete &
  16. watch_pid=$!
  17. free | grep Mem: |
  18. (read label total used free shared buffers cached; qubesdb-write /qubes-used-mem $(( $used + $cached )) )
  19. # we're still running in DispVM template
  20. echo "Waiting for save/restore..."
  21. qubesdb-read /qubes-restore-complete || wait $watch_pid
  22. echo Back to life.
  23. systemctl --no-block restart qubes-random-seed.service
  24. fi