grahampugh / erase-install

A script that automates downloading macOS installers, and optionally erasing or upgrading macOS in a single process. Watch the video!
https://grahamrpugh.com/2023/05/14/macaduk-presentation-eraseinstall.html
Apache License 2.0
834 stars 131 forks source link

FR: Use tags to get the latest download URL from github #494

Closed bartreardon closed 3 months ago

bartreardon commented 6 months ago

Regarding this block of code:

https://github.com/grahampugh/erase-install/blob/515128ae88e166e4e5868bce52a06db646a2b713/erase-install.sh#L59-L67

It would be more robust to use the release tag to get the download url rather than expect the pkg name to be in a certain format. Then if I have a lapse in memory and use a different filename things won't break and you only need the tag to get whatever the download url is (or no tag to just get the latest)

The following will work to get either the latest release or a specific tag:

getDownloadURL() {
    url="https://api.github.com/repos/swiftDialog/swiftDialog/releases"
    header="Accept: application/json"
    tag=${1:-"$(curl -sL -H "${header}" ${url}/latest | awk -F '"' '/tag_name/ { print $4; exit }')"}

    curl -sL -H "${header}" ${url}/tags/${tag} | awk -F '"' '/browser_download_url/ { print $4; exit }'
}

# URL for downloading the latest swiftDialog release
dialog_download_url=$(getDownloadURL)
echo "download url for latest : ${dialog_download_url}"

# URL for downloading swiftDialog (with tag version)
# This ensures a compatible swiftDialog version is used if not using the package installer
swiftdialog_tag_required="v2.4.2"
dialog_download_url=$(getDownloadURL "${swiftdialog_tag_required}")
echo "download url for tag version : ${dialog_download_url}"

# URL for downloading swiftDialog on macOS 11 (with tag version)
# This ensures a compatible swiftDialog version is used if not using the package installer
swiftdialog_bigsur_tag_required="v2.2.1"
dialog_bigsur_download_url=$(getDownloadURL "${swiftdialog_bigsur_tag_required}")
echo "download url for big sur supported version: ${dialog_bigsur_download_url}"

Do note that unauthenticated access to the github api is limited to 60 requests per hour per client.

grahampugh commented 4 months ago

Many thanks for this @bartreardon , I've incorporated this into the pre-release of 34.0 (and the Makefile) - in the 34.0 branch.

bartreardon commented 4 months ago

sharing is caring 🙂