From 9dd5fc2df16d4cb912924042e832dabe67e14257 Mon Sep 17 00:00:00 2001 From: Armin Briegel <1933192+scriptingosx@users.noreply.github.com> Date: Fri, 8 May 2020 09:21:27 +0200 Subject: [PATCH] cleaned up some DEBUG related code --- Installomator.sh | 16 +++++++++----- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Installomator.sh b/Installomator.sh index c525e94..148b8c4 100755 --- a/Installomator.sh +++ b/Installomator.sh @@ -18,7 +18,7 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin # set to 0 for production, 1 for debugging # while debugging, items will be downloaded to the parent directory of this script # also no actual installation will be performed -DEBUG=1 +DEBUG=1 # behavior when blocking processes are found BLOCKING_PROCESS_ACTION=prompt_user @@ -718,6 +718,12 @@ getAppVersion() { } checkRunningProcesses() { + # don't check in DEBUG mode + if [[ $DEBUG -ne 0 ]]; then + echo "DEBUG mode, not checking for blocking processes" + return + fi + # try at most 3 times for i in {1..3}; do countedProcesses=0 @@ -809,7 +815,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir # set ownership to current user - if [ -n "$currentUser" ]; then + if [ "$currentUser" != "loginwindow" ]; then echo "Changing owner to $currentUser" chown -R "$currentUser" "$targetDir/$appName" else @@ -984,7 +990,7 @@ if [[ -z $blockingProcesses ]]; then fi # determine tmp dir -if [ "$DEBUG" -eq 1 ]; then +if [ "$DEBUG" -ne 0 ]; then # for debugging use script dir as working directory tmpDir=$(dirname "$0") else @@ -1003,7 +1009,7 @@ fi # check if this is an Update getAppVersion if [[ -n $appVersion ]]; then - if [[ $DEBUG == 0 ]]; then + if [[ $DEBUG -eq 0 ]]; then if runUpdateTool; then cleanupAndExit 0 fi # otherwise continue @@ -1028,7 +1034,7 @@ fi # download the archive -if [ -f "$archiveName" ] && [ "$DEBUG" -eq 1 ]; then +if [ -f "$archiveName" ] && [ "$DEBUG" -ne 0 ]; then echo "$archiveName exists and DEBUG enabled, skipping download" else # download the dmg diff --git a/README.md b/README.md index 8e8aaac..325628f 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,60 @@ The script started out as a pure `sh` script, and when I needed arrays I 'switch Keeping the script as a `zsh` allows you to paste it into your management system's interface (and disable the DEBUG mode) and use it without requiring any other installations. -## +## How to use +### Interactively in the command line +The script will require at least one argument. If more than one argument is given, it will _ignore_ all but the last argument. +The argument can be `version` or `longversion` which will print the script's version. +``` +> ./Installomator.sh version +0.1 +> ./Installomator.sh longversion +Installomater: version 0.1 (20200506) +``` + +Other than the version arguments, the argument can be any of the labels listed in the Labels.txt file. Each of the labels will download and install the latest version of the application, or suite of applications. Since the script will have to run the `installer` command or copy the application to the `/Applications` folder, it will have to be run as root. + +``` +> sudo ./Installomator.sh desktoppr +``` + +### Debug mode + +There is a variable named `DEBUG` which is set in line 21 of the script. When `DEBUG` is set to `1` (default) no actions that wousld actually modify the current system are taken. This is useful for testing most of the actions in the script, but obviously not all of them. + +Also when the `DEBUG` variable is `1`, downloaded archives and extracted files will be written to the script's directory, rather than a temporary directory, which can make debugging easier. + +_Always remember_ to change the `DEBUG` variable to `0` when deploying. + +### Use Installomator with Jamf Pro + +In Jamf Pro, create a new 'Script' and paste the contents of `Installomator.sh` into the 'Script Contents' area. Under 'Options' you can change the parameter label for argument 4 to 'Application Label.' + +Then you can use the Installomator script in a policy and choose the application to install by setting the label for argument 4. + +## What it does + +When it runs with a known label, the script will perform the following: + +- when the application is running, prompt the user to quit or cancel +- download the latest version from the vendor +- dmg or zip archives: + - extract the application and copy it to /Applications + - change the owner of the application to the current user +- pkg files: + - when necessary, extract the pkg from the enclosing archive + - install the pkg with the `installer` tool +- clean up the downloaded files +- notify the user + +## Configuring the script + +As of now there are two settings that are meant to configured when deploying the script. + +### Debug mode + +The first is the `DEBUG` variable. When this is set to `1` the script will _not_ perform any changes to the current system. In other words, no application will be copied to the target directory and no `installer` command be performed. This is useful to test the download and verification process