Merge pull request #529 from scriptingosx/jxa-json

added function for JSON parsing using JXA
This commit is contained in:
Armin Briegel
2022-06-17 15:56:30 +02:00
committed by GitHub
8 changed files with 25 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
printlog "$2" $3
fi
printlog "################## End Installomator, exit code $1 \n" REQ
# if label is wrong and we wanted name of the label, then return ##################
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
1=0 # If only label name should be returned we exit without any errors
@@ -199,6 +199,16 @@ xpath() {
fi
}
# from @Pico: https://macadmins.slack.com/archives/CGXNNJXJ9/p1652222365989229?thread_ts=1651786411.413349&cid=CGXNNJXJ9
getJSONValue() {
# $1: JSON string OR file path to parse (tested to work with up to 1GB string and 2GB file).
# $2: JSON key path to look up (using dot or bracket notation).
printf '%s' "$1" | /usr/bin/osascript -l 'JavaScript' \
-e "let json = $.NSString.alloc.initWithDataEncoding($.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile$(/usr/bin/uname -r | /usr/bin/awk -F '.' '($1 > 18) { print "AndReturnError(ObjC.wrap())" }'), $.NSUTF8StringEncoding)" \
-e 'if ($.NSFileManager.defaultManager.fileExistsAtPath(json)) json = $.NSString.stringWithContentsOfFileEncodingError(json, $.NSUTF8StringEncoding, ObjC.wrap())' \
-e "const value = JSON.parse(json.js)$([ -n "${2%%[.[]*}" ] && echo '.')$2" \
-e 'if (typeof value === "object") { JSON.stringify(value, null, 4) } else { value }'
}
getAppVersion() {
# modified by: Søren Theilgaard (@theilgaard) and Isaac Ordonez

View File

@@ -2,7 +2,8 @@ firefox)
name="Firefox"
type="dmg"
downloadURL="https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US"
appNewVersion=$(curl -fs https://www.mozilla.org/en-US/firefox/releases/ | grep '<html' | grep -o -i -e "data-latest-firefox=\"[0-9.]*\"" | cut -d '"' -f2)
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
printlog "WARNING for ERROR: Label firefox and firefox_intl should not be used. Instead use firefoxpkg and firefoxpkg_intl as per recommendations from Firefox. It's not fully certain that the app actually gets updated here. firefoxpkg and firefoxpkg_intl will have built in updates and make sure the client is updated in the future." REQ

View File

@@ -2,7 +2,8 @@ firefox_da)
name="Firefox"
type="dmg"
downloadURL="https://download.mozilla.org/?product=firefox-latest&amp;os=osx&amp;lang=da"
appNewVersion=$(curl -fs https://www.mozilla.org/en-US/firefox/releases/ | grep '<html' | grep -o -i -e "data-latest-firefox=\"[0-9.]*\"" | cut -d '"' -f2)
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
printlog "WARNING for ERROR: Label firefox, firefox_da and firefox_intl should not be used. Instead use firefoxpkg and firefoxpkg_intl as per recommendations from Firefox. It's not fully certain that the app actually gets updated here. firefoxpkg and firefoxpkg_intl will have built in updates and make sure the client is updated in the future." REQ

View File

@@ -19,7 +19,8 @@ firefox_intl)
printlog "Download not found for '$userLanguage', using default ('en-US')."
downloadURL="https://download.mozilla.org/?product=firefox-latest-ssl&os=osx"
fi
appNewVersion=$(curl -fsIL $downloadURL | awk -F releases/ '/Location:/ {split($2,a,"/"); print a[1]}')
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
printlog "WARNING for ERROR: Label firefox and firefox_intl should not be used. Instead use firefoxpkg and firefoxpkg_intl as per recommendations from Firefox. It's not fully certain that the app actually gets updated here. firefoxpkg and firefoxpkg_intl will have built in updates and make sure the client is updated in the future." REQ

View File

@@ -3,7 +3,8 @@ firefoxesrpkg)
name="Firefox"
type="pkg"
downloadURL="https://download.mozilla.org/?product=firefox-esr-pkg-latest-ssl&os=osx"
appNewVersion=$(curl -fsIL "$downloadURL" | grep -i "^location" | awk '{print $2}' | sed -E 's/.*releases\/([0-9.]*)esr.*/\1/g')
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "FIREFOX_ESR")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
;;

View File

@@ -19,7 +19,8 @@ firefoxesr_intl)
printlog "Download not found for '$userLanguage', using default ('en-US')."
downloadURL="https://download.mozilla.org/?product=firefox-esr-latest-ssl&os=osx"
fi
appNewVersion=$(curl -fsIL $downloadURL | awk -F releases/ '/Location:/ {split($2,a,"esr/"); print a[1]}')
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
printlog "WARNING for ERROR: Label firefox and firefox_intl should not be used. Instead use firefoxpkg and firefoxpkg_intl as per recommendations from Firefox. It's not fully certain that the app actually gets updated here. firefoxpkg and firefoxpkg_intl will have built in updates and make sure the client is updated in the future." REQ

View File

@@ -2,7 +2,8 @@ firefoxpkg)
name="Firefox"
type="pkg"
downloadURL="https://download.mozilla.org/?product=firefox-pkg-latest-ssl&os=osx&lang=en-US"
appNewVersion=$(curl -fs https://www.mozilla.org/en-US/firefox/releases/ | grep '<html' | grep -o -i -e "data-latest-firefox=\"[0-9.]*\"" | cut -d '"' -f2)
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
;;

View File

@@ -18,7 +18,8 @@ firefoxpkg_intl)
printlog "Download not found for that language. Using en-US" WARN
downloadURL="https://download.mozilla.org/?product=firefox-pkg-latest-ssl&os=osx&lang=en-US"
fi
appNewVersion=$(curl -fsIL "$downloadURL" | grep -i location | cut -d "/" -f7)
firefoxVersions=$(curl -fs "https://product-details.mozilla.org/1.0/firefox_versions.json")
appNewVersion=$(getJSONValue "$firefoxVersions" "LATEST_FIREFOX_VERSION")
expectedTeamID="43AQ936H96"
blockingProcesses=( firefox )
;;