aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qvm-screenrecord.sh
blob: 57a71992aa824f740f6098be67cedd0941e31e36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh

# Record desktop in Qubes Dom0 and copy video to AppVM
# Dependencies: recordmydesktop (sudo qubes-dom0-update recordmydesktop)
# If you want create a keyboard shortcut you should run it in Konsole
# Example: konsole -e qvm-screenrecord.sh -s -n
# 2013, Laurent Ghigonis <laurent@p1sec.com>

DOM0_SHOTS_DIR=$HOME/shots
APPVM_SHOTS_DIR=/home/user/shots
QUBES_DOM0_APPVMS=/var/lib/qubes/appvms/

usage() {
	echo "$program [-hns]"
	echo -e "\t-n : after capturing, run nautilus in AppVM"
	echo -e "\t-s : select window to capture"
}

program="`basename $0`"
mode_nautilus=0
mode_select=0
opts="$(getopt -o hns -n "$program" -- "$@")"
err=$?
eval set -- "$opts"
while true; do case $1 in
	-h) usage; exit 1 ;;
	-n) mode_nautilus=1; shift ;;
	-s) mode_select=1; shift ;;
	--) shift; break ;;
esac done
[[ $err -ne 0 ]] && usage && exit 1

mkdir -p $DOM0_SHOTS_DIR ||exit 1
d=`date +"%Y%m%d-%H%M"`
tmpname=$d.ogv

if [ $mode_select -eq 1 ]; then
	echo "[-] select window to record"
	echo "Press <enter> when ready to select"
	read a
	unset x y w h
	eval $(xwininfo | \
		sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
		       -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
		       -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
		       -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
	record_opts="-x $x -y $y --width $w --height $h"
	echo "[-] recording zone at ${x} ${y} size ${w} ${h}"
else
	echo "[-] recording root window"
	echo "Press <enter> when ready to record"
	read a
	record_opts=""
fi

echo
echo "============================="
echo "Hit Crtl-C to end the capture"
echo "============================="
echo
recordmydesktop --no-sound -o $DOM0_SHOTS_DIR/$tmpname $record_opts $@
size=`ls -hs $DOM0_SHOTS_DIR/$tmpname |cut -d' ' -f1`

title=`kdialog --inputbox "Enter capture title ($size)" --title "$program"`
[[ X"$title" = X"" ]] && exit 1
vidname=${d}_${title}.ogv

echo "[-] saving $DOM0_SHOTS_DIR/$vidname ($size)"
mv $DOM0_SHOTS_DIR/$tmpname $DOM0_SHOTS_DIR/$vidname
ls -lh $DOM0_SHOTS_DIR/$vidname

choice=`ls $QUBES_DOM0_APPVMS |sed 's/\([^ ]*\)/\1 \1/g'`
appvm=`kdialog --menu "Select destination AppVM" $choice --title "$program"`

if [ X"$appvm" != X"" ]; then
	if [ $mode_nautilus -eq 1 ]; then
		echo "[-] running nautilus in AppVM"
		qvm-run $appvm "nautilus $APPVM_SHOTS_DIR"
	fi

	echo "[-] copy to AppVM $appvm"
	qvm-run $appvm "mkdir -p $APPVM_SHOTS_DIR"
	echo "[-] copying $APPVM_SHOTS_DIR/$vidname"
	cat $DOM0_SHOTS_DIR/$vidname \
		|qvm-run --pass-io $appvm "cat > $APPVM_SHOTS_DIR/$vidname"
else
	echo "no AppVM name provided"
fi

echo "[*] done"