mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 21:02:46 +00:00
first attempt at runUpdateTool
This commit is contained in:
@@ -133,6 +133,8 @@ fi
|
|||||||
# lowercase the identifier
|
# lowercase the identifier
|
||||||
identifier=$(echo "$identifier" | tr '[:upper:]' '[:lower:]' )
|
identifier=$(echo "$identifier" | tr '[:upper:]' '[:lower:]' )
|
||||||
|
|
||||||
|
# get current user
|
||||||
|
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
|
||||||
|
|
||||||
|
|
||||||
# identifiers in case statement
|
# identifiers in case statement
|
||||||
@@ -156,6 +158,9 @@ case $identifier in
|
|||||||
type="pkg"
|
type="pkg"
|
||||||
downloadURL="https://dl.google.com/chrome/mac/stable/gcem/GoogleChrome.pkg"
|
downloadURL="https://dl.google.com/chrome/mac/stable/gcem/GoogleChrome.pkg"
|
||||||
expectedTeamID="EQHXZ8M8AV"
|
expectedTeamID="EQHXZ8M8AV"
|
||||||
|
updateTool="/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/GoogleSoftwareUpdateAgent.app/Contents/MacOS/GoogleSoftwareUpdateAgent"
|
||||||
|
updateToolArguments=( -runMode oneshot -userInitiated YES )
|
||||||
|
updateToolRunAsCurrentUser=1
|
||||||
;;
|
;;
|
||||||
spotify)
|
spotify)
|
||||||
name="Spotify"
|
name="Spotify"
|
||||||
@@ -304,10 +309,13 @@ case $identifier in
|
|||||||
expectedTeamID="UBF8T346G9"
|
expectedTeamID="UBF8T346G9"
|
||||||
;;
|
;;
|
||||||
microsoftteams)
|
microsoftteams)
|
||||||
name="Teams"
|
name="Microsoft Teams"
|
||||||
type="pkg"
|
type="pkg"
|
||||||
downloadURL="https://go.microsoft.com/fwlink/?linkid=869428"
|
downloadURL="https://go.microsoft.com/fwlink/?linkid=869428"
|
||||||
expectedTeamID="UBF8T346G9"
|
expectedTeamID="UBF8T346G9"
|
||||||
|
blockingProcesses=( Teams "Microsoft Teams Helper" )
|
||||||
|
updateTool="/Library/Application\ Support/Microsoft/MAU2.0/Microsoft\ AutoUpdate.app/Contents/MacOS/msupdate"
|
||||||
|
updateToolArguments=( --install --apps TEAM01 )
|
||||||
;;
|
;;
|
||||||
microsoftautoupdate)
|
microsoftautoupdate)
|
||||||
name="Microsoft AutoUpdate"
|
name="Microsoft AutoUpdate"
|
||||||
@@ -321,6 +329,14 @@ case $identifier in
|
|||||||
downloadURL="https://go.microsoft.com/fwlink/?linkid=2093438"
|
downloadURL="https://go.microsoft.com/fwlink/?linkid=2093438"
|
||||||
teamID="UBF8T346G9"
|
teamID="UBF8T346G9"
|
||||||
;;
|
;;
|
||||||
|
microsoftword)
|
||||||
|
name="Microsoft Word"
|
||||||
|
type="pkg"
|
||||||
|
downloadURL="https://go.microsoft.com/fwlink/?linkid=525134"
|
||||||
|
teamID="UBF8T346G9"
|
||||||
|
updateTool="/Library/Application\ Support/Microsoft/MAU2.0/Microsoft\ AutoUpdate.app/Contents/MacOS/msupdate"
|
||||||
|
updateToolArguments=( --install --apps MSWD2019 )
|
||||||
|
;;
|
||||||
microsoftsharepointplugin)
|
microsoftsharepointplugin)
|
||||||
name="MicrosoftSharePointPlugin"
|
name="MicrosoftSharePointPlugin"
|
||||||
type="pkg"
|
type="pkg"
|
||||||
@@ -411,15 +427,10 @@ cleanupAndExit() { # $1 = exit code, $2 message
|
|||||||
exit "$1"
|
exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleUser() {
|
|
||||||
scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }'
|
|
||||||
}
|
|
||||||
|
|
||||||
runAsUser() {
|
runAsUser() {
|
||||||
cuser=$(consoleUser)
|
if [[ $currentUser != "loginwindow" ]]; then
|
||||||
if [[ $cuser != "loginwindow" ]]; then
|
uid=$(id -u "$currentUser")
|
||||||
uid=$(id -u "$cuser")
|
launchctl asuser $uid sudo -u $currentUser "$@"
|
||||||
launchctl asuser $uid sudo -u $cuser "$@"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,6 +602,22 @@ installFromZIP() {
|
|||||||
installAppWithPath "$tmpDir/$appName"
|
installAppWithPath "$tmpDir/$appName"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runUpdateTool() {
|
||||||
|
if [[ -x $updateTool ]]; then
|
||||||
|
echo "running $updateTool $updateToolArguments"
|
||||||
|
if [[ -n $updateToolRunAsCurrentUser ]]; then
|
||||||
|
runAsUser $updateTool "${updateToolArguments}"
|
||||||
|
else
|
||||||
|
$updateTool "${updateToolArguments}"
|
||||||
|
fi
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
cleanupAndExit 15 "Error running $updateTool"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
cleanupAndExit 16 "couldn't find $updateTool"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### main code starts here
|
### main code starts here
|
||||||
@@ -641,8 +668,6 @@ if [[ -z $blockingProcesses ]]; then
|
|||||||
blockingProcesses=( $name )
|
blockingProcesses=( $name )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentUser=$(consoleUser)
|
|
||||||
|
|
||||||
# determine tmp dir
|
# determine tmp dir
|
||||||
if [ "$DEBUG" -eq 1 ]; then
|
if [ "$DEBUG" -eq 1 ]; then
|
||||||
# for debugging use script dir as working directory
|
# for debugging use script dir as working directory
|
||||||
@@ -660,6 +685,30 @@ if ! cd "$tmpDir"; then
|
|||||||
cleanupAndExit 1
|
cleanupAndExit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check if this is an Update
|
||||||
|
if [[ $(mdfind -count -name "$appName") -gt 0 ]]; then
|
||||||
|
# get all apps matching name
|
||||||
|
applist=$(mdfind "kMDItemFSName == '$appName' && kMDItemKind == 'Application'")
|
||||||
|
appPathArray=( ${(f)applist} )
|
||||||
|
filteredAppPaths=( ${(M)appPathArray:#${targetDir}*} )
|
||||||
|
echo $filteredAppPaths
|
||||||
|
if [[ ${#filteredAppPaths} -eq 1 ]]; then
|
||||||
|
installedAppPath=$filteredAppPaths[1]
|
||||||
|
appversion=$(mdls -name kMDItemVersion -raw $installedAppPath )
|
||||||
|
echo "found app at $installedAppPath, version $appversion"
|
||||||
|
if [[ $DEBUG == 0 ]]; then
|
||||||
|
runUpdateTool
|
||||||
|
else
|
||||||
|
echo "DEBUG mode enabled, not running update tool"
|
||||||
|
fi
|
||||||
|
cleanupAndExit 0
|
||||||
|
else
|
||||||
|
echo "could not determine location of $appName"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "could not find $appName"s
|
||||||
|
fi
|
||||||
|
|
||||||
# when user is logged in, and app is running, prompt user to quit app
|
# when user is logged in, and app is running, prompt user to quit app
|
||||||
|
|
||||||
if [[ $BLOCKING_PROCESS_ACTION == "ignore" ]]; then
|
if [[ $BLOCKING_PROCESS_ACTION == "ignore" ]]; then
|
||||||
@@ -704,6 +753,7 @@ case $type in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: notify when done
|
# TODO: notify when done
|
||||||
|
|
||||||
# all done!
|
# all done!
|
||||||
|
|||||||
Reference in New Issue
Block a user