aboutsummaryrefslogtreecommitdiff
path: root/data/scripts/common.sh
blob: 0fbaa456d456a053215a320ef7f130a68791f2f6 (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
#!/bin/bash

SERVER_URL="https://frypan.jadupc.com" #"builder.jadupc.com"

if [[ $DEBUG ]]; then
	SERVER_URL="http://log-server.local"
fi

function getiface
{
	printf '%s\n' "/sys/class/$1"*/ | head -n1
}

function getaddr
{
	if [[ -d $1 ]]; then
		tr ':' '-' < "$1/address"
	else
		echo '00-00-00-00-00-00'
	fi
}

function communicate
{
	local endpoint type wlmac enmac year week day month
	endpoint="$1"
	type="$2"
	wlmac="$3"
	enmac="$4"
	year="$5"
	shift 5
	case "${type#*/}" in
		weekly)
			week="$1"
			shift 1
			set -- -d "week=$week" "$@"
			;;
		daily)
			month="$1"
			day="$2"
			shift 2
			set -- -d "month=$month" -d "day=$day" "$@"
			;;
	esac

	curl --disable -Ls \
		-d "type=${type%%/*}" -d "wlmac=$wlmac" \
		-d "enmac=$enmac" -d "year=$year" -d "user=$USER" "$@" \
		"$SERVER_URL$endpoint"
}