3 # Written with a lot of assistance by Scott Chacon
5 USAGE
="$0"' <options>... <filepath>
7 --description <download-description> (required)
8 --user <github-account> (required)
9 --repository <github-repository> (required)
22 --description|
--user|
--repository)
24 echo "Option '$1' needs a value" >&2
30 --description=*|
--user=*|
--repository=*)
32 eval ${pair%%=*}="${pair#*=}"
35 dryrun
=YouGotThatRight
47 if test $# -ne 1 ||
! test -f "$1"
54 filesize
="$(stat -c %s "$filepath")"
55 basename="$(basename "$filepath")"
57 # extract 'for version <version>' from basename
58 for_version
=${basename%-preview*}
59 for_version
=${for_version##*Git-}
60 for_version
=${for_version##*install-}
61 for_version
="for official Git for Windows $for_version"
65 description
="${description:-Full installer $for_version}"
66 repository
=${repository:-msysgit/git}
69 description
="${description:-Portable application $for_version}"
70 repository
=${repository:-msysgit/git}
73 description
="${description:-Net installer if you want to hack on Git}"
74 repository
=${repository:-msysgit/git}
76 msysGit-fullinstall-
*)
77 description
="${description:-Full installer (self-contained) if you want to hack on Git}"
78 repository
=${repository:-msysgit/git}
83 user
="$(grep -A2 -i '^machine *api.github.com' < "$HOME/.netrc
" 2> /dev/null |
84 sed -n 's|login *||pi')"
86 if test -z "$description" ||
test -z "$user" ||
test -z "$repository"
92 get_password
() { # args: user host
93 # try $HOME/.netrc; ignore <user> parameter first
94 password
="$(grep -A2 -i "^machine
*$2" < $HOME/.netrc 2> /dev/null |
95 sed -n 's|^password *||p')"
96 test -z "$password" &&
97 password
="$(git gui--askpass "Password
for $1@
$2")"
101 json_get
() { # args: key json
103 sed -n -s "s|^ *\"$1\" *: *\"\(.*\)\",\?$|\1|p"
106 json_wrap
() { # args: key1, value1, [key2, value2], ...
111 printf '%s"%s":"%s"' "$sep" "$1" "$2"
119 windowsfilepath
="$(cd "$
(dirname "$filepath")" && pwd -W)\\$basename"
121 test -n "$dryrun" && {
125 description: $description
127 repository: $repository
132 password
="$(get_password "$user" "api.github.com
")"
133 test -n "$password" ||
exit
136 json
="$(curl -XPOST \
140 description
"$description")" \
141 -u "$user:$password" \
142 https://api.github.com/repos/$repository/downloads)"
144 # upload for real, using S3
146 -F key="$
(json_get path
"$json")" \
147 -F acl="$
(json_get acl
"$json")" \
148 -F success_action_status=201 \
149 -F Filename="$
(json_get name
"$json")" \
150 -F AWSAccessKeyId="$
(json_get accesskeyid
"$json")" \
151 -F Policy="$
(json_get policy
"$json")" \
152 -F Signature="$
(json_get signature
"$json")" \
153 -F Content-Type="$
(json_get mime_type
"$json")" \
154 -F file=@"$windowsfilepath" \
155 "$
(json_get s3_url
"$json")")"
159 # Verify that the upload was successful
161 *"<Location>"*"</Location>"*)