mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-26 21:03:57 +00:00
added more "broken " tests and checks for app existence
This commit is contained in:
@@ -31,6 +31,9 @@ fi
|
|||||||
#
|
#
|
||||||
# the team ID is the ten-digit ID at the end of the line starting with 'origin='
|
# the team ID is the ten-digit ID at the end of the line starting with 'origin='
|
||||||
|
|
||||||
|
# target directory (remember to _omit_ last / )
|
||||||
|
targetDir="/Applications"
|
||||||
|
# this can be overridden below if you want a different location for a specific identifier
|
||||||
|
|
||||||
case $identifier in
|
case $identifier in
|
||||||
|
|
||||||
@@ -44,11 +47,21 @@ case $identifier in
|
|||||||
appName="Spotify.app"
|
appName="Spotify.app"
|
||||||
expectedTeamID="2FNC3A47ZF"
|
expectedTeamID="2FNC3A47ZF"
|
||||||
;;
|
;;
|
||||||
brokenChrome)
|
brokenDownloadURL)
|
||||||
downloadURL="https://dl.google.com/chromeglechrome.dmg"
|
downloadURL="https://broken.com/broken.dmg"
|
||||||
appName="Google Chrome.app"
|
appName="Google Chrome.app"
|
||||||
expectedTeamID="EQHXZ8M8AV"
|
expectedTeamID="EQHXZ8M8AV"
|
||||||
;;
|
;;
|
||||||
|
brokenAppName)
|
||||||
|
downloadURL="https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg"
|
||||||
|
appName="broken.app"
|
||||||
|
expectedTeamID="EQHXZ8M8AV"
|
||||||
|
;;
|
||||||
|
brokenTeamID)
|
||||||
|
downloadURL="https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg"
|
||||||
|
appName="Google Chrome.app"
|
||||||
|
expectedTeamID="broken"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
# unknown identifier
|
# unknown identifier
|
||||||
echo "unknown identifier $identifier"
|
echo "unknown identifier $identifier"
|
||||||
@@ -56,12 +69,9 @@ case $identifier in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# target directory (remember to _omit_ last / )
|
|
||||||
targetDir="/Applications"
|
|
||||||
|
|
||||||
dmgname="${downloadURL##*/}"
|
dmgname="${downloadURL##*/}"
|
||||||
|
|
||||||
cleanupBeforeExit() { # $1 = exit code
|
cleanupAndExit() { # $1 = exit code
|
||||||
if [ "$DEBUG" -eq 0 ]; then
|
if [ "$DEBUG" -eq 0 ]; then
|
||||||
# remove the temporary working directory when done
|
# remove the temporary working directory when done
|
||||||
echo "Deleting $tmpDir"
|
echo "Deleting $tmpDir"
|
||||||
@@ -75,6 +85,7 @@ cleanupBeforeExit() { # $1 = exit code
|
|||||||
echo "Unmounting $dmgmount"
|
echo "Unmounting $dmgmount"
|
||||||
hdiutil detach "$dmgmount"
|
hdiutil detach "$dmgmount"
|
||||||
fi
|
fi
|
||||||
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
# create temporary working directory
|
# create temporary working directory
|
||||||
@@ -89,8 +100,7 @@ echo "Changing directory to $tmpDir"
|
|||||||
if ! cd "$tmpDir"; then
|
if ! cd "$tmpDir"; then
|
||||||
echo "error changing directory $tmpDir"
|
echo "error changing directory $tmpDir"
|
||||||
#rm -Rf "$tmpDir"
|
#rm -Rf "$tmpDir"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 1
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO: when user is logged in, and app is running, prompt user to quit app
|
# TODO: when user is logged in, and app is running, prompt user to quit app
|
||||||
@@ -100,10 +110,9 @@ if [ -f "$dmgname" ] && [ "$DEBUG" -eq 1 ]; then
|
|||||||
else
|
else
|
||||||
# download the dmg
|
# download the dmg
|
||||||
echo "Downloading $downloadURL"
|
echo "Downloading $downloadURL"
|
||||||
if ! curl --location --silent "$downloadURL" -o "$dmgname"; then
|
if ! curl --location --fail --silent "$downloadURL" -o "$dmgname"; then
|
||||||
echo "error downloading $downloadURL"
|
echo "error downloading $downloadURL"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 2
|
||||||
exit 2
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -112,25 +121,28 @@ echo "Mounting $tmpDir/$dmgname"
|
|||||||
# set -o pipefail
|
# set -o pipefail
|
||||||
if ! dmgmount=$(hdiutil attach "$tmpDir/$dmgname" -nobrowse -readonly | tail -n 1 | cut -c 54- ); then
|
if ! dmgmount=$(hdiutil attach "$tmpDir/$dmgname" -nobrowse -readonly | tail -n 1 | cut -c 54- ); then
|
||||||
echo "Error mounting $tmpDir/$dmgname"
|
echo "Error mounting $tmpDir/$dmgname"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 3
|
||||||
exit 3
|
|
||||||
fi
|
fi
|
||||||
echo "Mounted: $dmgmount"
|
echo "Mounted: $dmgmount"
|
||||||
|
|
||||||
|
# check if app exists
|
||||||
|
if [ ! -e "$dmgmount/$appName" ]; then
|
||||||
|
echo "could not find: $dmgmount/$appName"
|
||||||
|
cleanupAndExit 8
|
||||||
|
fi
|
||||||
|
|
||||||
# verify with spctl
|
# verify with spctl
|
||||||
echo "Verifying: $dmgmount/$appName"
|
echo "Verifying: $dmgmount/$appName"
|
||||||
if ! teamID=$(spctl -a -vv "$dmgmount/$appName" 2>&1 | awk '/origin=/ {print $NF }' ); then
|
if ! teamID=$(spctl -a -vv "$dmgmount/$appName" 2>&1 | awk '/origin=/ {print $NF }' ); then
|
||||||
echo "Error verifying $dmgmount/$appName"
|
echo "Error verifying $dmgmount/$appName"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 4
|
||||||
exit 4
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Comparing Team IDs: ($expectedTeamID) $teamID"
|
echo "Comparing Team IDs: ($expectedTeamID) $teamID"
|
||||||
|
|
||||||
if [ "($expectedTeamID)" != "$teamID" ]; then
|
if [ "($expectedTeamID)" != "$teamID" ]; then
|
||||||
echo "Team IDs do not match!"
|
echo "Team IDs do not match!"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 5
|
||||||
exit 5
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for root
|
# check for root
|
||||||
@@ -138,13 +150,11 @@ if [ "$(whoami)" != "root" ]; then
|
|||||||
# not running as root
|
# not running as root
|
||||||
if [ "$DEBUG" -eq 0 ]; then
|
if [ "$DEBUG" -eq 0 ]; then
|
||||||
echo "not running as root, exiting"
|
echo "not running as root, exiting"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 6
|
||||||
exit 6
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "DEBUG enabled, skipping copy and chown steps"
|
echo "DEBUG enabled, skipping copy and chown steps"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 0
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove existing application
|
# remove existing application
|
||||||
@@ -157,10 +167,10 @@ fi
|
|||||||
echo "Copy $dmgmount/$appName to $targetDir"
|
echo "Copy $dmgmount/$appName to $targetDir"
|
||||||
if ! cp -R "$dmgmount/$appName" "$targetDir"; then
|
if ! cp -R "$dmgmount/$appName" "$targetDir"; then
|
||||||
echo "Error while copying!"
|
echo "Error while copying!"
|
||||||
cleanupBeforeExit
|
cleanupAndExit 7
|
||||||
exit 7
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# set ownership to current users
|
# set ownership to current users
|
||||||
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
|
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
|
||||||
if [ -n "$currentUser" ]; then
|
if [ -n "$currentUser" ]; then
|
||||||
@@ -170,6 +180,7 @@ else
|
|||||||
echo "No user logged in, not changing user"
|
echo "No user logged in, not changing user"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# TODO: notify when done
|
||||||
|
|
||||||
# all done!
|
# all done!
|
||||||
cleanupBeforeExit
|
cleanupAndExit 0
|
||||||
exit 0
|
|
||||||
|
|||||||
Reference in New Issue
Block a user