rename err to bash-bear
[distro-setup] / ziva-screen
1 #!/bin/bash
2
3 # Get screenshots from bow, discard them if they dont change much.
4
5 source /usr/local/lib/bash-bear
6 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
7
8 dest_dir=/d/ziva-log
9 case $HOSTNAME in
10 sy)
11 dest_dir=/t/zlog
12 ;;
13 esac
14
15 f=/run/user/1000/ziva-tmp.jpg
16
17 mkdir -p $dest_dir
18 cd $dest_dir
19 shopt -s nullglob
20 jpgs=( 20*jpg )
21 if (( ${#jpgs[@]} >= 1 )); then
22 # shellcheck disable=SC2048 # intentional
23 lastf=$(ls -1 20*jpg | tail -n1)
24 fi
25
26 ssh bow DISPLAY=:0 scrot -z $f 2>/dev/null || exit 0
27 rsync --inplace bow:$f $dest_dir 2>/dev/null || exit 0
28 ssh bow rm -f $f
29
30 same=false
31 if [[ $lastf ]]; then
32 # returns 2 on error, but maybe in that case we want to ignore, file the image away
33 # and then it can go away in a subsequent comparison. going with that for now.
34 diff=$(compare -metric MSE $lastf ziva-tmp.jpg /dev/null |& sed 's/[^0-9].*//') ||:
35 if printf "%s\n" "$diff" | grep -E '^[0-9]+$' &>/dev/null && (( diff < 200 )); then
36 same=true
37 fi
38 fi
39
40 if $same; then
41 rm -f ziva-tmp.jpg
42 else
43 mv ziva-tmp.jpg "$(date +%F.%R)".jpg
44 fi