Merge branch 'dev' into microsoft-labels-updates

This commit is contained in:
Søren Theilgaard
2021-11-22 09:58:33 +01:00
committed by GitHub
19 changed files with 475 additions and 87 deletions

View File

@@ -1,5 +1,8 @@
## v0.8
- Installomator now detects when an app is already installed, and will display notifications correctly the user based on if the app was updated or installed for the first time.
- New variables for labels that should be installaed using CLI: `CLIInstaller` and `CLIArguments`. If the installer app is named differently than the installed app, then the variable `installerTool` should be use to name the app that should be located in the DMG or zip. See the label __adobecreativeclouddesktop__ to see its use.
- `buildLabel.sh` has been improved to build GitHub software labels much easier. In essense if the URL contains github.com, then it will try to find if it's the latest version or if variable `archiveName` is needed for finding the software. Also improved messaging throughout the script, as well as handling a situation where a pkg does not include a “DIstribution” file, but a “PackageInfo”.
- Microsoft labels with `updateTool` variable, is updated to run `msupdate --list` before running the updateTool directly. Problems have been reported that the update would fail if the `--list` parameter for the command was not run first.
## v0.7

View File

@@ -3799,6 +3799,15 @@ fi
if [ -f "$archiveName" ] && [ "$DEBUG" -ne 0 ]; then
printlog "$archiveName exists and DEBUG enabled, skipping download"
else
# check for blocking process and exit if we are instructed to silent_fail (prevents excess download)
if [[ $BLOCKING_PROCESS_ACTION == "silent_fail" ]]; then
if [[ ${#blockingProcesses} -gt 0 ]]; then
if [[ ${blockingProcesses[1]} != "NONE" ]]; then
checkRunningProcesses
fi
fi
fi
# download the dmg
printlog "Downloading $downloadURL to $archiveName"
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then

View File

@@ -204,6 +204,7 @@ nextcloud
nomad
nomadlogin
notion
nudge
nvivo
obs
obsidian

65
MDM/MDMMosyle install.sh Normal file
View File

@@ -0,0 +1,65 @@
PKG_ID="com.scriptingosx.Installomator"
TARGET_VERSION="0.7.0"
URLDOWNLOAD="%MosyleCDNFile:blah-blah-blah%"
######################################################################
# Installation using Installomator (enter the software to install separated with spaces in the "what"-variable)
what="handbrake theunarchiver microsoftoffice365"
# Covered by Mosyle Catalog: "brave firefox googlechrome microsoftedge microsoftteams signal sublimetext vlc webex zoom" among others
######################################################################
## Code here
# Mark: Condition for Installomator installation
INSTALLED_VERSION="$(pkgutil --pkg-info $PKG_ID 2>/dev/null | grep -i "^version" | awk '{print $2}')"
echo "Current Version: ${INSTALLED_VERSION}"
if [[ "$TARGET_VERSION" != "$INSTALLED_VERSION" ]]; then
TMPDIR=$(mktemp -d )
if ! cd "$TMPDIR"; then
echo "error changing directory $TMPDIR"
exit 98
fi
NAME=$TMPDIR/$(date +%s).pkg
if ! curl -fsL "$URLDOWNLOAD" -o "$NAME"; then
echo "error downloading $URLDOWNLOAD to $NAME."
exit 97
fi
installer -pkg "$NAME" -target /
rm -rf "$TMPDIR"
else
echo "Installomator version $INSTALLED_VERSION already installed!"
fi
# Mark: Start Installomator label(s) installation
# Count errors
errorCount=0
# Verify that Installomator has been installed
destFile="/usr/local/Installomator/Installomator.sh"
if [ ! -e "${destFile}" ]; then
echo "Installomator not found here:"
echo "${destFile}"
echo "Exiting."
exit 99
fi
for item in $what; do
#echo $item
${destFile} ${item} LOGO=mosyle NOTIFY=all BLOCKING_PROCESS_ACTION=tell_user #NOTIFY=silent BLOCKING_PROCESS_ACTION=quit_kill #INSTALL=force
if [ $? != 0 ]; then
# Error handling
echo "[$(DATE)] Error installing ${item}. Exit code $?"
let errorCount++
# exit $?
fi
done
echo
echo "Errors: $errorCount"
echo "[$(DATE)][LOG-END]"
exit $errorCount

View File

@@ -372,11 +372,24 @@ Depending on the application or pkg there are a few more variables you can or ne
`$updateTool $updateArguments`
Will be run instead of of downloading and installing a complete new version.
Use this when the `updateTool` does differential and optimized downloads.
e.g. `msupdate` (see microsoft installations)
e.g. `msupdate` (see various Microsoft installations).
- `updateToolRunAsCurrentUser`:
When this variable is set (any value), `$updateTool` will be run as the current user. Default is unset and
- `CLIInstaller`:
- `CLIArguments`:
If the downloaded dmg is actually an installer that we can call using CLI, we can use these two variables for what to call.
We need to define `name` for the installed app (to be version checked), as well as `installerTool` for the installer app (if named differently that `name`. Installomator will add the path to the folder/disk image with the binary, and it will be called like this:
`$CLIInstaller $CLIArguments`
For most installations `CLIInstaller` should contain the `installerTool` for the CLI call (if its the same).
We can support a whole range of other software titles by implementing this.
See label adobecreativeclouddesktop.
- `installerTool`:
Introduced as part of `CLIInstaller`. If the installer in the DMG or ZIP is named differently than the installed app, then this variable can be used to name the installer that should be located after mounting/expanding the downloaded archive.
See label adobecreativeclouddesktop
### Configuration from Arguments
You can provide a configuration variable, such as `DEBUG` or `NOTIFY` as an argument in the form `VAR=value`. For example:

View File

@@ -36,6 +36,12 @@ done
# lowercase the label
label=${label:l}
# separate check for 'version' in order to print plain version number without any other information
if [ $label == "version" ]; then
echo "$VERSION"
exit 0
fi
printlog "################## Start Installomator v. $VERSION"
printlog "################## $label"
@@ -49,11 +55,6 @@ currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print
# MARK: labels in case statement
case $label in
version)
# print the script VERSION
printlog "$VERSION"
exit 0
;;
longversion)
# print the script version
printlog "Installomater: version $VERSION ($VERSIONDATE)"

View File

@@ -148,6 +148,7 @@ getAppVersion() {
appversion="$(pkgutil --pkg-info-plist ${packageID} 2>/dev/null | grep -A 1 pkg-version | tail -1 | sed -E 's/.*>([0-9.]*)<.*/\1/g')"
if [[ $appversion != "" ]]; then
printlog "found packageID $packageID installed, version $appversion"
updateDetected="YES"
return
else
printlog "No version found using packageID $packageID"
@@ -162,7 +163,11 @@ getAppVersion() {
else
applist=$(mdfind "kind:application $appName" -0 )
fi
printlog "App(s) found: ${applist}"
if [[ -z applist ]]; then
printlog "No previous app found"
else
printlog "App(s) found: ${applist}"
fi
appPathArray=( ${(0)applist} )
@@ -173,6 +178,7 @@ getAppVersion() {
#appversion=$(mdls -name kMDItemVersion -raw $installedAppPath )
appversion=$(defaults read $installedAppPath/Contents/Info.plist $versionKey) #Not dependant on Spotlight indexing
printlog "found app at $installedAppPath, version $appversion"
updateDetected="YES"
# Is current app from App Store
if [[ -d "$installedAppPath"/Contents/_MASReceipt ]];then
printlog "Installed $appName is from App Store, use “IGNORE_APP_STORE_APPS=yes” to replace."
@@ -342,7 +348,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
# versioncheck
# credit: Søren Theilgaard (@theilgaard)
appNewVersion=$(defaults read $appPath/Contents/Info.plist $versionKey)
if [[ $appversion == $appNewVersion ]]; then
if [[ -n $appNewVersion && $appversion == $appNewVersion ]]; then
printlog "Downloaded version of $name is $appNewVersion, same as installed."
if [[ $INSTALL != "force" ]]; then
message="$name, version $appNewVersion, is the latest version."
@@ -370,6 +376,8 @@ installAppWithPath() { # $1: path to app to install in $targetDir
cleanupAndExit 6 "not running as root, exiting"
fi
# Test if variable CLIInstaller is set
if [[ -z $CLIInstaller ]]; then
# remove existing application
if [ -e "$targetDir/$appName" ]; then
printlog "Removing existing $targetDir/$appName"
@@ -382,7 +390,6 @@ installAppWithPath() { # $1: path to app to install in $targetDir
cleanupAndExit 7 "Error while copying"
fi
# set ownership to current user
if [ "$currentUser" != "loginwindow" ]; then
printlog "Changing owner to $currentUser"
@@ -391,6 +398,22 @@ installAppWithPath() { # $1: path to app to install in $targetDir
printlog "No user logged in, not changing user"
fi
elif [[ ! -z $CLIInstaller ]]; then
mountname=$(dirname $appPath)
printlog "CLIInstaller exists, running installer command $mountname/$CLIInstaller $CLIArguments" #INFO
CLIoutput=$("$mountname/$CLIInstaller" "${CLIArguments[@]}" 2>&1)
CLIstatus=$(echo $?)
logoutput="$CLIoutput" # dedupliatelogs "$CLIoutput"
if [ $CLIstatus -ne 0 ] ; then
cleanupAndExit 3 "Error installing $mountname/$CLIInstaller $CLIArguments error:\n$logoutput" #ERROR
else
printlog "Succesfully ran $mountname/$CLIInstaller $CLIArguments"
fi
printlog "Debugging enabled, update tool output was:\n$logoutput" #DEBUG
fi
}
mountDMG() {
@@ -411,7 +434,6 @@ mountDMG() {
installFromDMG() {
mountDMG
installAppWithPath "$dmgmount/$appName"
}
@@ -612,7 +634,11 @@ finishing() {
if [[ $currentUser != "loginwindow" && ( $NOTIFY == "success" || $NOTIFY == "all" ) ]]; then
printlog "notifying"
displaynotification "$message" "$name update/installation complete!"
if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "$name update complete!"
else
displaynotification "$message" "$name installation complete!"
fi
fi
}

View File

@@ -198,8 +198,27 @@ REOPEN="yes"
# $updateTool $updateArguments
# Will be run instead of of downloading and installing a complete new version.
# Use this when the updateTool does differential and optimized downloads.
# e.g. msupdate
# e.g. msupdate on various Microsoft labels
#
# - updateToolRunAsCurrentUser:
# When this variable is set (any value), $updateTool will be run as the current user.
#
# - CLIInstaller:
# - CLIArguments:
# If the downloaded dmg is actually an installer that we can call using CLI, we can
# use these two variables for what to call.
# We need to define `name` for the installed app (to be version checked), as well as
# `installerTool` for the installer app (if named differently that `name`. Installomator
# will add the path to the folder/disk image with the binary, and it will be called like this:
`$CLIInstaller $CLIArguments`
# For most installations `CLIInstaller` should contain the `installerTool` for the CLI call
# (if its the same).
# We can support a whole range of other software titles by implementing this.
# See label adobecreativeclouddesktop
#
# - installerTool:
# Introduced as part of `CLIInstaller`. If the installer in the DMG or ZIP is named
# differently than the installed app, then this variable can be used to name the
# installer that should be located after mounting/expanding the downloaded archive.
# See label adobecreativeclouddesktop
#

View File

@@ -0,0 +1,17 @@
adobecreativeclouddesktop)
name="Adobe Creative Cloud"
#appName="Install.app"
type="dmg"
if [[ $(arch) == "arm64" ]]; then
downloadURL=$(curl -fs "https://helpx.adobe.com/download-install/kb/creative-cloud-desktop-app-download.html" | grep -o "https*.*macarm64.*dmg" | cut -d '"' -f1 | head -1)
elif [[ $(arch) == "i386" ]]; then
downloadURL=$(curl -fs "https://helpx.adobe.com/download-install/kb/creative-cloud-desktop-app-download.html" | grep -o "https*.*osx10.*dmg" | cut -d '"' -f1 | head -1)
fi
#downloadURL=$(curl -fs "https://helpx.adobe.com/download-install/kb/creative-cloud-desktop-app-download.html" | grep -o "https*.*dmg" | head -1)
appNewVersion=$(curl -fs "https://helpx.adobe.com/creative-cloud/release-note/cc-release-notes.html" | grep "mandatory" | head -1 | grep -o "Version *.* released" | cut -d " " -f2)
installerTool="Install.app"
CLIInstaller="Install.app/Contents/MacOS/Install"
CLIArguments=(--mode=silent)
expectedTeamID="JQ525L2MZD"
Company="Adobe"
;;

View File

@@ -0,0 +1,9 @@
eshareosx)
name="e-Share"
type="pkg"
packageID="com.ncryptedcloud.e-Share.pkg"
downloadURL=https://www.ncryptedcloud.com/static/downloads/osx/$(curl -fs https://www.ncryptedcloud.com/static/downloads/osx/ | grep -o -i "href.*\".*\"" | cut -d '"' -f2)
versionKey="CFBundleVersion"
appNewVersion=$( echo "${downloadURL}" | sed -E 's/.*\/[a-zA-Z\-]*_([0-9.]*)\.pkg/\1/g' )
expectedTeamID="X9MBQS7DDC"
;;

View File

@@ -0,0 +1,7 @@
maccyapp)
name="Maccy"
type="zip"
downloadURL="$(downloadURLFromGit p0deje Maccy)"
appNewVersion="$(versionFromGit p0deje Maccy)"
expectedTeamID="MN3X4648SC"
;;

View File

@@ -0,0 +1,8 @@
nudge)
name="Nudge"
type="pkg"
downloadURL=$(downloadURLFromGit macadmins Nudge )
appNewVersion=$(versionFromGit macadmins Nudge )
expectedTeamID="9GQZ7KUFR6"
archiveName="Nudge-[0-9.]*.pkg"
;;

View File

@@ -0,0 +1,8 @@
overflow)
name="Overflow"
type="dmg"
downloadURL="$(curl -sL 'https://overflow.io/download/' | awk -F '"' '/app-updates.overflow.io\/packages\/updates\/osx_64/ { print $8; exit }')"
appNewVersion=$(echo "$downloadURL" | awk -F '-|[.]dmg' '{ print $(NF-1) }')
expectedTeamID="7TK7YSGJFF"
versionKey="CFBundleShortVersionString"
;;

View File

@@ -0,0 +1,6 @@
sketchupviewer)
name="SketchUpViewer"
type="dmg"
downloadURL="$(curl -fs https://www.sketchup.com/sketchup/SketchUpViewer-en-dmg | grep "<a href=" | sed 's/.*href="//' | sed 's/".*//')"
expectedTeamID="J8PVMCY7KL"
;;

View File

@@ -0,0 +1,7 @@
talkdeskcallbar)
name="Callbar"
type="dmg"
downloadURL=https://downloadcallbar.talkdesk.com/Callbar-$(curl -fsL https://downloadcallbar.talkdesk.com/release_metadata.json | sed -n 's/^.*"version":"\([^"]*\)".*$/\1/p').dmg
appNewVersion=$(curl -fsL https://downloadcallbar.talkdesk.com/release_metadata.json | sed -n 's/^.*"version":"\([^"]*\)".*$/\1/p')
expectedTeamID="YGGJX44TB8"
;;

View File

@@ -1,7 +1,9 @@
typora)
name="Typora"
type="dmg"
downloadURL="https://www.typora.io/download/Typora.dmg"
appNewVersion="$(curl -fs "https://www.typora.io/dev_release.html" | grep -o -i "h4>[0-9.]*</h4" | head -1 | sed -E 's/.*h4>([0-9.]*)<\/h4.*/\1/')"
#downloadURL="https://www.typora.io/download/Typora.dmg"
downloadURL=$(curl -fs "https://www.typora.io/download/dev_update.xml" | xpath '(//rss/channel/item/enclosure/@url)[1]' 2>/dev/null | cut -d '"' -f2)
#appNewVersion="$(curl -fs "https://www.typora.io/dev_release.html" | grep -o -i "h4>[0-9.]*</h4" | head -1 | sed -E 's/.*h4>([0-9.]*)<\/h4.*/\1/')"
appNewVersion=$(curl -fs "https://www.typora.io/download/dev_update.xml" | xpath '(//rss/channel/item/enclosure/@sparkle:shortVersionString)[1]' 2>/dev/null | cut -d '"' -f2)
expectedTeamID="9HWK5273G4"
;;

View File

@@ -166,14 +166,22 @@ else
printlog "Downloading $downloadURL to $archiveName"
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "Downloading $name update" "Download in progress …"
if [[ $updateDetected == "YES" ]]; then
displaynotification "Downloading $name update" "Download in progress …"
else
displaynotification "Downloading new $name" "Download in progress …"
fi
fi
if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
printlog "error downloading $downloadURL"
message="$name update/installation failed. This will be logged, so IT can follow up."
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "$message" "Error installing/updating $name"
if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "Error updating $name"
else
displaynotification "$message" "Error installing $name"
fi
fi
cleanupAndExit 2
fi
@@ -196,7 +204,17 @@ fi
printlog "Installing $name"
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "Installing $name" "Installation in progress …"
if [[ $updateDetected == "YES" ]]; then
displaynotification "Updating $name" "Installation in progress …"
else
displaynotification "Installing $name" "Installation in progress …"
fi
fi
if [ -n "$installerTool" ]; then
# installerTool defined, and we use that for installation
printlog "installerTool used: $installerTool"
appName="$installerTool"
fi
case $type in

View File

@@ -10,6 +10,94 @@ downloadURL=${1?:"need to provide a download URL."}
# Usage
# ./buildLabel.sh <URL to download software>
# Mark: Functions
xpath() {
# the xpath tool changes in Big Sur and now requires the `-e` option
if [[ $(sw_vers -buildVersion) > "20A" ]]; then
/usr/bin/xpath -e $@
# alternative: switch to xmllint (which is not perl)
#xmllint --xpath $@ -
else
/usr/bin/xpath $@
fi
}
# will get the latest release download from a github repo
downloadURLFromGit() { # $1 git user name, $2 git repo name
gitusername=${1?:"no git user name"}
gitreponame=${2?:"no git repo name"}
if [[ $type == "pkgInDmg" ]]; then
filetype="dmg"
elif [[ $type == "pkgInZip" ]]; then
filetype="zip"
else
filetype=$type
fi
if [ -n "$archiveDestinationName" ]; then
downloadURL=$(curl -sf "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }")
else
downloadURL=$(curl -sf "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }")
fi
echo "$downloadURL"
return 0
}
versionFromGit() {
# $1 git user name, $2 git repo name
gitusername=${1?:"no git user name"}
gitreponame=${2?:"no git repo name"}
appNewVersion=$(curl --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | grep tag_name | cut -d '"' -f 4 | sed 's/[^0-9\.]//g')
if [ -z "$appNewVersion" ]; then
printlog "could not retrieve version number for $gitusername/$gitreponame"
appNewVersion=""
else
echo "$appNewVersion"
return 0
fi
}
pkgInvestigation() {
echo "Package investigation."
teamID=$(spctl -a -vv -t install "$pkgPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' )
if [[ -z $teamID ]]; then
echo "Error verifying PKG: $pkgPath"
echo "No TeamID found."
exit 4
fi
echo "Team ID found for PKG: $teamID"
echo "For PKGs it's advised to find packageID for version checking, so extracting those"
pkgutil --expand "$pkgPath" "$archiveName"_pkg
if [[ -a "$archiveName"_pkg/Distribution ]] ; then
cat "$archiveName"_pkg/Distribution | xpath '//installer-gui-script/pkg-ref[@id][@version]' 2>/dev/null
packageID="$(cat "$archiveName"_pkg/Distribution | xpath '//installer-gui-script/pkg-ref[@id][@version]' 2>/dev/null | tr ' ' '\n' | grep -i "id" | cut -d \" -f 2)"
elif [[ -a "$archiveName"_pkg/PackageInfo ]] ; then
cat "$archiveName"_pkg/PackageInfo | xpath '//pkg-info/@version' 2>/dev/null
packageID="$(cat "$archiveName"_pkg/PackageInfo | xpath '//pkg-info/@identifier' 2>/dev/null | cut -d '"' -f2 )"
fi
rm -r "$archiveName"_pkg
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."
}
appInvestigation() {
appName=${appPath##*/}
name=${appName%.*}
echo "Application investigation."
# verify with spctl
teamID=$(spctl -a -vv "$appPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' )
if [[ -z $teamID ]]; then
echo "Error verifying app: $appPath"
echo "No TeamID found."
exit 4
fi
echo "Team ID found for app: $teamID"
}
# Mark: Code
# Use working directory as download folder
tmpDir="$(pwd)/$(date "+%Y-%m-%d-%H-%M-%S")"
# Create a n almost unique folder name
@@ -23,21 +111,25 @@ if ! cd "$tmpDir"; then
fi
echo "Working dir: $(pwd)"
# download the URL
# investigate and download the URL
echo "Downloading $downloadURL"
echo $(basename $downloadURL)
#exit
# First trying to find redirection headers on the download, as those can contain version numbers
echo "Redirecting to (maybe this can help us with version):\n$(curl -fsIL -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" | grep -i "^[location|x\-amz\-meta\-version]*")"
# Now downloading without extra headers
if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then
echo "error downloading $downloadURL using standard headers."
echo "result: $downloadOut"
echo "Trying all headers…"
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
# we are only here if the download failed
echo "error downloading $downloadURL using all headers."
echo "result: $downloadOut"
# Sometimes a server will give some results to the downloaded output
if [[ -n $downloadOut ]]; then
echo "Trying output of this…"
downloadURL="$(echo $downloadOut | tail -1)"
# Last chance for succes on this download
if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -w "%{filename_effective}\n%{url_effective}\n")"; then
echo "error downloading $downloadURL using previous output."
echo "result: $downloadOut"
@@ -48,49 +140,19 @@ if ! downloadOut="$(curl -fL "$downloadURL" --remote-header-name --remote-name -
fi
fi
xpath() {
# the xpath tool changes in Big Sur and now requires the `-e` option
if [[ $(sw_vers -buildVersion) > "20A" ]]; then
/usr/bin/xpath -e $@
# alternative: switch to xmllint (which is not perl)
#xmllint --xpath $@ -
else
/usr/bin/xpath $@
fi
}
# Now we have downloaded the archive, and we need to analyze this
# The download have returned both {filename_effective} and {url_effective}
pkgInvestigation() {
echo "Package found"
teamID=$(spctl -a -vv -t install "$archiveName" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' )
echo "For PKGs it's advised to find packageID for version checking"
pkgutil --expand "$pkgPath" "$archiveName"_pkg
cat "$archiveName"_pkg/Distribution | xpath '//installer-gui-script/pkg-ref[@id][@version]' 2>/dev/null
packageID="$(cat "$archiveName"_pkg/Distribution | xpath '//installer-gui-script/pkg-ref[@id][@version]' 2>/dev/null | tr ' ' '\n' | grep -i "id" | cut -d \" -f 2)"
rm -r "$archiveName"_pkg
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."
}
appInvestigation() {
appName=${appPath##*/}
# verify with spctl
echo "Verifying: $appPath"
if ! teamID=$(spctl -a -vv "$appPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' ); then
echo "Error verifying $appPath"
exit 4
fi
}
#echo "downloadOut:\n${downloadOut}"
archiveTempName=$( echo "${downloadOut}" | head -1 )
echo "archiveTempName: $archiveTempName"
archivePath=$( echo "${downloadOut}" | tail -1 )
echo "archivePath: $archivePath"
# The two fields retuurned can be exchanged, so some servers return the filename on the other variable. Don't know why.
# So we want to investigate which one has the filename
try1archiveName=${${archiveTempName##*/}%%\?*}
try2archiveName=${${archivePath##*/}%%\?*}
fileName_re='^([a-zA-Z0-9\_.%-]*)\.(dmg|pkg|zip|tbz)$'
fileName_re='^([a-zA-Z0-9\_.%-]*)\.(dmg|pkg|zip|tbz)$' # regular expression for matching
if [[ "${try1archiveName}" =~ $fileName_re ]]; then
archiveName=${try1archiveName}
elif [[ "${try2archiveName}" =~ $fileName_re ]]; then
@@ -98,22 +160,26 @@ elif [[ "${try2archiveName}" =~ $fileName_re ]]; then
else
echo "Could not determine archiveName from “$try1archiveName” and “$try2archiveName"
#echo "Extensions $archiveTempName:t:e $archivePath:t:e"
exit
exit 1
fi
# So we found a filename, and now we want to detect the extension and other information
echo "Calculated archiveName: $archiveName"
mv $archiveTempName $archiveName
name=${archiveName%.*}
echo "name: $name"
archiveExt=${archiveName##*.}
type=$archiveExt
echo "archiveExt: $archiveExt"
identifier=${name:l}
identifier=${identifier//\%[0-9a-fA-F][0-9a-fA-F]}
identifier=${identifier//[,._*@$\(\)\-]}
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
if [ "$archiveExt" = "pkg" ]; then
pkgPath="$archiveName"
echo "PKG found: $pkgPath"
pkgInvestigation
elif [ "$archiveExt" = "dmg" ]; then
echo "Diskimage found"
@@ -125,15 +191,20 @@ elif [ "$archiveExt" = "dmg" ]; then
fi
echo "Mounted: $dmgmount"
# check if app og pkg exists
# 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"
@@ -142,43 +213,141 @@ elif [ "$archiveExt" = "zip" ] || [ "$archiveExt" = "tbz" ]; then
# unzip the archive
tar -xf "$archiveName"
# check if app og pkg exists
# check if app og pkg exists after expanding
appPath=$(find "$tmpDir" -name "*.app" -maxdepth 2 -print )
pkgPath=$(find "$tmpDir" -name "*.pkg" -maxdepth 2 -print )
if [[ $appPath != "" ]]; then
echo "App found: $appPath"
appInvestigation
elif [[ $pkgPath != "" ]]; then
echo "PKG found: $pkgPath"
archiveExt="pkgInZip"
pkgInvestigation
else
echo "Nothing found in compressed archive."
exit 9
fi
fi
echo
echo "**********"
echo
echo "Labels should be named in small caps, numbers 0-9, “-”, and “_”. No other characters allowed."
echo
echo "appNewVersion is often difficult to find. Can sometimes be found in the filename, sometimes as part of the download redirects, but also on a web page. See redirect and archivePath above if link contains information about this. That is a good place to start"
echo
echo "$identifier)"
# 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
echo "\n**********\n\nFound GitHub path"
githubAuthor=$(echo "$downloadURL" | cut -d "/" -f4)
githubRepo=$(echo "$downloadURL" | cut -d "/" -f5)
if [[ ! -z $githubAuthor && $githubRepo ]] ; then
githubError=9
echo "Github place: $githubAuthor $githubRepo"
originalDownloadURL="$downloadURL"
githubDownloadURL=$(downloadURLFromGit "$githubAuthor" "$githubRepo")
githubAppNewVersion=$(versionFromGit "$githubAuthor" "$githubRepo")
downloadURL=$originalDownloadURL
echo "Latest URL on github: $githubDownloadURL \nLatest version: $githubAppNewVersion"
if [[ "$originalDownloadURL" == "$githubDownloadURL" ]]; then
echo "GitHub calculated URL matches entered URL."
githubError=0
downloadURL="\$(downloadURLFromGit $githubAuthor $githubRepo)"
appNewVersion="\$(versionFromGit $githubAuthor $githubRepo)"
else
if [[ "$( echo $originalDownloadURL | cut -d "/" -f1-7)" == "$( echo $githubDownloadURL | cut -d "/" -f1-7)" ]]; then
echo "Calculated GitHub URL almost identical, only this diff:"
echo "$( echo $originalDownloadURL | cut -d "/" -f8-)” and “$( echo $githubDownloadURL | cut -d "/" -f8-)"
echo "Could be version difference or difference in archiveName for a given release."
echo "Testing for version difference."
#Investigate if these strings match if numbers are removed.
if [[ "$( echo $originalDownloadURL | cut -d "/" -f8- | sed 's/[0-9.]*//g')" == "$( echo $githubDownloadURL | cut -d "/" -f8- | sed 's/[0-9.]*//g')" ]]; then
# In this if..then we found out if the end parts of the URL was mathing after removinger numbers and dots (and then assuming that only a version was different
echo "$( echo $originalDownloadURL | cut -d "/" -f8- | sed 's/[0-9.]*//g')” and “$( echo $githubDownloadURL | cut -d "/" -f8- | sed 's/[0-9.]*//g')"
echo "Matching without numbers in string.\nVERY LIKELY a version difference."
githubError=1
echo "Try running again with URL: ${githubDownloadURL}"
else
# If we are here more than numbers and dots didn't match, so maybe this repo has software for several software titles
echo "Not a version problem.\nTesting for difference in archiveName."
tempName=$(echo ${archiveName%.*} | grep -o "[0-9.]*" )
# if archiveName contains several sections of numbers and/or dots, like "Marathon2-20210408-Mac.dmg" that will return 2 and 20210408 so we want to find the longest of these two (or more), assuming that the longest is the version
tempName=( $tempName ) # make it an array
i=0; max=0; tempString=""
echo $tempName | while read tempLine; do
((i++))
length[$i]=${#tempLine}
if [[ $max -lt $length[$i] ]] ; then
max=$length[$i]
tempString=$tempLine
fi
done
# Now tempString will have the longest string returned before. So I use that in a search-replace to remove that part and insert regular expression "[0-9.]*" instead as that will match the removed part
archiveDestinationName="$(echo $archiveName | sed -E "s/^(.*)$tempString(.*)$/\1[0-9.]*\2/g")"
echo "archiveName=\"$archiveDestinationName\""
# Now we want to test if the archiveName is working
githubDownloadURL=$(downloadURLFromGit "$githubAuthor" "$githubRepo")
githubAppNewVersion=$(versionFromGit "$githubAuthor" "$githubRepo")
downloadURL=$originalDownloadURL
echo "Latest URL on github: $githubDownloadURL \nLatest version: $githubAppNewVersion"
# Final evaluation of our result
if [[ "$originalDownloadURL" == "$githubDownloadURL" ]]; then
echo "GitHub calculated URL matches entered URL."
githubError=0
downloadURL="\$(downloadURLFromGit $githubAuthor $githubRepo)"
appNewVersion="\$(versionFromGit $githubAuthor $githubRepo)"
else
githubError=2
echo "Not solved by using archiveName."
echo "Not sure what this can be."
archiveDestinationName=""
fi
fi
else
echo "GitHub URL not matching"
fi
fi
fi
fi
# We are finished downloading and analyzing, so now we need to present the data
echo "\n**********"
echo "\nLabels should be named in small caps, numbers 0-9, “-”, and “_”. No other characters allowed."
if [[ -z $githubError || $githubError != 0 ]]; then
echo "\nappNewVersion is often difficult to find. Can sometimes be found in the filename, sometimes as part of the download redirects, but also on a web page. See redirect and archivePath above if link contains information about this. That is a good place to start"
fi
# Here the label is built, for easy copy and paste
echo "\n$identifier)"
echo " name=\"$name\""
echo " type=\"$archiveExt\""
if [ "$packageID" != "" ]; then
if [ -n "$packageID" ]; then
echo " packageID=\"$packageID\""
fi
if [ -n "$archiveDestinationName" ]; then
echo " archiveName=\"$archiveDestinationName\""
fi
echo " downloadURL=\"$downloadURL\""
echo " appNewVersion=\"\""
echo " appNewVersion=\"$appNewVersion\""
echo " expectedTeamID=\"$teamID\""
if [ -n "$appName" ] && [ "$appName" != "${name}.app" ]; then
echo " appName=\"$appName\""
fi
echo " ;;"
echo
echo "Above should be saved in a file with exact same name as label, and given extension “.sh”."
echo "Put this file in folder “fragments/labels”."
echo
case $githubError in
0)
echo "\nLabel converted to GitHub label without errors."
echo "Details can be seen above."
;;
1)
echo "\nFound Github place in this URL: $githubAuthor $githubRepo"
echo "But version has a problem."
echo "Try running again with URL: ${githubDownloadURL}"
echo "See details above."
;;
2)
echo "\nFound Github place in this URL: $githubAuthor $githubRepo"
echo "But it could not be resolved."
echo "Can be from a hidden repository, or the software title has a number in it."
;;
esac
exit 0
echo "\nAbove should be saved in a file with exact same name as label, and given extension “.sh”."
echo "Put this file in folder “fragments/labels”.\n"

View File

@@ -16,14 +16,14 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# MARK: Constants
pathToLabels="fragments/labels"
if [[ ! -d ${pathToLabels} ]]; then
echo "This script should be called from Installomator directory as working directory with this command:"
echo "utils/checkLabels.sh"
echo
exit 99
fi
#setup some folders
script_dir=$(dirname ${0:A})
repo_dir=$(dirname $script_dir)
build_dir="$repo_dir/build"
destination_file="$build_dir/Installomator.sh"
fragments_dir="$repo_dir/fragments"
labels_dir="$fragments_dir/labels"
# MARK: Check minimal macOS requirement
if [[ $(sw_vers -buildVersion ) < "18" ]]; then
@@ -98,11 +98,11 @@ BLUE='\033[1;34m'
NC='\033[0m' # No Color
# Labels with the $(arch) call for different versions for Intel and Apple Silicon should be listed here:
archLabels=( $(grep "\$(arch)" ${pathToLabels}/* | awk '{print $1}' | sed -E 's/.*\/([a-z0-9\_-]*)\..*/\1/g'| uniq ) )
archLabels=( $(grep "\$(arch)" ${labels_dir}/* | awk '{print $1}' | sed -E 's/.*\/([a-z0-9\_-]*)\..*/\1/g'| uniq ) )
echo "${BLUE}Labels with \"\$(arch)\" call:${NC}\n${archLabels}\n"
if [[ $# -eq 0 ]]; then
allLabels=( $(grep -h -E '^([a-z0-9\_-]*)(\)|\|\\)$' ${pathToLabels}/*.sh | tr -d ')|\\' | sort) )
allLabels=( $(grep -h -E '^([a-z0-9\_-]*)(\)|\|\\)$' ${labels_dir}/*.sh | tr -d ')|\\' | sort) )
else
allLabels=( ${=@} )
fi
@@ -122,7 +122,7 @@ for label in $allLabels; do
name=""; type=""; downloadURL=""; appNewVersion=""; expectedTeamID=""; blockingProcesses=""; updateTool=""; updateToolArguments=""; archiveName=""
#caseLabel
if cat "${pathToLabels}/${label}.sh" | grep -v -E '^[a-z0-9\_-]*(\)|\|\\)$' | grep -v ";;" > checkLabelCurrent.sh; then
if cat "${labels_dir}/${label}.sh" | grep -v -E '^[a-z0-9\_-]*(\)|\|\\)$' | grep -v ";;" > checkLabelCurrent.sh; then
source checkLabelCurrent.sh
echo "Name: $name"