30 lines
610 B
Bash
30 lines
610 B
Bash
#!/bin/bash
|
|
|
|
export GITHUB_REPOS=https://api.github.com/repos
|
|
|
|
github_latest() {
|
|
local endpoint=$GITHUB_REPOS/$1/$2/releases/latest
|
|
local auth; local res
|
|
[[ $GITHUB_TOKEN ]] && auth="-u $GITHUB_USER:$GITHUB_TOKEN"
|
|
if ! res=$(curl $auth -s $endpoint); then
|
|
return 1
|
|
fi
|
|
echo $res| jq .name -r
|
|
}
|
|
|
|
github_asset () {
|
|
# user repo version asset
|
|
|
|
asset_url=$(curl -s "$GITHUB_REPOS/$1/$2/releases/tags/v$3" \
|
|
| jq --arg aname "$4" -r '.assets[] | select(.name == $aname).browser_download_url' \
|
|
| head -1)
|
|
|
|
if [ -z "${asset_url}" ]; then
|
|
return 1
|
|
fi
|
|
|
|
echo $asset_url
|
|
|
|
}
|
|
|