From 1412f86e69877fd668471616d26abce11769e193 Mon Sep 17 00:00:00 2001 From: Theile Date: Wed, 14 Sep 2022 15:45:00 +0200 Subject: [PATCH] If GItHub does not give an URL we can fall back on API call Today something strange happened for Installomator on GitHub. Or latest release would spend too much time loading the assets, and would not return an URL, like here: ``` % gitusername="Installomator"; gitreponame="Installomator"; curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.pkg" | head -1 % gitusername="bartreardon"; gitreponame="swiftDialog"; curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.pkg" | head -1 /bartreardon/swiftDialog/releases/download/v1.11.2/dialog-1.11.2-3095.pkg ``` As can be seen above it worked for swiftDialog, but not for Installomator. Now we can fall back on the API call if we do not get the URL in first try. --- fragments/functions.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index 0da3726..cec20b2 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -162,11 +162,17 @@ downloadURLFromGit() { # $1 git user name, $2 git repo name fi if [ -n "$archiveName" ]; then - #downloadURL=$(curl -L --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }") downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) + if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }") + fi else - #downloadURL=$(curl -L --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) + if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") + fi fi if [ -z "$downloadURL" ]; then cleanupAndExit 14 "could not retrieve download URL for $gitusername/$gitreponame" ERROR