forked from msysgit/msysgit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow-github-usage.sh
executable file
·74 lines (63 loc) · 1.29 KB
/
show-github-usage.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
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
#!/bin/sh
USAGE="$0"' <options>...
Get the amount of kB used by the msysGit organization
Options:
--user <github-account> (required)
'
user=
repository=
while test $# -gt 0
do
case "$1" in
--user)
test $# -gt 1 || {
echo "Option '$1' needs a value" >&2
exit 1
}
eval ${1#--}="$2"
shift
;;
--user=*)
pair="${1#--}"
eval ${pair%%=*}="${pair#*=}"
;;
--help)
echo "$USAGE"
exit 1
;;
*)
break;
esac
shift
done
test -z "$user" &&
user="$(grep -A2 -i '^machine *api.github.com' < "$HOME/.netrc" 2> /dev/null |
sed -n 's|login *||pi')"
test -n "$user" || {
echo "$USAGE"
exit 1
}
get_password () { # args: user host
# try $HOME/.netrc; ignore <user> parameter first
password="$(grep -A2 -i "^machine *$2" < $HOME/.netrc 2> /dev/null |
sed -n 's|^password *||p')"
test -z "$password" &&
password="$(git gui--askpass "Password for $1@$2")"
echo "$password"
}
json_get () { # args: key json
echo "$2" |
sed -n -s \
-e "s|^ *\"$1\" *: *\"\(.*\)\",\?$|\1|p" \
-e "s|^ *\"$1\" *: *\([^\"]*[^\",]\),\?$|\1|p"
}
password="$(get_password "$user" "api.github.com")"
test -n "$password" || exit
# get disk usage
json="$(curl -s \
-XPATCH \
-i \
-d '{}' \
-u "$user:$password" \
https://api.github.com/orgs/msysgit)"
echo "Disk usage: $(json_get disk_usage "$json")kB"