From 1412f86e69877fd668471616d26abce11769e193 Mon Sep 17 00:00:00 2001 From: Theile Date: Wed, 14 Sep 2022 15:45:00 +0200 Subject: [PATCH 1/4] 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 From e5d309a9d9ec8a000b920a2f4966f6b4b21b6df9 Mon Sep 17 00:00:00 2001 From: Theile Date: Wed, 14 Sep 2022 16:19:57 +0200 Subject: [PATCH 2/4] Minor correction to the `if` statement --- fragments/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index cec20b2..85a7902 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -163,7 +163,7 @@ downloadURLFromGit() { # $1 git user name, $2 git repo name if [ -n "$archiveName" ]; then 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 + if [[ "$(echo $downloadURL | grep -ioE "https.*$archiveName")" == "" ]]; 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 From 91af2427fa3535db2eb7ad5453eb3f3e533b54c5 Mon Sep 17 00:00:00 2001 From: Theile Date: Wed, 21 Sep 2022 11:58:56 +0200 Subject: [PATCH 3/4] Fix for #698 GitHub download links changed, fixed #698. --- fragments/functions.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index 85a7902..74045da 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -162,13 +162,15 @@ downloadURLFromGit() { # $1 git user name, $2 git repo name fi if [ -n "$archiveName" ]; then - downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) + #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) + downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1)" if [[ "$(echo $downloadURL | grep -ioE "https.*$archiveName")" == "" ]]; 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=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) + #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) + downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | 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 }") From e0222cfe4982f256eb394b064735ad46980c59e2 Mon Sep 17 00:00:00 2001 From: Theile Date: Thu, 29 Sep 2022 16:10:36 +0200 Subject: [PATCH 4/4] API call first, then fall back on home page url. --- fragments/functions.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index 74045da..812b297 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -162,18 +162,18 @@ downloadURLFromGit() { # $1 git user name, $2 git repo name fi if [ -n "$archiveName" ]; then - #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) - downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1)" + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }") if [[ "$(echo $downloadURL | grep -ioE "https.*$archiveName")" == "" ]]; 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 }") + printlog "GitHub API not returning URL, trying https://github.com/$gitusername/$gitreponame/releases/latest." + #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) + downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1)" fi else - #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) - downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") 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 }") + printlog "GitHub API not returning URL, trying https://github.com/$gitusername/$gitreponame/releases/latest." + #downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) + downloadURL="https://github.com$(curl -sfL "$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "expanded_assets" | head -1)" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" fi fi if [ -z "$downloadURL" ]; then