Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Download Artifacts from a Latest GitHub Release with Bash

October 31, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

Lately I’ve been working on an application for which the releases are published on GitHub, and I wanted to create an install script which always downloads the latest release.

It turned out that downloading the artifacts for a specific version is easy, we can simply build an URL with the version number to access the artifact. However, there is no direct URL to download artifacts from the latest release, so we need a bit of logic in our scripts to do that.

Bg2236

Link structure

We can access a particular release with a URL like https://github.com/user/<repo>/<releases>/tag/v1.x.x. (The part after tag/ is what we specified when we created the release.)

Bg2239
Note And there is this URL, which always takes us to the latest release of a project: https://github.com/user/repo/releases/latest.

Artifacts from this particular release can be downloaded with the URL https://github.com/<user>/<repo>/releases/download/v1.x.x/myArtifact.zip

Bg2240

Getting the latest version from GitHub

To achieve that goal, you will need curl or wget shipped with Linux, for this to work.

Take a look the link of zlib project https://github.com///releases/latest.

  • <user> = madler
  • <repo> = zlib
 curl -s https://api.github.com/repos/<user>/<repo>/releases/latest \
  | awk -F': ' '/browser_download_url/ && /\.<file extension>/ \
  {gsub(/"/, "", $(NF)); system("curl -LO " $(NF))}'
wget -q -nv -O - https://api.github.com/repos/<user>/<repo>/releases/latest \
  | awk -F': ' '/browser_download_url/ && /\.<file extension>/ \
  {gsub(/"/, "", $(NF)); system("wget -qi -L " $(NF))}'

Here is a quick explanation

  1. First, curl or wget obtains the response from an HTTP GET request. This response contains the URLs for the various artifacts for the latest release of the project.
  2. Next, awk processes the response, finding the line containing a download URL and matching the given file extension.
  3. It then removes the quotation marks surrounding the URL and downloads the file directly with curl or wget.

You need modify the match pattern for the file extension (.zip, .tar.gz, .tar.xz…) to make it more specific if need be. And replace user and repo the GitHub project that you need grab the installer from. 

The following example demonstrates this by fetching the latest Linux release tar.gz file of the zlib.

Download with curl:

curl -s https://api.github.com/repos/madler/zlib/releases/latest \
  | awk -F': ' '/browser_download_url/ && /\.tar.gz/ \
  {gsub(/"/, "", $(NF)); system("curl -LO " $(NF))}'
# curl -s https://api.github.com/repos/madler/zlib/releases/latest \
>   | awk -F': ' '/browser_download_url/ && /\.tar.gz/ \
>   {gsub(/"/, "", $(NF)); system("curl -LO " $(NF))}'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 1462k  100 1462k    0     0  1066k      0  0:00:01  0:00:01 --:--:-- 12.6M

# ll
-rw-r--r--. 1 root root 1497445 Oct 30 10:35 zlib-1.2.13.tar.gz

Download with wget:

wget -q -nv -O - https://api.github.com/repos/madler/zlib/releases/latest \
  | awk -F': ' '/browser_download_url/ && /\.tar.gz/ \
  {gsub(/"/, "", $(NF)); system("wget -qi -L " $(NF))}' 
# wget -q -nv -O - https://api.github.com/repos/madler/zlib/releases/latest \
>   | awk -F': ' '/browser_download_url/ && /\.tar.gz/ \
>   {gsub(/"/, "", $(NF)); system("wget -qi -L " $(NF))}'

# ll
-rw-r--r--. 1 root root 1497445 Oct 14 06:07 zlib-1.2.13.tar.gz
ADVERTISEMENT
5/5 - (1 vote)
Previous Post

How to Download the Latest Release from GitHub Repo in Linux

Next Post

Download Artifacts from a Latest GitHub Release with PowerShell

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory