Update buildLabel.sh

Different set of headers.
This commit is contained in:
Søren Theilgaard
2022-01-07 19:40:51 +01:00
parent 21cee3a1ba
commit c3ddd4f8c7

View File

@@ -82,6 +82,36 @@ pkgInvestigation() {
echo "$packageID" echo "$packageID"
echo "Above is the possible packageIDs that can be used, and the correct one is probably one of those with a version number. More investigation might be needed to figure out correct packageID if several are displayed." echo "Above is the possible packageIDs that can be used, and the correct one is probably one of those with a version number. More investigation might be needed to figure out correct packageID if several are displayed."
} }
dmgInvestigation() {
echo "DMG investigation."
# mount the dmg
echo "Mounting $archiveName"
if ! dmgmount=$(echo "Y"$'\n' | hdiutil attach "$archiveName" -nobrowse -readonly | tail -n 1 | cut -c 54- ); then
echo "Error mounting $archiveName"
exit 3
fi
echo "Mounted: $dmgmount"
# check if app og pkg exists on disk image
appPath=$(find "$dmgmount" -name "*.app" -maxdepth 1 -print )
pkgPath=$(find "$dmgmount" -name "*.pkg" -maxdepth 1 -print )
if [[ $appPath != "" ]]; then
echo "App found: $appPath"
appInvestigation
elif [[ $pkgPath != "" ]]; then
echo "PKG found: $pkgPath"
archiveExt="pkgInDmg"
pkgInvestigation
else
echo "Nothing found on DMG."
exit 9
fi
hdiutil detach "$dmgmount"
}
appInvestigation() { appInvestigation() {
appName=${appPath##*/} appName=${appPath##*/}
name=${appName%.*} name=${appName%.*}
@@ -122,19 +152,22 @@ if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -
echo "result: $downloadOut" echo "result: $downloadOut"
echo "Trying all headers…" # that I know of echo "Trying all headers…" # that I know of
if ! downloadOut="$(curl -fL -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15" -H "accept-encoding: gzip, deflate, br" -H "Referrer Policy: strict-origin-when-cross-origin" -H "upgrade-insecure-requests: 1" -H "sec-fetch-dest: document" -H "sec-gpc: 1" -H "sec-fetch-user: ?1" -H "accept-language: en-US,en;q=0.9" -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" -H "sec-fetch-mode: navigate" "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then if ! downloadOut="$(curl -fL -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15" -H "accept-encoding: gzip, deflate, br" -H "Referrer Policy: strict-origin-when-cross-origin" -H "upgrade-insecure-requests: 1" -H "sec-fetch-dest: document" -H "sec-gpc: 1" -H "sec-fetch-user: ?1" -H "accept-language: en-US,en;q=0.9" -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" -H "sec-fetch-mode: navigate" "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then
# we are only here if the download failed echo "Trying almost all headers…" # that I know of
echo "error downloading $downloadURL using all headers." if ! downloadOut="$(curl -fL -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15" -H "accept-encoding: gzip, deflate, br" -H "upgrade-insecure-requests: 1" -H "sec-fetch-dest: document" -H "sec-gpc: 1" -H "sec-fetch-user: ?1" -H "accept-language: en-US,en;q=0.9" -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" -H "sec-fetch-mode: navigate" "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then
echo "result: $downloadOut" # we are only here if the download failed
# Sometimes a server will give some results to the downloaded output echo "error downloading $downloadURL using two different sets of headers."
if [[ -n $downloadOut ]]; then echo "result: $downloadOut"
echo "Trying output of this…" # Sometimes a server will give some results to the downloaded output
downloadURL="$(echo $downloadOut | tail -1)" if [[ -n $downloadOut ]]; then
# Last chance for succes on this download echo "Trying output of this…"
if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then downloadURL="$(echo $downloadOut | tail -1)"
echo "error downloading $downloadURL using previous output." # Last chance for succes on this download
echo "result: $downloadOut" if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then
echo "No more tries. Cannot continue." echo "error downloading $downloadURL using previous output."
exit 1 echo "result: $downloadOut"
echo "No more tries. Cannot continue."
exit 1
fi
fi fi
fi fi
fi fi
@@ -171,10 +204,6 @@ echo "name: $name"
archiveExt=${archiveName##*.} archiveExt=${archiveName##*.}
type=$archiveExt type=$archiveExt
echo "archiveExt: $archiveExt" echo "archiveExt: $archiveExt"
identifier=${name:l} # making lower case
identifier=${identifier//\%[0-9a-fA-F][0-9a-fA-F]} # removing certain characters
identifier=${identifier//[,._*@$\(\)\-]} # removing more characters from label name
echo "identifier: $identifier"
# Now figuring out the filename extension and handling those situations # Now figuring out the filename extension and handling those situations
if [ "$archiveExt" = "pkg" ]; then if [ "$archiveExt" = "pkg" ]; then
@@ -183,31 +212,7 @@ if [ "$archiveExt" = "pkg" ]; then
pkgInvestigation pkgInvestigation
elif [ "$archiveExt" = "dmg" ]; then elif [ "$archiveExt" = "dmg" ]; then
echo "Diskimage found" echo "Diskimage found"
# mount the dmg dmgInvestigation
echo "Mounting $archiveName"
if ! dmgmount=$(echo "Y"$'\n' | hdiutil attach "$archiveName" -nobrowse -readonly | tail -n 1 | cut -c 54- ); then
echo "Error mounting $archiveName"
exit 3
fi
echo "Mounted: $dmgmount"
# check if app og pkg exists on disk image
appPath=$(find "$dmgmount" -name "*.app" -maxdepth 1 -print )
pkgPath=$(find "$dmgmount" -name "*.pkg" -maxdepth 1 -print )
if [[ $appPath != "" ]]; then
echo "App found: $appPath"
appInvestigation
elif [[ $pkgPath != "" ]]; then
echo "PKG found: $pkgPath"
archiveExt="pkgInDmg"
pkgInvestigation
else
echo "Nothing found on DMG."
exit 9
fi
hdiutil detach "$dmgmount"
elif [ "$archiveExt" = "zip" ] || [ "$archiveExt" = "tbz" ]; then elif [ "$archiveExt" = "zip" ] || [ "$archiveExt" = "tbz" ]; then
echo "Compressed file found" echo "Compressed file found"
# unzip the archive # unzip the archive
@@ -216,6 +221,7 @@ elif [ "$archiveExt" = "zip" ] || [ "$archiveExt" = "tbz" ]; then
# check if app og pkg exists after expanding # check if app og pkg exists after expanding
appPath=$(find "$tmpDir" -name "*.app" -maxdepth 2 -print ) appPath=$(find "$tmpDir" -name "*.app" -maxdepth 2 -print )
pkgPath=$(find "$tmpDir" -name "*.pkg" -maxdepth 2 -print ) pkgPath=$(find "$tmpDir" -name "*.pkg" -maxdepth 2 -print )
archiveName=$(find "$tmpDir" -name "*.dmg" -maxdepth 2 -print )
if [[ $appPath != "" ]]; then if [[ $appPath != "" ]]; then
echo "App found: $appPath" echo "App found: $appPath"
@@ -223,14 +229,24 @@ elif [ "$archiveExt" = "zip" ] || [ "$archiveExt" = "tbz" ]; then
elif [[ $pkgPath != "" ]]; then elif [[ $pkgPath != "" ]]; then
echo "PKG found: $pkgPath" echo "PKG found: $pkgPath"
archiveExt="pkgInZip" archiveExt="pkgInZip"
echo "archiveExt: $archiveExt"
pkgInvestigation pkgInvestigation
elif [[ $archiveName != "" ]]; then
echo "Disk image found: $archiveName"
archiveExt="dmgInZip"
echo "archiveExt: $archiveExt"
dmgInvestigation
else else
echo "Nothing found in compressed archive." echo "Nothing found in compressed archive."
exit 9 exit 9
fi fi
fi fi
identifier=${name:l} # making lower case
identifier=${identifier//\%[0-9a-fA-F][0-9a-fA-F]} # removing certain characters
identifier=${identifier//[,._*@$\(\)\-]} # removing more characters from label name
echo "identifier: $identifier"
# github-part to figure out if we can find author and repo, to use our github functions for the label # github-part to figure out if we can find author and repo, to use our github functions for the label
if echo "$downloadURL" | grep -i "github.com.*releases/download"; then if echo "$downloadURL" | grep -i "github.com.*releases/download"; then
echo "\n**********\n\nFound GitHub path" echo "\n**********\n\nFound GitHub path"