Skip to content

Commit 02f5ae0

Browse files
committed
Merge pull request #18 from tbridge/non-root
Completing the non-root branch to make this the new normal.
2 parents 437dd71 + c3c8f32 commit 02f5ae0

File tree

2 files changed

+65
-32
lines changed

2 files changed

+65
-32
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ munki-in-a-box
33

44
Post Munki Install Simple Deployment Script
55

6-
76
The goal of this script is to deploy a basic munki repo in a simple script based on a set of common variables. I have placed defaults in these variables, but they are easily overridden and you should decide where they go.
87

98
This script is based upon the Demonstration Setup Guide for Munki, AutoPKG, and other sources. My sincerest thanks to Greg Neagle, Tim Sutton, Allister Banks, Rich Trouton, Charles Edge, Pepijn Bruienne, the Linde Group and numerous others who have helped me assemble this script. The Mac Admins Community is supportive and awesome.
@@ -20,7 +19,7 @@ This script is based upon the Demonstration Setup Guide for Munki, AutoPKG, and
2019
3) Alter Line 32 to reflect your choice of AutoPKG installs
2120
4) Alter Line 35 to reflect your admin username (ladmin is default)
2221
5) Alter Lines 37-38 to reflect AutoPKG Automation Scripts
23-
6) sudo ./munkiinabox.sh
22+
6) ./munkiinabox.sh
2423

2524
If you do not make changes to the script before running it, the script may not run as intended. Please double-check to make sure that you are comfortable with the variables' values.
2625

