2

Looking for a simple way to download a .zip from a latest GitHub release. There are other similar questions, but I havent been able to get them to work. :(

Trying to pull latest release from https://github.com/CTCaer/hekate

Currently ive got:

#!/bin/bash
curl -s https://api.github.com/repos/CTCaer/hekate/releases/latest | jq -r ".assets[] | select(.name | test(\"hekate_ctcaer\")) | .browser_download_url"

trying to fetch the url of the latest .zip and only grab the "hekate_ctcaer_X.X.X_Nyx_X.X.X.zip"

I saw someone trying to achieve this with 'Xidel', so im open to trying that if someone knows the syntax to grab a specific file from the GitHub api.

As I understand it (?), the Github API spits out an array for the release 'assets', so im trying to specify an item in this array that matches "hekate_ctcaer", and download the specified file.

Fraxalotl
  • 21
  • 2

4 Answers4

1

This will print out the url to the zip file of the latest release:

curl -sL https://api.github.com/repos/CTCaer/hekate/tags \
  | jq -r '.[0].zipball_url' \
  | xargs -I {} curl -sL {} -o latest.zip
ericfossas
  • 1,511
  • 8
  • 12
  • 1
    Thanks! I'll try this out and see if it works, would there be anything I should watch for implementing this across different OS's? – Fraxalotl Jul 16 '22 at 18:11
  • 1
    also how would I modify this for the following: https://github.com/Atmosphere-NX/Atmosphere/releases/tag/1.3.2 the .zip AND the .bin – Fraxalotl Jul 16 '22 at 18:14
  • 1
    Also is there a neat way to rename the downloaded file within the same command, or just do it as a separate command after? – Fraxalotl Jul 16 '22 at 18:17
  • 1
    different OS's - no, i don't thinks so (i tried this on Mac and Debian and it worked). "-o latest.zip" - this part names the file, so change it to whatever you need. please accept the answer and ask your 2nd comment in a new question and i'll help you there. – ericfossas Jul 16 '22 at 20:10
1

Github is also a compatible git repo. I provide a new train of thought.

  • use git ls-remote to fetch last release tag.
git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' http://github.com/CTCaer/hekate.git
| tail --lines=1
| cut --delimiter='/' --fields=3

Here this examples outputs v5.8.0

  • then clone remote repo
git clone --branch v5.8.0 http://github.com/CTCaer/hekate.git
  • zip repos to zipped file.
zip hekate.zip -r hekate/
mariolu
  • 624
  • 8
  • 17
  • 1
    this may work, but I'd like to avoid git, as its less likely that majority of users would have git installed, whereas curl is more ubiquitous and jq seems quite a light download that I can include. This is also to go in almost an automation script, so it seems the other solution is more concise – Fraxalotl Jul 16 '22 at 18:11
1

I saw someone trying to achieve this with 'Xidel'

I assume you're referring to my answer here. That answer is tagged , so you first of all have to swop the quotes for ("function('string')" --> 'function("string")'). And secondly, you're right. You have to select the appropriate object in the "assets"-array.

$ xidel -s "https://api.github.com/repos/CTCaer/hekate/releases/latest" \
  -f '$json/(assets)()[starts-with(name,"hekate_ctcaer")]/browser_download_url' \
  --download '{substring-after($headers[starts-with(.,"Content-Disposition")],"filename=")}'

This downloads 'hekate_ctcaer_5.8.0_Nyx_1.3.0.zip' in the current dir.
With r8389 or newer you can just use --download ..

also how would I modify this for the following: github.com/Atmosphere-NX/Atmosphere/releases/tag/1.3.2 the .zip AND the .bin

Strictly speaking you'd have to raise a new question for this, but ok.

It appears that (at the moment) v1.3.2 is also the latest release for this repo, so you can use...

$ xidel -s "https://api.github.com/repos/Atmosphere-NX/Atmosphere/releases/latest" \
  -e '$json'

or alternatively...

$ xidel -s "https://api.github.com/repos/Atmosphere-NX/Atmosphere/releases" \
  -e '$json()[tag_name="1.3.2"]'

The "assets"-array here has just 2 objects; one with the zip-file and one with the bin-file, so just "follow" (--follow / -f) the 2 "browser_download_url"-keys to download:

$ xidel -s "https://api.github.com/repos/Atmosphere-NX/Atmosphere/releases" \
  -f '$json()[tag_name="1.3.2"]//browser_download_url' \
  --download .
Reino
  • 3,203
  • 1
  • 13
  • 21
0

Sorry to bump this topic, but here's my take on downloading file $file from the latest release of $repo by $owner

compatible with git-bash on windows (doesn't have rev...)

echo "fetching latest version"
latest_version=`
    curl https://github.com/$owner/$repo/releases/latest --verbose 2>&1 |
    grep Location |
    sed -e "s|.*/v||"`

echo "version: $latest_version"

# if the version number is in the file name, append it
# example:
# file=somefile-$latest_version.ext

link="https://github.com/$owner/$repo/releases/download/v$latest_version/$file"

echo "$link"

curl -o "destination/folder/$file" -L "$link"

gui3
  • 1,711
  • 14
  • 30