From 6c9bf4d7bbce6e4e11e68e4e528d10fc8a1fa743 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 3 May 2018 10:21:27 +0200 Subject: Initial commit --- .gitignore | 1 + upload-asset | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100755 upload-asset diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6685f28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pw.gpg 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}" -- cgit v1.2.3-70-g09d2