@@ -65,6 +64,10 @@ For more information on munkireport-php, please be sure to [visit their document
6564

6665
###Changelog
6766

67+
**NEW in 1.4.0:**
68+
69+
• No more running as root!
70+
6871
**NEW in 1.3.0:**
6972

7073
• Updated deployment technique for Munkireport-php, thanks to A.E. von Bochoven.

munkiinabox.sh

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Munki In A Box
44
# By Tom Bridge, Technolutionary LLC
55

6-
# Version: 1.3.0 - New MunkiReport-PHP
6+
# Version: 1.4.0 - Non-Root Execution
77

88
# This software carries no guarantees, warranties or other assurances that it works. It may wreck your entire environment. That would be bad, mmkay. Backup, test in a VM, and bug report.
99

@@ -13,7 +13,7 @@
1313

1414
# This script is based upon the Demonstration Setup Guide for Munki, AutoPkg, and other sources. My sincerest thanks to Greg Neagle, Tim Sutton, Allister Banks, Rich Trouton, Charles Edge, Hannes Juutilainen, Sean Kaiser, Peter Bukowinski, Elliot Jordan, The Linde Group and numerous others who have helped me assemble this script.
1515

16-
# Pre-Reqs for this script: 10.8/Server 2, 10.9/Server 3 or 10.10/Server 4. Web Services should be turned on and PHP should be enabled.
16+
# Pre-Reqs for this script: 10.10/Server 4 or 10.11/Server 5. Web Services should be turned on and PHP should be enabled. This script might work with 10.8 or later, but I'm only testing it on 10.10 or later.
1717

1818
# Establish our Basic Variables:
1919

@@ -41,6 +41,20 @@ SCRIPTDIR="/usr/local/bin"
4141

4242
echo "Welcome to Munki-in-a-Box. We're going to get things rolling here with a couple of tests"'!'
4343

44+
echo "First up: Are you an admin user? Enter your password below:"
45+
46+
#Let's see if this works...
47+
#This isn't bulletproof, but this is a basic test.
48+
sudo whoami > /tmp/quickytest
49+
50+
if
51+
[[ `cat /tmp/quickytest` == "root" ]]; then
52+
${LOGGER} "Privilege Escalation Allowed, Please Continue."
53+
else
54+
${LOGGER} "Privilege Escalation Denied, User Cannot Sudo."
55+
exit 6 "You are not an admin user, you need to do this an admin user."
56+
fi
57+
4458
${LOGGER} "Starting up..."
4559

4660
echo "$webstatus"
@@ -69,6 +83,13 @@ if
6983
exit 2 # 10.8+ for the Web Root Location.
7084
fi
7185

86+
if
87+
[[ $osvers -lt 10 ]]; then
88+
echo "##################################################"
89+
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."
90+
echo "##################################################"
91+
fi
92+
7293
${LOGGER} "Mac OS X 10.8 or later is installed."
7394

7495
if
@@ -81,12 +102,12 @@ fi
81102
${LOGGER} "Web service is running."
82103

83104
if
84-
[[ $EUID -ne 0 ]]; then
85-
$echo "This script must run as root. Type sudo $0, then press [ENTER]."
86-
exit 4 # Not running as root.
105+
[[ $EUID -eq 0 ]]; then
106+
$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."
107+
exit 4 # Running as root.
87108
fi
88109

89-
${LOGGER} "Script is running as root."
110+
#${LOGGER} "Script is running as root."
90111

91112
if
92113
[[ ! -d "${WEBROOT}" ]]; then
@@ -102,9 +123,12 @@ fi
102123

103124
if
104125
[[ ! -f $MUNKILOC/munkiimport ]]; then
126+
cd ${REPOLOC}
105127
${LOGGER} "Grabbing and Installing the Munki Tools Because They Aren't Present"
106-
curl -L "https://munkibuilds.org/munkitools2-latest.pkg" -o "$REPOLOC/munkitools2.pkg"
107-
128+
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"]')
129+
130+
curl -L "${MUNKI_LATEST}" -o munki-latest1.pkg
131+
108132
# Write a Choices XML file for the Munki package. Thanks Rich and Greg!
109133

110134
/bin/cat > "/tmp/com.github.munki-in-a-box.munkiinstall.xml" << 'MUNKICHOICESDONE'
@@ -147,7 +171,7 @@ if
147171
</plist>
148172
MUNKICHOICESDONE
149173

150-
/usr/sbin/installer -dumplog -verbose -applyChoiceChangesXML "/tmp/com.github.munki-in-a-box.munkiinstall.xml" -pkg "$REPOLOC/munkitools2.pkg" -target "/"
174+
sudo /usr/sbin/installer -dumplog -verbose -applyChoiceChangesXML "/tmp/com.github.munki-in-a-box.munkiinstall.xml" -pkg "munki-latest1.pkg" -target "/"
151175

152176
${LOGGER} "Installed Munki Admin and Munki Core packages"
153177
echo "Installed Munki packages"
@@ -188,7 +212,7 @@ cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in
188212

189213
#Install the command line tools
190214

191-
softwareupdate -i "$cmd_line_tools" -v
215+
sudo softwareupdate -i "$cmd_line_tools" -v
192216

193217
# Remove the temp file
194218

@@ -217,7 +241,7 @@ cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in
217241
curl "$DMGURL" -o "$TOOLS"
218242
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX`
219243
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse
220-
installer -allowUntrusted -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target /
244+
sudo installer -allowUntrusted -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target /
221245
hdiutil detach "$TMPMOUNT"
222246
rm -rf "$TMPMOUNT"
223247
rm "$TOOLS"
@@ -279,7 +303,7 @@ echo "Client install pkg is created. It's in the base of the repo."
279303
AUTOPKG_LATEST=$(curl https://api.github.com/repos/autopkg/autopkg/releases | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["assets"][0]["browser_download_url"]')
280304
curl -L "${AUTOPKG_LATEST}" -o autopkg-latest1.pkg
281305

282-
installer -pkg autopkg-latest1.pkg -target /
306+
sudo installer -pkg autopkg-latest1.pkg -target /
283307

284308
${LOGGER} "AutoPkg Installed"
285309
echo "AutoPkg Installed"
@@ -292,6 +316,11 @@ echo "AutoPkg Installed"
292316
${DEFAULTS} write com.github.autopkg MUNKI_REPO "$REPODIR"
293317

294318
${AUTOPKG} repo-add http://github.com/autopkg/recipes.git
319+
${AUTOPKG} repo-add rtrouton-recipes
320+
${AUTOPKG} repo-add jleggat-recipes
321+
${AUTOPKG} repo-add timsutton-recipes
322+
${AUTOPKG} repo-add nmcspadden-recipes
323+
${AUTOPKG} repo-add jessepeterson-recipes
295324

296325
${DEFAULTS} write com.googlecode.munki.munkiimport editor "${TEXTEDITOR}"
297326
${DEFAULTS} write com.googlecode.munki.munkiimport repo_path "${REPODIR}"
@@ -303,10 +332,10 @@ echo "AutoPkg Configured"
303332

304333
# This makes AutoPkg useful on future runs for the admin user defined at the top. It copies & creates preferences for autopkg and munki into their home dir's Library folder, as well as transfers ownership for the ~/Library/AutoPkg folders to them.
305334

306-
cp /var/root/Library/Preferences/com.googlecode.munki.munkiimport.plist ~/Library/Preferences
307-
cp /var/root/Library/Preferences/com.github.autopkg.plist ~/Library/Preferences
308-
chmod 660 ~/Library/Preferences/com.googlecode.munki.munkiimport.plist
309-
chmod 660 ~/Library/Preferences/com.github.autopkg.plist
335+
#cp /var/root/Library/Preferences/com.googlecode.munki.munkiimport.plist ~/Library/Preferences
336+
#cp /var/root/Library/Preferences/com.github.autopkg.plist ~/Library/Preferences
337+
#chmod 660 ~/Library/Preferences/com.googlecode.munki.munkiimport.plist
338+
#chmod 660 ~/Library/Preferences/com.github.autopkg.plist
310339

311340
plutil -convert xml1 ~/Library/Preferences/com.googlecode.munki.munkiimport.plist
312341

@@ -320,8 +349,8 @@ ${LOGGER} "AutoPkg Run"
320349
echo "AutoPkg has run"
321350

322351
# Bring it on home to the all-powerful, all-wise, local admin... (Thanks Luis)
323-
324-
chown -R ${ADMINUSERNAME} ~/Library/AutoPkg
352+
# To be deleted if this rootless thing works.
353+
# chown -R ${ADMINUSERNAME} ~/Library/AutoPkg
325354

326355
####
327356
# Create new site_default manifest and add imported packages to it
@@ -352,8 +381,6 @@ done
352381
# Install AutoPkgr from the awesome Linde Group!
353382
####
354383

355-
${AUTOPKG} repo-add rtrouton-recipes
356-
357384
${AUTOPKG} run AutoPkgr.install
358385

359386
${LOGGER} "AutoPkgr Installed"
@@ -373,7 +400,7 @@ com.github.autopkg.munki.textwrangler
373400
com.github.autopkg.munki.munkitools2
374401
com.github.autopkg.munki.makecatalogs" > /Users/$ADMINUSERNAME/Library/Application\ Support/AutoPkgr/recipe_list.txt
375402

376-
chown -R $ADMINUSERNAME /Users/$ADMINUSERNAME/Library/Application\ Support/AutoPkgr
403+
# chown -R $ADMINUSERNAME /Users/$ADMINUSERNAME/Library/Application\ Support/AutoPkgr
377404

378405
####
379406
# Install Munki Admin App by the amazing Hannes Juutilainen
@@ -405,17 +432,17 @@ MR_BASEURL="https://$HOSTNAME/munkireport-php/index.php?"
405432
MR_DB_DIR="/var/munkireport"
406433

407434
# Create database directory
408-
mkdir -p $MR_DB_DIR
409-
chmod +a "_www allow add_file,delete_child" $MR_DB_DIR
435+
sudo mkdir -p $MR_DB_DIR
436+
sudo chmod +a "_www allow add_file,delete_child" $MR_DB_DIR
410437

411438
echo "<?php" > ${MR_CONFIG}
412439
echo >> ${MR_CONFIG}
413440
echo "\$conf['pdo_dsn'] = 'sqlite:$MR_DB_DIR/db.sqlite';" >> ${MR_CONFIG}
414441

415-
echo "short_open_tag = On" >> "${PHPROOT}/php.ini"
442+
sudo echo "short_open_tag = On" >> "${PHPROOT}/php.ini"
443+
# This creates a user "root" with password "root"
416444
echo "\$auth_config['root'] = '\$P\$BSQDsvw8vyCZxzlPaEiXNoP6CIlwzt/';" >> ${MR_CONFIG}
417445

418-
# This creates a user "root" with password "root"
419446
# Now to download the pkgsinfo file into the right place and add it to the catalogs and site_default manifest:
420447

421448
echo "Downloading available modules"
@@ -445,15 +472,18 @@ chmod -R a+rX,g+w "${REPONAME}"
445472
chown -R ${ADMINUSERNAME}:admin "${REPONAME}"
446473

447474
rm "$REPOLOC/autopkg-latest1.pkg"
448-
rm "$REPOLOC/munkitools2.pkg"
475+
rm "$REPOLOC/munki-latest1.pkg"
449476
rm "$REPOLOC/munkireport-"*.pkg
450477

451478
${LOGGER} "I put my toys away."
452479

480+
echo "#########"
453481
echo "Thank you for flying Munki in a Box Air. You now have a working repo, go forth and install your clients."
454-
455-
echo "MunkiAdmin and AutoPkgr are ready to go, please launch them to complete their setup. MunkiAdmin needs to know where your repo is, and AutoPkgr needs to have its helper tool installed."
456-
482+
echo "#########"
483+
echo "MunkiAdmin and AutoPkgr are ready to go, please launch them to complete their setup."
484+
echo "#########"
485+
echo "MunkiAdmin needs to know where your repo is, and AutoPkgr needs to have its helper tool installed."
486+
echo "#########"
457487
echo "Be sure to login to MunkiReport-PHP at http://localhost/munkireport-php and initiate the database, as well change the login password."
458488

459-
exit 0
489+
exit 0

0 commit comments

Comments
 (0)