Created
January 16, 2018 06:12
-
-
Save thesues/127741672ec8c8dfc5fe816937b769f6 to your computer and use it in GitHub Desktop.
Download latest release from github
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
account="thesues" | |
token=$1 | |
download_asset() | |
{ | |
user=$1 | |
repo=$2 | |
json=$3 | |
filelist=$4 | |
ids=`echo $json | jq '.assets[]' | jq "[.id][]"` | |
for id in $ids; do | |
name=`echo $json | jq '.assets[]' | jq "[.id, .name][]" | grep $id -A1 | tail -n1 | sed "s/\"//g"` | |
if [ "$filelist" != "" ]; then | |
for want in $filelist; do | |
echo "${name##*/}" | grep "^$want\-[0-9].*$" > /dev/null | |
ret=$? | |
if [ "$ret" = "0" ]; then | |
echo "downloading $name" | |
curl -o $name -L -H "Accept: application/octet-stream" -u $account:$token https://api.github.com/repos/$user/$repo/releases/assets/$id | |
break | |
else | |
continue | |
fi | |
done | |
else | |
echo "downloading $name" | |
curl -o $name -L -H "Accept: application/octet-stream" -u $account:$token https://api.github.com/repos/$user/$repo/releases/assets/$id | |
fi | |
done | |
} | |
download_rpms() | |
{ | |
user=$1 | |
repo=$2 | |
type=$3 | |
filelist=$4 | |
json=`curl -u $account:$token -s https://api.github.com/repos/$user/$repo/releases/latest` | |
download_asset $user $repo "$json" "$filelist" | |
} | |
download_all_tars() | |
{ | |
user=$1 | |
repo=$2 | |
url=`curl -u $account:$token -s https://api.github.com/repos/$user/$repo/releases/latest | grep "tarball_url" | cut -d \" -f 4` | |
echo $url | |
curl -o ${repo}_${url##*/}.tar.gz -u $account:$token -L $url | |
} | |
if [ "$token" = "" ]; then | |
echo "github api token mission, exit" | |
exit 127 | |
fi | |
download_rpms journeymidnight nier rpm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment