From c37f98181d56a019dacf900249142b37adf042d4 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Wed, 12 Jul 2017 14:27:01 -0400 Subject: [PATCH 1/7] Standardize whitespace Four spaces per indent, no trailing spaces, if/then on single line. --- munkiinabox.sh | 258 ++++++++++++++++++++++++------------------------- 1 file changed, 125 insertions(+), 133 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index b5f85a8..4511913 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -47,12 +47,11 @@ echo "First up: Are you an admin user? Enter your password below:" #This isn't bulletproof, but this is a basic test. sudo whoami > /tmp/quickytest -if - [[ `cat /tmp/quickytest` == "root" ]]; then - ${LOGGER} "Privilege Escalation Allowed, Please Continue." - else - ${LOGGER} "Privilege Escalation Denied, User Cannot Sudo." - exit 6 "You are not an admin user, you need to do this an admin user." +if [[ `cat /tmp/quickytest` == "root" ]]; then + ${LOGGER} "Privilege Escalation Allowed, Please Continue." +else + ${LOGGER} "Privilege Escalation Denied, User Cannot Sudo." + exit 6 "You are not an admin user, you need to do this an admin user." fi ${LOGGER} "Starting up..." @@ -76,24 +75,21 @@ fn_terminate() { } trap 'fn_terminate' SIGINT -if - [[ $osvers -lt 8 ]]; then +if [[ $osvers -lt 8 ]]; then ${LOGGER} "Could not run because the version of the OS does not meet requirements" echo "Sorry, this is for Mac OS 10.8 or later." exit 2 # 10.8+ for the Web Root Location. fi -if - [[ $osvers -lt 10 ]]; then - echo "##################################################" - echo "This script is intended for OS X 10.10 or later. It may work on 10.8 or 10.9, but the ride may be a bit bumpy, and things may not go quite the way the script intended them to go. In short, this is not supported, but it probably won't light anything on fire. Be aware." - echo "##################################################" +if [[ $osvers -lt 10 ]]; then + echo "##################################################" + echo "This script is intended for OS X 10.10 or later. It may work on 10.8 or 10.9, but the ride may be a bit bumpy, and things may not go quite the way the script intended them to go. In short, this is not supported, but it probably won't light anything on fire. Be aware." + echo "##################################################" fi ${LOGGER} "Mac OS X 10.8 or later is installed." -if - [[ $webstatus == *STOPPED* ]]; then +if [[ $webstatus == *STOPPED* ]]; then ${LOGGER} "Could not run because the Web Service is stopped" echo "Please turn on Web Services in Server.app" exit 3 # Sorry, turn on the webserver. @@ -101,148 +97,145 @@ fi ${LOGGER} "Web service is running." -if - [[ $EUID -eq 0 ]]; then - $echo "This script is NOT MEANT to run as root. This script is meant to be run as an admin user. I'm going to quit now. Run me without the sudo, please." +if [[ $EUID -eq 0 ]]; then + $echo "This script is NOT MEANT to run as root. This script is meant to be run as an admin user. I'm going to quit now. Run me without the sudo, please." exit 4 # Running as root. fi #${LOGGER} "Script is running as root." -if - [[ ! -d "${WEBROOT}" ]]; then +if [[ ! -d "${WEBROOT}" ]]; then echo "No web root exists at ${WEBROOT}. This might be because you don't have Server.app installed and configured." exit 5 # Web Root folder doesn't exist. fi -if - [[ ! -f $MUNKILOC/munkiimport ]]; then +if [[ ! -f $MUNKILOC/munkiimport ]]; then cd ${REPOLOC} ${LOGGER} "Grabbing and Installing the Munki Tools Because They Aren't Present" MUNKI_LATEST=$(curl https://api.github.com/repos/munki/munki/releases/latest | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["assets"][0]["browser_download_url"]') curl -L "${MUNKI_LATEST}" -o munki-latest1.pkg -# Write a Choices XML file for the Munki package. Thanks Rich and Greg! - - /bin/cat > "/tmp/com.github.munki-in-a-box.munkiinstall.xml" << 'MUNKICHOICESDONE' - + # Write a Choices XML file for the Munki package. Thanks Rich and Greg! + + /bin/cat > "/tmp/com.github.munki-in-a-box.munkiinstall.xml" << 'MUNKICHOICESDONE' + + - - - attributeSetting - 1 - choiceAttribute - selected - choiceIdentifier - core - - - attributeSetting - 1 - choiceAttribute - selected - choiceIdentifier - admin - - - attributeSetting - 0 - choiceAttribute - selected - choiceIdentifier - app - - - attributeSetting - 0 - choiceAttribute - selected - choiceIdentifier - launchd - + + + attributeSetting + 1 + choiceAttribute + selected + choiceIdentifier + core + + + attributeSetting + 1 + choiceAttribute + selected + choiceIdentifier + admin + + + attributeSetting + 0 + choiceAttribute + selected + choiceIdentifier + app + + + attributeSetting + 0 + choiceAttribute + selected + choiceIdentifier + launchd + MUNKICHOICESDONE - + sudo /usr/sbin/installer -dumplog -verbose -applyChoiceChangesXML "/tmp/com.github.munki-in-a-box.munkiinstall.xml" -pkg "munki-latest1.pkg" -target "/" - + ${LOGGER} "Installed Munki Admin and Munki Core packages" echo "Installed Munki packages" - - else - ${LOGGER} "Munki was already installed, I think, so I'm moving on" - echo "/usr/local/munki/munkiimport existed, so I am not reinstalling. Hope you really had Munki installed..." - + +else + ${LOGGER} "Munki was already installed, I think, so I'm moving on" + echo "/usr/local/munki/munkiimport existed, so I am not reinstalling. Hope you really had Munki installed..." + fi # Check for 10.9 and 10.8 created here by Tim Sutton, for which I owe him a beer. Or six. -if - [[ ! -d /Applications/Xcode.app ]]; then +if [[ ! -d /Applications/Xcode.app ]]; then echo "You need to install the Xcode command line tools. Let me get that for you, it'll just take a minute." - -### -# This section written by Rich Trouton and embedded because he's awesome. Diet Coke++, Rich. -### - -# Installing the Xcode command line tools on 10.7.x through 10.10.x - -osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}') -cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" - -# Installing the latest Xcode command line tools on 10.9.x, 10.10.x or 10.11.x - - if [[ "$osx_vers" -ge 9 ]] ; then - - # Create the placeholder file which is checked by the softwareupdate tool - # before allowing the installation of the Xcode command line tools. - - touch "$cmd_line_tools_temp_file" - - # Find the last listed update in the Software Update feed with "Command Line Tools" in the name - - cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) - - #Install the command line tools - - sudo softwareupdate -i "$cmd_line_tools" -v - - # Remove the temp file - - if [[ -f "$cmd_line_tools_temp_file" ]]; then - rm "$cmd_line_tools_temp_file" - fi - fi - -# Installing the latest Xcode command line tools on 10.7.x and 10.8.x - -# on 10.7/10.8, instead of using the software update feed, the command line tools are downloaded -# instead from public download URLs, which can be found in the dvtdownloadableindex: -# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex - - if [[ "$osx_vers" -eq 7 ]] || [[ "$osx_vers" -eq 8 ]]; then - - if [[ "$osx_vers" -eq 7 ]]; then - DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg - fi - - if [[ "$osx_vers" -eq 8 ]]; then - DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_april_2014.dmg - fi - - TOOLS=clitools.dmg - curl "$DMGURL" -o "$TOOLS" - TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX` - hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse - sudo installer -allowUntrusted -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target / - hdiutil detach "$TMPMOUNT" - rm -rf "$TMPMOUNT" - rm "$TOOLS" - - fi - + + ### + # This section written by Rich Trouton and embedded because he's awesome. Diet Coke++, Rich. + ### + + # Installing the Xcode command line tools on 10.7.x through 10.10.x + + osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}') + cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" + + # Installing the latest Xcode command line tools on 10.9.x, 10.10.x or 10.11.x + + if [[ "$osx_vers" -ge 9 ]] ; then + + # Create the placeholder file which is checked by the softwareupdate tool + # before allowing the installation of the Xcode command line tools. + + touch "$cmd_line_tools_temp_file" + + # Find the last listed update in the Software Update feed with "Command Line Tools" in the name + + cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) + + #Install the command line tools + + sudo softwareupdate -i "$cmd_line_tools" -v + + # Remove the temp file + + if [[ -f "$cmd_line_tools_temp_file" ]]; then + rm "$cmd_line_tools_temp_file" + fi + fi + + # Installing the latest Xcode command line tools on 10.7.x and 10.8.x + + # on 10.7/10.8, instead of using the software update feed, the command line tools are downloaded + # instead from public download URLs, which can be found in the dvtdownloadableindex: + # https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex + + if [[ "$osx_vers" -eq 7 ]] || [[ "$osx_vers" -eq 8 ]]; then + + if [[ "$osx_vers" -eq 7 ]]; then + DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg + fi + + if [[ "$osx_vers" -eq 8 ]]; then + DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_april_2014.dmg + fi + + TOOLS=clitools.dmg + curl "$DMGURL" -o "$TOOLS" + TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX` + hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse + sudo installer -allowUntrusted -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target / + hdiutil detach "$TMPMOUNT" + rm -rf "$TMPMOUNT" + rm "$TOOLS" + + fi + fi ### @@ -292,8 +285,7 @@ sudo chown _www:wheel .htaccess .htpasswd # Create a client installer pkg pointing to this repo. Thanks Nick! #### -if - [[ ! -f /usr/bin/pkgbuild ]]; then +if [[ ! -f /usr/bin/pkgbuild ]]; then ${LOGGER} "Pkgbuild is not installed." echo "Please install Xcode command line tools first." exit 0 # Gotta install the command line tools. @@ -359,7 +351,7 @@ echo "$aLen" "overrides to create" for (( j=0; j Date: Wed, 12 Jul 2017 14:29:55 -0400 Subject: [PATCH 2/7] Use $(..) instead of legacy `..` --- munkiinabox.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index 4511913..29f99f5 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -47,7 +47,7 @@ echo "First up: Are you an admin user? Enter your password below:" #This isn't bulletproof, but this is a basic test. sudo whoami > /tmp/quickytest -if [[ `cat /tmp/quickytest` == "root" ]]; then +if [[ $(cat /tmp/quickytest) == "root" ]]; then ${LOGGER} "Privilege Escalation Allowed, Please Continue." else ${LOGGER} "Privilege Escalation Denied, User Cannot Sudo." @@ -227,7 +227,7 @@ if [[ ! -d /Applications/Xcode.app ]]; then TOOLS=clitools.dmg curl "$DMGURL" -o "$TOOLS" - TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX` + TMPMOUNT=$(/usr/bin/mktemp -d /tmp/clitools.XXXX) hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse sudo installer -allowUntrusted -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target / hdiutil detach "$TMPMOUNT" From 7aca805a8bbcfd40e89ee4742db518ddfb145682 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Wed, 12 Jul 2017 15:04:16 -0400 Subject: [PATCH 3/7] Remove trailing whitespace --- munkiinabox.sh | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index 29f99f5..a69ff0c 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -114,11 +114,11 @@ if [[ ! -f $MUNKILOC/munkiimport ]]; then cd ${REPOLOC} ${LOGGER} "Grabbing and Installing the Munki Tools Because They Aren't Present" MUNKI_LATEST=$(curl https://api.github.com/repos/munki/munki/releases/latest | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["assets"][0]["browser_download_url"]') - + curl -L "${MUNKI_LATEST}" -o munki-latest1.pkg - + # Write a Choices XML file for the Munki package. Thanks Rich and Greg! - + /bin/cat > "/tmp/com.github.munki-in-a-box.munkiinstall.xml" << 'MUNKICHOICESDONE' @@ -159,72 +159,72 @@ if [[ ! -f $MUNKILOC/munkiimport ]]; then MUNKICHOICESDONE - + sudo /usr/sbin/installer -dumplog -verbose -applyChoiceChangesXML "/tmp/com.github.munki-in-a-box.munkiinstall.xml" -pkg "munki-latest1.pkg" -target "/" - + ${LOGGER} "Installed Munki Admin and Munki Core packages" echo "Installed Munki packages" - + else ${LOGGER} "Munki was already installed, I think, so I'm moving on" echo "/usr/local/munki/munkiimport existed, so I am not reinstalling. Hope you really had Munki installed..." - + fi # Check for 10.9 and 10.8 created here by Tim Sutton, for which I owe him a beer. Or six. if [[ ! -d /Applications/Xcode.app ]]; then echo "You need to install the Xcode command line tools. Let me get that for you, it'll just take a minute." - + ### # This section written by Rich Trouton and embedded because he's awesome. Diet Coke++, Rich. ### - + # Installing the Xcode command line tools on 10.7.x through 10.10.x - + osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}') cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" - + # Installing the latest Xcode command line tools on 10.9.x, 10.10.x or 10.11.x - + if [[ "$osx_vers" -ge 9 ]] ; then - + # Create the placeholder file which is checked by the softwareupdate tool # before allowing the installation of the Xcode command line tools. - + touch "$cmd_line_tools_temp_file" - + # Find the last listed update in the Software Update feed with "Command Line Tools" in the name - + cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) - + #Install the command line tools - + sudo softwareupdate -i "$cmd_line_tools" -v - + # Remove the temp file - + if [[ -f "$cmd_line_tools_temp_file" ]]; then rm "$cmd_line_tools_temp_file" fi fi - + # Installing the latest Xcode command line tools on 10.7.x and 10.8.x - + # on 10.7/10.8, instead of using the software update feed, the command line tools are downloaded # instead from public download URLs, which can be found in the dvtdownloadableindex: # https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex - + if [[ "$osx_vers" -eq 7 ]] || [[ "$osx_vers" -eq 8 ]]; then - + if [[ "$osx_vers" -eq 7 ]]; then DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg fi - + if [[ "$osx_vers" -eq 8 ]]; then DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_april_2014.dmg fi - + TOOLS=clitools.dmg curl "$DMGURL" -o "$TOOLS" TMPMOUNT=$(/usr/bin/mktemp -d /tmp/clitools.XXXX) @@ -233,9 +233,9 @@ if [[ ! -d /Applications/Xcode.app ]]; then hdiutil detach "$TMPMOUNT" rm -rf "$TMPMOUNT" rm "$TOOLS" - + fi - + fi ### From ca606151329848f35e3c6ca6f62ab3282b7d92bd Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Wed, 12 Jul 2017 15:06:16 -0400 Subject: [PATCH 4/7] For/do on one line, like if/then --- munkiinabox.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index a69ff0c..039a7be 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -348,8 +348,7 @@ plutil -convert xml1 ~/Library/Preferences/com.googlecode.munki.munkiimport.plis aLen=${#AUTOPKGARRAY[@]} echo "$aLen" "overrides to create" -for (( j=0; j Date: Wed, 12 Jul 2017 15:07:35 -0400 Subject: [PATCH 5/7] Remove unused variables --- munkiinabox.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index 039a7be..a3a56b1 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -23,7 +23,6 @@ REPODIR="${REPOLOC}/${REPONAME}" LOGGER="/usr/bin/logger -t Munki-in-a-Box" MUNKILOC="/usr/local/munki" WEBROOT="/Library/Server/Web/Data/Sites/Default" -PHPROOT="/Library/Server/Web/Config/php" GIT="/usr/bin/git" MANU="/usr/local/munki/manifestutil" TEXTEDITOR="TextWrangler.app" @@ -33,9 +32,7 @@ AUTOPKGRUN="AdobeFlashPlayer.munki AdobeReader.munki Dropbox.munki Firefox.munki AUTOPKGARRAY=($AUTOPKGRUN) DEFAULTS="/usr/bin/defaults" AUTOPKG="/usr/local/bin/autopkg" -MAINPREFSDIR="/Library/Preferences" ADMINUSERNAME="ladmin" -SCRIPTDIR="/usr/local/bin" HTPASSWD="YouNeedToChangeThis" From 5ed56f5aebe4badc9a8f51bbbf0e61e90c1889f2 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Wed, 12 Jul 2017 15:10:31 -0400 Subject: [PATCH 6/7] No $echo var is defined --- munkiinabox.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index a3a56b1..45a7d66 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -95,7 +95,7 @@ fi ${LOGGER} "Web service is running." if [[ $EUID -eq 0 ]]; then - $echo "This script is NOT MEANT to run as root. This script is meant to be run as an admin user. I'm going to quit now. Run me without the sudo, please." + echo "This script is NOT MEANT to run as root. This script is meant to be run as an admin user. I'm going to quit now. Run me without the sudo, please." exit 4 # Running as root. fi From 081fd91f0e1d56c561f23e57256dae2f91698d9b Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Wed, 12 Jul 2017 15:21:01 -0400 Subject: [PATCH 7/7] Catch failed `cd` commands --- munkiinabox.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/munkiinabox.sh b/munkiinabox.sh index 45a7d66..9b16ad8 100644 --- a/munkiinabox.sh +++ b/munkiinabox.sh @@ -108,7 +108,7 @@ fi if [[ ! -f $MUNKILOC/munkiimport ]]; then - cd ${REPOLOC} + cd "${REPOLOC}" || exit 1 ${LOGGER} "Grabbing and Installing the Munki Tools Because They Aren't Present" MUNKI_LATEST=$(curl https://api.github.com/repos/munki/munki/releases/latest | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["assets"][0]["browser_download_url"]') @@ -244,7 +244,7 @@ ${LOGGER} "All Tests Passed! On to the configuration." # Create the repo. -cd "$REPOLOC" +cd "$REPOLOC" || exit 1 mkdir "${REPONAME}" mkdir "${REPONAME}/catalogs" mkdir "${REPONAME}/manifests" @@ -269,7 +269,7 @@ AuthUserFile /Library/Server/Web/Data/Sites/Default/munki_repo/.htpasswd Require valid-user HTPASSWDDONE -cd ${REPONAME} +cd "${REPONAME}" || exit 1 htpasswd -cb .htpasswd munki $HTPASSWD HTPASSAUTH=$(python -c "import base64; print \"Authorization: Basic %s\" % base64.b64encode(\"munki:$HTPASSWD\")") @@ -411,7 +411,7 @@ ${AUTOPKG} run MunkiAdmin.install # Install MunkiReport-PHP #### -cd "${WEBROOT}" +cd "${WEBROOT}" || exit 1 ${GIT} clone https://github.com/munkireport/munkireport-php.git MR_CONFIG="munkireport-php/config.php" MR_BASEURL="https://$HOSTNAME/munkireport-php/index.php?"