$(( )) is POSIX syntax for shell arithmetic operations. Especially dash (default shell in Debian) doesn't support $[ ].
		
			
				
	
	
		
			27 lines
		
	
	
		
			877 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			877 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash
 | 
						|
 | 
						|
possibly_run_save_script()
 | 
						|
{
 | 
						|
	ENCODED_SCRIPT=$(qubesdb-read /qubes-save-script)
 | 
						|
	if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi
 | 
						|
	echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64(<STDIN>)' >/tmp/qubes-save-script
 | 
						|
	chmod 755 /tmp/qubes-save-script
 | 
						|
	DISPLAY=:0 su - user -c /tmp/qubes-save-script
 | 
						|
}
 | 
						|
 | 
						|
if true; then
 | 
						|
    echo user | /bin/sh /etc/qubes-rpc/qubes.WaitForSession
 | 
						|
    possibly_run_save_script
 | 
						|
    umount /rw
 | 
						|
    dmesg -c >/dev/null
 | 
						|
    qubesdb-watch /qubes-restore-complete &
 | 
						|
    watch_pid=$!
 | 
						|
    free | grep Mem: | 
 | 
						|
        (read label total used free shared buffers cached; qubesdb-write /qubes-used-mem $(( $used + $cached )) )
 | 
						|
    # we're still running in DispVM template
 | 
						|
    echo "Waiting for save/restore..."
 | 
						|
    qubesdb-read /qubes-restore-complete || wait $watch_pid
 | 
						|
    echo Back to life.
 | 
						|
fi
 | 
						|
 |