Last active
May 15, 2024 22:28
-
-
Save chapagainmanoj/23bf05d1b662a066536583951ed1b181 to your computer and use it in GitHub Desktop.
Gist to download latest git release asset
This file contains 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 | |
# This script downloads the first asset from the latest Github release of a | |
# private repo. | |
# | |
# PREREQUISITES | |
# | |
# curl, jq | |
# | |
# USAGE | |
# | |
# Set owner and repo variables inside the script, make sure you chmod +x it. | |
# | |
# ./download.sh <--GITHUB TOKEN HERE--> <Owner> <Repo> | |
# | |
# Define variables | |
echo "---------------------------------------------------------------------" | |
echo "Define variables" | |
echo "---------------------------------------------------------------------" | |
GITHUB_API_TOKEN=$1 | |
owner=$2 | |
repo=$3 | |
GH_API="https://api.github.com" | |
GH_REPO="$GH_API/repos/$owner/$repo" | |
GH_LATEST="$GH_REPO/releases/latest" | |
AUTH="Authorization: token $GITHUB_API_TOKEN" | |
# Read asset name and id | |
echo "---------------------------------------------------------------------" | |
echo "Read asset name and id" | |
echo "---------------------------------------------------------------------" | |
response=$(curl -sH "$AUTH" $GH_LATEST) | |
id=`echo "$response" | jq '.assets[0] .id' | tr -d '"'` | |
name=`echo "$response" | jq '.assets[0] .name' | tr -d '"'` | |
GH_ASSET="$GH_REPO/releases/assets/$id" | |
# Print Details | |
echo "---------------------------------------------------------------------" | |
echo "Print Details" | |
echo "Assets Id: $id" | |
echo "Name: $name" | |
echo "Assets URL: $GH_ASSET" | |
echo "---------------------------------------------------------------------" | |
# Downloading asset file | |
echo "---------------------------------------------------------------------" | |
echo "Downloading asset file" | |
echo "---------------------------------------------------------------------" | |
curl -v -L -o "$name" -H "$AUTH" -H 'Accept: application/octet-stream' "$GH_ASSET" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment