-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaa
More file actions
executable file
·76 lines (62 loc) · 1.6 KB
/
aa
File metadata and controls
executable file
·76 lines (62 loc) · 1.6 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Scripts to work with AAISP APIs.
## Get the set variables
. ./aavars
## Returns all of its arguments except the first.
## This is useful for writing subcommands.
rest() {
echo "${@:2}"
}
showhelp() {
echo "$0: Usage:"
echo " $0 sms - SMS api"
echo " $0 broadband - broadband lookups"
echo " $0 voip - VoIP lookups"
echo " $0 bill - billing"
}
sms() {
echo "Not implemented yet, sorry"
}
broadband() {
case $1 in
"quota"|q)
broadband_quota $(rest $@)
;;
*)
broadband_help
;;
esac
}
broadband_help() {
echo "$0 broadband: Usage:"
echo " $0 broadband quota: show remaining quota on line"
}
broadband_quota() {
## Find the monthly quota remaining on a broadband line.
## Find days left in current month, which is approximately
## presumed to be the quota reset cycle. This is true for
## my case, so maybe others. Dangerous words.
MONTH=`date +%m`
YEAR=`date +%Y`
DAYSINMONTH=`cal $MONTH $YEAR | egrep -v '[A-Za-z]' | wc -w`
CURRENTDAY=`date +%d`
## Quota in kB from AAISP API call
QUOTA_REMAINING="$(http https://chaos2.aa.net.uk/broadband/quota "control_login==$CONTROL_LOGIN" "control_password==$CONTROL_PASS" | jq --raw-output '.quota[0].quota_remaining')"
## Calculate quota in meaningful units
let "QUOTA_REMAINING_GB = $QUOTA_REMAINING / (1000*1000*1000)"
let "DAYS_REMAINING = $DAYSINMONTH - $CURRENTDAY"
let "PERDAY = $QUOTA_REMAINING_GB / DAYS_REMAINING"
## Report the results
echo $QUOTA_REMAINING_GB GB for $DAYS_REMAINING days -- $PERDAY GB per day.
}
case $1 in
"sms")
sms $(rest $@)
;;
"bb")
broadband $(rest $@)
;;
*)
showhelp
;;
esac