-
Notifications
You must be signed in to change notification settings - Fork 5
/
osb-stats.sh
executable file
·51 lines (42 loc) · 1.57 KB
/
osb-stats.sh
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
#!/bin/bash
# NEMS Linux Migrator Off-Site Backup Restore
# By Robbie Ferguson
# nemslinux.com | baldnerd.com | category5.tv
# Load Config
hwid=`/usr/local/bin/nems-info hwid`
osbpass=$(cat /usr/local/share/nems/nems.conf | grep osbpass | printf '%s' $(cut -n -d '=' -f 2))
osbkey=$(cat /usr/local/share/nems/nems.conf | grep osbkey | printf '%s' $(cut -n -d '=' -f 2))
timestamp=$(/bin/date +%s)
if [[ $osbpass == '' ]] || [[ $osbkey == '' ]]; then
echo NEMS Migrator Offsite Backup is not currently enabled.
exit
fi;
if [ $(dpkg-query -W -f='${Status}' jq 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo "JSON parser not yet installed. Installing."
apt-get update
apt-get install -y jq
fi
if [[ -f /tmp/osb.backup.nems ]]; then
rm /tmp/osb.backup.nems
fi
# Cron triggers this at 4:30am
# Sleep for a random time up to 2 hours to stagger user backups to relieve stress on the API server
if [[ $1 != 'now' ]]; then
delay=$[ ( $RANDOM % 7200 ) ]
echo "Waiting $delay seconds" >&2
sleep ${delay}s
echo "Running OSB" >&2
else
echo "Running OSB now" >&2
fi
# Load Account Data (output options are json, serial or blank = :: separated, one item per line
data=$(curl -s -F "hwid=$hwid" -F "osbkey=$osbkey" -F "output=json" https://nemslinux.com/api-backend/offsite-backup-checkin.php)
if jq -e . >/dev/null 2>&1 <<<"$data"; then # Parse reply to make sure it is JSON before clobbering
if [[ $data == '' ]]; then
echo "[]" > /var/log/nems/nems-osb.json
else
echo "$data" > /var/log/nems/nems-osb.json
fi
else
echo $data
fi