Skip to content

Instantly share code, notes, and snippets.

@bryanzak
Last active May 25, 2016 01:16
Show Gist options
  • Save bryanzak/9346880 to your computer and use it in GitHub Desktop.
Save bryanzak/9346880 to your computer and use it in GitHub Desktop.
Munki Syncer - LaunchDaemon and script to auto sync a local munki_repo from a master on an smb server elsewhere within your organization once a day at a specified time. The server mount point could be automounted etc, but this script demonstrates mounting it dynamically if needed
#!/bin/bash
SERVER_MOUNT_PT="/Volumes/Munki"
SERVER_URL="//SERVICEACCOUNTNAME:[email protected]/Munki"
we_mounted="false"
MUNKI_MASTER="/Volumes/Munki/Master Repository/munki_repo/"
MUNKI_LOCAL="/Users/Shared/munki_repo"
# important, trailing slash must be on source and must not be on destination
MountServer()
{
if [ ! -d "${SERVER_MOUNT_PT}" ]; then
# the sysctl is needed to get smbfs mounting from root
sysctl -w net.smb.fs.kern_ntlmssp=1
mkdir "${SERVER_MOUNT_PT}"
mount -t smbfs "${SERVER_URL}" "${SERVER_MOUNT_PT}"
result=$?
if [ "$result" == 0 ]; then
we_mounted="true"
else
rmdir "${SERVER_MOUNT_PT}"
echo "### error ${result} trying to mount moof, exiting"
exit ${result}
fi
fi
}
UnmountServer()
{
if [ "${we_mounted}" == "true" ]; then
umount "${SERVER_MOUNT_PT}"
fi
}
MunkiSyncEverything()
{
rsync --exclude '.DS_Store' --delete-before --recursive --owner --group --times --progress "${MUNKI_MASTER}" "${MUNKI_LOCAL}"
}
MunkiUpdatePermissions()
{
# probably not needed, but does not hurt
echo "Updating munki_repo permissions..."
chmod -R 777 "${MUNKI_LOCAL}"
}
echo "### $(date) munki sync begin "
MountServer
MunkiSyncEverything
MunkiUpdatePermissions
UnmountServer
echo "### $(date) munki sync end "
exit 0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.yourorg.munkisyncer</string>
<key>ProgramArguments</key>
<array>
<string>/private/var/root/Library/yourorg/MunkiSyncer.sh</string>
</array>
<key>StandardOutPath</key>
<string>/var/log/munkisyncer.log</string>
<key>StandardErrorPath</key>
<string>/var/log/munkisyncer.log</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>17</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
</plist>
@WardsParadox
Copy link

No longer functional on OSX 10.10.3. Errors out on lines 12-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment