#!/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}"