mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
Merge branch 'dev' into Update/install-detection
This commit is contained in:
@@ -1,6 +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 it’s 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”.
|
||||
|
||||
## v0.7
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
65
MDM/MDMMosyle install.sh
Normal file
65
MDM/MDMMosyle install.sh
Normal 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
|
||||
15
README.md
15
README.md
@@ -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 it’s 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:
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -348,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."
|
||||
@@ -375,7 +375,9 @@ installAppWithPath() { # $1: path to app to install in $targetDir
|
||||
# not running as root
|
||||
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"
|
||||
@@ -388,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"
|
||||
@@ -397,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() {
|
||||
@@ -417,7 +434,6 @@ mountDMG() {
|
||||
|
||||
installFromDMG() {
|
||||
mountDMG
|
||||
|
||||
installAppWithPath "$dmgmount/$appName"
|
||||
}
|
||||
|
||||
|
||||
@@ -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 it’s 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
|
||||
#
|
||||
|
||||
17
fragments/labels/adobecreativeclouddesktop.sh
Normal file
17
fragments/labels/adobecreativeclouddesktop.sh
Normal 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"
|
||||
;;
|
||||
@@ -214,6 +214,12 @@ if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$installerTool" ]; then
|
||||
# installerTool defined, and we use that for installation
|
||||
printlog "installerTool used: $installerTool"
|
||||
appName="$installerTool"
|
||||
fi
|
||||
|
||||
case $type in
|
||||
dmg)
|
||||
installFromDMG
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user