summaryrefslogtreecommitdiff
path: root/frontends/scripts/goprecords-upload.sh.tpl
blob: 4770f1e4e89dd1a509efeab8db13151929cf6ec5 (plain)
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
#!/bin/sh
set -e
HOST="<%= $goprecords_host %>"
BASE_URL="https://goprecords.f3s.buetow.org"
TOKEN="<%= $goprecords_token %>"
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH}"

upload() {
	kind=$1
	file=$2
	if [ ! -f "$file" ]; then
		echo "goprecords-upload: skip $kind (no $file)" >&2
		return 0
	fi
	curl -fsS -X PUT --data-binary "@${file}" \
		-H "Authorization: Bearer ${TOKEN}" \
		"${BASE_URL}/upload/${HOST}/${kind}"
}

records_path=/var/db/uptimed/records
if [ -f /var/spool/uptimed/records ]; then
	records_path=/var/spool/uptimed/records
fi

tmp=$(mktemp)
trap 'rm -f "$tmp"' 0 INT TERM HUP

upload records "$records_path"

if command -v uprecords >/dev/null 2>&1; then
	uprecords -a -m 100 >"$tmp"
	upload txt "$tmp"
	uprecords -a | grep '^->' >"$tmp" || true
	if [ -s "$tmp" ]; then
		upload cur.txt "$tmp"
	fi
fi

if [ -r /etc/os-release ]; then
	upload os.txt /etc/os-release
else
	uname -a >"$tmp"
	upload os.txt "$tmp"
fi

if [ -r /var/run/dmesg.boot ]; then
	upload cpuinfo.txt /var/run/dmesg.boot
else
	sysctl hw.model hw.ncpu hw.machine >"$tmp" 2>/dev/null || uname -a >"$tmp"
	upload cpuinfo.txt "$tmp"
fi