diff options
Diffstat (limited to 'upload-asset')
-rwxr-xr-x | upload-asset | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/upload-asset b/upload-asset new file mode 100755 index 0000000..607c5fd --- /dev/null +++ b/upload-asset @@ -0,0 +1,51 @@ +#!/bin/sh + +base_dir=$( + dirname "$( + readlink -f "$0" + )" +) + +api_url='https://api.github.com' +auth='Authorization: token '"$( + gpg -d -o - "${base_dir}/pw.gpg" 2>/dev/null +)" + +owner='archlinux32' +repo='archlinux32-keyring' +tag='v20180411' +file='test.asc' +name='test.asc' + +repo_url="${api_url}/repos/${owner}/${repo}" +tags_url="${repo_url}/releases/tags/${tag}" + +response=$( + curl -sH "${auth}" "${repo_url}" +) + +if echo "${response}" | \ + grep -qF '"Bad credentials"'; then + >&2 echo "${response}" + exit 1 +fi + +eval $( + curl -sH "${auth}" "${tags_url}" | \ + grep -m1 '"id":' | \ + tr : = | \ + tr -cd '[[:alnum:]]=' +) + +if [ -z "${id}" ]; then + >&2 printf 'Error: Failed to get release id for tag %s.\n' "${tag}" + >&2 printf '%s\n' "${response}" + exit 1 +fi + +upload_url="https://uploads.github.com/repos/${owner}/${repo}/releases/${id}/assets?name=${name}" +curl \ + --data-binary @"${file}" \ + -H "${auth}" \ + -H "Content-Type: application/octet-stream" \ + "${upload_url}" |