mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 21:02:46 +00:00
Merge pull request #278 from samess-flowers/dev
Move root user check forward and add in debug mode 2 to replicate lost functionality
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## v9?
|
## v9?
|
||||||
|
|
||||||
|
- We have moved the root check to the beginning of the script, and improved DEBUG handling with two different modes. `DEBUG=0` is still for production, and `1` is still for the DEBUG we previously knew downloading to the directory it is running from, but `2` will download to temporary folder, will detect updates, but will not install anything, but it will notify the user (almost as running the script without root before).
|
||||||
|
|
||||||
## v8.0
|
## v8.0
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ versionKey="CFBundleShortVersionString"
|
|||||||
# get current user
|
# get current user
|
||||||
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
|
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
|
||||||
|
|
||||||
|
# MARK: check for root
|
||||||
|
if [[ "$(whoami)" != "root" && "$DEBUG" -ne 2 ]]; then
|
||||||
|
# not running as root
|
||||||
|
cleanupAndExit 6 "not running as root, exiting"
|
||||||
|
fi
|
||||||
|
|
||||||
# MARK: labels in case statement
|
# MARK: labels in case statement
|
||||||
case $label in
|
case $label in
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ cleanupAndExit() { # $1 = exit code, $2 message
|
|||||||
if [[ -n $2 && $1 -ne 0 ]]; then
|
if [[ -n $2 && $1 -ne 0 ]]; then
|
||||||
printlog "ERROR: $2"
|
printlog "ERROR: $2"
|
||||||
fi
|
fi
|
||||||
if [ "$DEBUG" -eq 0 ]; then
|
if [ "$DEBUG" -ne 1 ]; then
|
||||||
# remove the temporary working directory when done
|
# remove the temporary working directory when done
|
||||||
printlog "Deleting $tmpDir"
|
printlog "Deleting $tmpDir"
|
||||||
rm -Rf "$tmpDir"
|
rm -Rf "$tmpDir"
|
||||||
@@ -198,9 +198,9 @@ getAppVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkRunningProcesses() {
|
checkRunningProcesses() {
|
||||||
# don't check in DEBUG mode
|
# don't check in DEBUG mode 1
|
||||||
if [[ $DEBUG -ne 0 ]]; then
|
if [[ $DEBUG -eq 1 ]]; then
|
||||||
printlog "DEBUG mode, not checking for blocking processes"
|
printlog "DEBUG mode 1, not checking for blocking processes"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -305,9 +305,9 @@ reopenClosedProcess() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# don't reopen in DEBUG mode
|
# don't reopen in DEBUG mode 1
|
||||||
if [[ $DEBUG -ne 0 ]]; then
|
if [[ $DEBUG -eq 1 ]]; then
|
||||||
printlog "DEBUG mode, not reopening anything"
|
printlog "DEBUG mode 1, not reopening anything"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -364,16 +364,16 @@ installAppWithPath() { # $1: path to app to install in $targetDir
|
|||||||
printlog "Downloaded version of $name is $appNewVersion (replacing version $appversion)."
|
printlog "Downloaded version of $name is $appNewVersion (replacing version $appversion)."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# skip install for DEBUG
|
# skip install for DEBUG 1
|
||||||
if [ "$DEBUG" -ne 0 ]; then
|
if [ "$DEBUG" -eq 1 ]; then
|
||||||
printlog "DEBUG enabled, skipping remove, copy and chown steps"
|
printlog "DEBUG mode 1 enabled, skipping remove, copy and chown steps"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for root
|
# skip install for DEBUG 2
|
||||||
if [ "$(whoami)" != "root" ]; then
|
if [ "$DEBUG" -eq 2 ]; then
|
||||||
# not running as root
|
printlog "DEBUG mode 2 enabled, exiting"
|
||||||
cleanupAndExit 6 "not running as root, exiting"
|
cleanupAndExit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test if variable CLIInstaller is set
|
# Test if variable CLIInstaller is set
|
||||||
@@ -485,16 +485,16 @@ installFromPKG() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# skip install for DEBUG
|
# skip install for DEBUG 1
|
||||||
if [ "$DEBUG" -ne 0 ]; then
|
if [ "$DEBUG" -eq 1 ]; then
|
||||||
printlog "DEBUG enabled, skipping installation"
|
printlog "DEBUG enabled, skipping installation"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for root
|
# skip install for DEBUG 2
|
||||||
if [ "$(whoami)" != "root" ]; then
|
if [ "$DEBUG" -eq 2 ]; then
|
||||||
# not running as root
|
printlog "DEBUG mode 2 enabled, exiting"
|
||||||
cleanupAndExit 6 "not running as root, exiting"
|
cleanupAndExit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install pkg
|
# install pkg
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
|||||||
|
|
||||||
# NOTE: adjust these variables:
|
# NOTE: adjust these variables:
|
||||||
|
|
||||||
# set to 0 for production, 1 for debugging
|
# set to 0 for production, 1 or 2 for debugging
|
||||||
# while debugging, items will be downloaded to the parent directory of this script
|
# while debugging, items will be downloaded to the parent directory of this script
|
||||||
# also no actual installation will be performed
|
# also no actual installation will be performed
|
||||||
|
# debug mode 1 will download to the directory the script is run in, but will not check version
|
||||||
|
# debug mode 2 will download to the temp directory, check for blocking processes, check version, but will not install anything or remove the current version
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
|
|
||||||
# notify behavior
|
# notify behavior
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ if [[ -z $blockingProcesses ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# MARK: determine tmp dir
|
# MARK: determine tmp dir
|
||||||
if [ "$DEBUG" -ne 0 ]; then
|
if [ "$DEBUG" -eq 1 ]; then
|
||||||
# for debugging use script dir as working directory
|
# for debugging use script dir as working directory
|
||||||
tmpDir=$(dirname "$0")
|
tmpDir=$(dirname "$0")
|
||||||
else
|
else
|
||||||
@@ -124,7 +124,7 @@ fi
|
|||||||
if [[ -n $appNewVersion ]]; then
|
if [[ -n $appNewVersion ]]; then
|
||||||
printlog "Latest version of $name is $appNewVersion"
|
printlog "Latest version of $name is $appNewVersion"
|
||||||
if [[ $appversion == $appNewVersion ]]; then
|
if [[ $appversion == $appNewVersion ]]; then
|
||||||
if [[ $DEBUG -eq 0 ]]; then
|
if [[ $DEBUG -ne 1 ]]; then
|
||||||
printlog "There is no newer version available."
|
printlog "There is no newer version available."
|
||||||
if [[ $INSTALL != "force" ]]; then
|
if [[ $INSTALL != "force" ]]; then
|
||||||
message="$name, version $appNewVersion, is the latest version."
|
message="$name, version $appNewVersion, is the latest version."
|
||||||
@@ -135,7 +135,7 @@ if [[ -n $appNewVersion ]]; then
|
|||||||
cleanupAndExit 0 "No newer version."
|
cleanupAndExit 0 "No newer version."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printlog "DEBUG mode enabled, not exiting, but there is no new version of app."
|
printlog "DEBUG mode 1 enabled, not exiting, but there is no new version of app."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -145,7 +145,7 @@ fi
|
|||||||
# MARK: check if this is an Update and we can use updateTool
|
# MARK: check if this is an Update and we can use updateTool
|
||||||
if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
|
if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
|
||||||
printlog "appversion & updateTool"
|
printlog "appversion & updateTool"
|
||||||
if [[ $DEBUG -eq 0 ]]; then
|
if [[ $DEBUG -ne 1 ]]; then
|
||||||
if runUpdateTool; then
|
if runUpdateTool; then
|
||||||
finishing
|
finishing
|
||||||
cleanupAndExit 0
|
cleanupAndExit 0
|
||||||
@@ -154,13 +154,13 @@ if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
|
|||||||
cleanupAndExit 0
|
cleanupAndExit 0
|
||||||
fi # otherwise continue
|
fi # otherwise continue
|
||||||
else
|
else
|
||||||
printlog "DEBUG mode enabled, not running update tool"
|
printlog "DEBUG mode 1 enabled, not running update tool"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# MARK: download the archive
|
# MARK: download the archive
|
||||||
if [ -f "$archiveName" ] && [ "$DEBUG" -ne 0 ]; then
|
if [ -f "$archiveName" ] && [ "$DEBUG" -eq 1 ]; then
|
||||||
printlog "$archiveName exists and DEBUG enabled, skipping download"
|
printlog "$archiveName exists and DEBUG mode 1 enabled, skipping download"
|
||||||
else
|
else
|
||||||
# download the dmg
|
# download the dmg
|
||||||
printlog "Downloading $downloadURL to $archiveName"
|
printlog "Downloading $downloadURL to $archiveName"
|
||||||
|
|||||||
Reference in New Issue
Block a user