mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
Merge pull request #529 from scriptingosx/jxa-json
added function for JSON parsing using JXA
This commit is contained in:
@@ -22,7 +22,7 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
|
|||||||
printlog "$2" $3
|
printlog "$2" $3
|
||||||
fi
|
fi
|
||||||
printlog "################## End Installomator, exit code $1 \n" REQ
|
printlog "################## End Installomator, exit code $1 \n" REQ
|
||||||
|
|
||||||
# if label is wrong and we wanted name of the label, then return ##################
|
# if label is wrong and we wanted name of the label, then return ##################
|
||||||
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
|
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
|
||||||
1=0 # If only label name should be returned we exit without any errors
|
1=0 # If only label name should be returned we exit without any errors
|
||||||
@@ -199,6 +199,16 @@ xpath() {
|
|||||||
fi
|
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() {
|
getAppVersion() {
|
||||||
# modified by: Søren Theilgaard (@theilgaard) and Isaac Ordonez
|
# modified by: Søren Theilgaard (@theilgaard) and Isaac Ordonez
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ firefox)
|
|||||||
name="Firefox"
|
name="Firefox"
|
||||||
type="dmg"
|
type="dmg"
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US"
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
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
|
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"
|
name="Firefox"
|
||||||
type="dmg"
|
type="dmg"
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-latest&os=osx&lang=da"
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
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
|
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')."
|
printlog "Download not found for '$userLanguage', using default ('en-US')."
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-latest-ssl&os=osx"
|
downloadURL="https://download.mozilla.org/?product=firefox-latest-ssl&os=osx"
|
||||||
fi
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
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
|
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"
|
name="Firefox"
|
||||||
type="pkg"
|
type="pkg"
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-esr-pkg-latest-ssl&os=osx"
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
blockingProcesses=( firefox )
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ firefoxesr_intl)
|
|||||||
printlog "Download not found for '$userLanguage', using default ('en-US')."
|
printlog "Download not found for '$userLanguage', using default ('en-US')."
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-esr-latest-ssl&os=osx"
|
downloadURL="https://download.mozilla.org/?product=firefox-esr-latest-ssl&os=osx"
|
||||||
fi
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
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
|
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"
|
name="Firefox"
|
||||||
type="pkg"
|
type="pkg"
|
||||||
downloadURL="https://download.mozilla.org/?product=firefox-pkg-latest-ssl&os=osx&lang=en-US"
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
blockingProcesses=( firefox )
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ firefoxpkg_intl)
|
|||||||
printlog "Download not found for that language. Using en-US" WARN
|
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"
|
downloadURL="https://download.mozilla.org/?product=firefox-pkg-latest-ssl&os=osx&lang=en-US"
|
||||||
fi
|
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"
|
expectedTeamID="43AQ936H96"
|
||||||
blockingProcesses=( firefox )
|
blockingProcesses=( firefox )
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user