summary refs log tree commit diff
path: root/bin/desk
blob: fab05b72c331de860dbb9cb6ee0663e3beaaf7f7 (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
#!/bin/sh

[ -n "$DEBUG" ] && set -x

export DESK="DA:02:BE:81:EB:77"

error() {
	notify-send -i /usr/share/icons/mdi/scalable/desk.svg -u critical "desk $1" "${2}"
}

pos=
case "$1" in
	sit | down) pos=780 ;;
	stand | up) pos=1150 ;;
	*) error "$1" "no position given" ;;
esac

printf "ensure bluetoothd is started...\n"
{ rc-service bluetooth status || doas rc-service bluetooth start; } >/dev/null

trap '{ exit 3; }' INT
retries=
while true; do
	printf "running bluedesk...\n"
	err=$(bluedesk "${pos}" 2>&1 1>/dev/stdout)
	# shellcheck disable=SC2181
	if [ $? -ne 0 ]; then
		error "$1" "${err}"
		sleep 1
		retries=$((retries + 1))
		if [ "${#retries}" -gt 2 ]; then
			error "$1" "giving up"
			exit 1
		fi
	else
		exit 0
	fi
done