Skip to content

Instantly share code, notes, and snippets.

@bryanzak
Last active August 29, 2015 13:57
Show Gist options
  • Save bryanzak/9382064 to your computer and use it in GitHub Desktop.
Save bryanzak/9382064 to your computer and use it in GitHub Desktop.
A very simple example of how we configure Munki based on some information encoded in the computer name and some input from the building tech doing the configuration. This script is normally sent via ARD
#!/bin/bash
# Munki: Configure
role="school"
# valid options: school, staff, lab, classroom, cart
# #################################################
# set manifest based on school number
# OPS naming convention
# CXXX-MD-xxxxxxx
# Digit 1: C=Computer P=Printer, N=Network Device (AP, etc)
# Digits 2,3,4: three digit school number
# Digit 5: a dash
# Digit 6: M=Macintosh W=Windows
# Digit 7: D=Desktop, L=Laptop, S=server
# Digit 8: a dash
# Digits 9-15: determined by building tech, for example LAB-001, 101-BP1, etc. Generally Room/Computer # or Teacher Initials
computer_name=$(/usr/sbin/scutil --get ComputerName)
school=$(echo "${computer_name}" | awk '{print substr($1,2,3)}')
manifest="$school/$school-$role" # if school does not have a manifest, change to manifest="ops-base"
# Munki server address changes for each school
case "${school}" in
043 ) server="C043-MD-BTS-001.omahaps.ops.org" ;; # Belvedere
044 ) server="C044-MD-BTS-001.omahaps.ops.org" ;; # Benson West
045 ) server="C045-MS-MUNKI-1.omahaps.ops.org" ;; # Bancroft
# and so one for each school number
# each school can be using whatever computer they want for their munki server
* ) server=""; echo "### WARNING: no server for ${school}, using ${server}"; echo; ;;
esac
munki_server="http://${server}/munki_repo"
# only teachers will get managed software update popping up once a day if needed
if [ "${role}" == "staff" ]; then
suppressnotification=false
else
suppressnotification=true
fi
# -- write out the settings -----------------------------
defaults write /Library/Preferences/ManagedInstalls SoftwareRepoURL "${munki_server}"
defaults write /Library/Preferences/ManagedInstalls ClientIdentifier "${manifest}"
defaults write /Library/Preferences/ManagedInstalls SuppressUserNotification -bool "${suppressnotification}"
defaults read /Library/Preferences/ManagedInstalls
#!/bin/bash
# Munki Logs: Quick Check
LOGFILE="/Library/Managed Installs/Logs/ManagedSoftwareUpdate.log"
if [ -f "${LOGFILE}" ]; then
lastline=$(tail -1 "${LOGFILE}")
hadEnding=$(echo "${lastline}" | grep Ending)
hasSkipping=$(echo "${lastline}" | grep Skipping)
hasIdle=$(echo "${lastline}" | grep "System not idle")
if [[ -n "${hadEnding}" ]] || [[ -n "${hasSkipping}" ]] || [[ -n "${hasIdle}" ]]; then
echo "last update OK: ${lastline:0:20}"
else
echo "### ERROR? In Progress? LASTLINE=${lastline}"
fi
else
if [ "`arch`" == "i386" ]; then
if [ ! -e "/usr/local/munki/managedsoftwareupdate" ]; then
echo "*** Munki not installed"
else
echo "!!! Installed, but not restarted: uptime=$(uptime)"
fi
else
echo "powerpc machine"
fi
fi
exit 0
#!/bin/bash
LOGFILE="/Library/Managed Installs/Logs/ManagedSoftwareUpdate.log"
if [ -f "${LOGFILE}" ]; then
tail -150 "${LOGFILE}"
else
echo "### no activity log"
fi
#!/bin/bash
LOGFILE="/Library/Managed Installs/Logs/errors.log"
LOGFILE0="/Library/Managed Installs/Logs/errors.log.0"
echo "### RECENT ERRORS ------------------------------------------"
if [ -f "${LOGFILE}" ]; then
tail -10 "${LOGFILE}"
elif [ -f "${LOGFILE0}" ]; then
tail -10 "${LOGFILE0}"
else
echo "### no error log"
fi
echo
echo "### RECENT WARNINGS ----------------------------------------"
LOGFILE="/Library/Managed Installs/Logs/warnings.log"
if [ -f "${LOGFILE}" ]; then
tail -10 "${LOGFILE}"
else
echo "### no warning log"
fi
echo
echo "### RECENT INSTALLS ----------------------------------------"
LOGFILE="/Library/Managed Installs/Logs/install.log"
if [ -f "${LOGFILE}" ]; then
tail -20 "${LOGFILE}"
else
echo "### no activity log"
fi
echo
echo "### RECENT ACTIVITY ----------------------------------------"
LOGFILE="/Library/Managed Installs/Logs/ManagedSoftwareUpdate.log"
if [ -f "${LOGFILE}" ]; then
tail -40 "${LOGFILE}"
else
echo "### no activity log"
fi
#!/bin/bash
# Munki: Set Manifest
manifest="123/123-staff"
defaults write /Library/Preferences/ManagedInstalls ClientIdentifier "$manifest"
#!/bin/bash
# Munki: Set Server
munki_server="http://CXXX-MS-XXX-XXX/munki_repo"
defaults write /Library/Preferences/ManagedInstalls SoftwareRepoURL "$munki_server"
#!/bin/bash
# Munki: Set Software Update - Apple
# change the true below to false to stop using Apple SU with Munki
defaults write /Library/Preferences/ManagedInstalls InstallAppleSoftwareUpdates -bool true
defaults delete /Library/Preferences/ManagedInstalls SoftwareUpdateServerURL 2> /dev/null
exit 0
#!/bin/bash
# Munki: Set Software Update - LDS
defaults write /Library/Preferences/ManagedInstalls InstallAppleSoftwareUpdates -bool true
school=$(/usr/sbin/scutil --get ComputerName | awk '{print substr($1,2,3)}')
mac_vers=$(sw_vers -productVersion)
fqdn="" # ".omahaps.ops.org"
write_sus()
{
defaults write /Library/Preferences/ManagedInstalls SoftwareUpdateServerURL "http://c$school-ws-lds-001$fqdn:8084/content/catalogs/others/$1"
}
case $mac_vers in
10.[0-4]* ) echo "Mac OS X $mac_vers is not supported" ; exit 1 ;;
10.[5]* ) write_sus index-leopard.merged-1.sucatalog ;;
10.[6]* ) write_sus index-leopard-snowleopard.merged-1.sucatalog ;;
10.[7]* ) write_sus index-lion-snowleopard-leopard.merged-1.sucatalog ;;
10.[8]* ) write_sus index-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog ;;
10.[9]* ) write_sus index-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog ;;
esac
echo "Current Munki SUS: $(defaults read /Library/Preferences/ManagedInstalls SoftwareUpdateServerURL 2> /dev/null)"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment