Git for Windows 1.9.5-preview20141217
[msysgit.git] / bin / show-github-usage.sh
blob78892caccefb40c660f01e2985dfe498b89332a1
1 #!/bin/sh
3 USAGE="$0"' <options>...
5 Get the amount of kB used by the msysGit organization
7 Options:
8 --user <github-account> (required)
11 user=
12 repository=
13 while test $# -gt 0
15 case "$1" in
16 --user)
17 test $# -gt 1 || {
18 echo "Option '$1' needs a value" >&2
19 exit 1
21 eval ${1#--}="$2"
22 shift
24 --user=*)
25 pair="${1#--}"
26 eval ${pair%%=*}="${pair#*=}"
28 --help)
29 echo "$USAGE"
30 exit 1
33 break;
34 esac
35 shift
36 done
38 test -z "$user" &&
39 user="$(grep -A2 -i '^machine *api.github.com' < "$HOME/.netrc" 2> /dev/null |
40 sed -n 's|login *||pi')"
42 test -n "$user" || {
43 echo "$USAGE"
44 exit 1
47 get_password () { # args: user host
48 # try $HOME/.netrc; ignore <user> parameter first
49 password="$(grep -A2 -i "^machine *$2" < $HOME/.netrc 2> /dev/null |
50 sed -n 's|^password *||p')"
51 test -z "$password" &&
52 password="$(git gui--askpass "Password for $1@$2")"
53 echo "$password"
56 json_get () { # args: key json
57 echo "$2" |
58 sed -n -s \
59 -e "s|^ *\"$1\" *: *\"\(.*\)\",\?$|\1|p" \
60 -e "s|^ *\"$1\" *: *\([^\"]*[^\",]\),\?$|\1|p"
63 password="$(get_password "$user" "api.github.com")"
64 test -n "$password" || exit
66 # get disk usage
67 json="$(curl -s \
68 -XPATCH \
69 -i \
70 -d '{}' \
71 -u "$user:$password" \
72 https://api.github.com/orgs/msysgit)"
74 echo "Disk usage: $(json_get disk_usage "$json")kB"