mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
added function for JSON parsing using JXA
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,8 @@ firefox_da)
|
||||
name="Firefox"
|
||||
type="dmg"
|
||||
downloadURL="https://download.mozilla.org/?product=firefox-latest&os=osx&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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 )
|
||||
;;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 )
|
||||
;;
|
||||
|
||||
@@ -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 )
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user