Created
November 4, 2017 19:23
-
-
Save MichalMMac/5e8856f781ab64cb46226ebf20a3f74f to your computer and use it in GitHub Desktop.
Import SUS configdata updates to Munki repo as unattended
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: MichalM.Mac | |
# Script gets list of all Apple update from Reposado server. | |
# Then it selects only those whose name contains 'Configuration Data' or ConfigData. | |
# Such updates are imported to Munki as an apple-update items with unattended install key. | |
readonly APPLEMETA_MUNKI_SUBDIR="apple/swupdateconfig/" | |
readonly APPLEMETA_MUNKI_DIR="/repos/munki/pkgsinfo/${APPLEMETA_MUNKI_SUBDIR}" | |
readonly UNIQUE_ID="server" | |
readonly SSH_PARAMS="-p 22022" | |
readonly SSH_URL="user@server" | |
readonly SSH_REMOTE_COMMAND="sudo -u reposado /opt/reposado/code/repoutil --products" | |
function log_to_syslog() { | |
local message_to_log="$1" | |
local log_level="$2" | |
syslog -s -k Facility "$UNIQUE_ID" Level "$log_level" Sender "$UNIQUE_ID" Message "$message_to_log" | |
echo "$message_to_log" | |
} | |
function import_to_munki() { | |
local idnum="$1" | |
if [ ! -f "${APPLEMETA_MUNKI_DIR}/${idnum}-1.0.plist" ]; then | |
log_to_syslog "Adding ${idnum} to Munki repo" "Notice" | |
/usr/local/munki/munkiimport --apple-update "$idnum" \ | |
--catalog production \ | |
--unattended_install \ | |
--displayname "Apple Configuration Data" \ | |
--description "Apple Configuration Data ${idnum}" \ | |
--subdirectory "$APPLEMETA_MUNKI_SUBDIR" \ | |
--developer "Apple" \ | |
--category "Apple" \ | |
--nointeractive | |
else | |
echo "Update ${idnum} is already in Munki repo" | |
fi | |
} | |
function main() { | |
# Get list of available Apple updates from Reposado server | |
local list_of_updates=$(ssh "${SSH_PARAMS}" "${SSH_URL}" "${SSH_REMOTE_COMMAND}" | egrep '^.*(Configuration Data|ConfigData)') | |
if [ -z "$list_of_updates" ]; then | |
log_to_syslog "Unable to get list of applicable updates" "Error" | |
exit 1 | |
fi | |
# Go over all Apple 'Config Data' updates | |
while read -r line ; do | |
read idnum dummy <<< "$line" | |
import_to_munki "$idnum" | |
done <<< "$list_of_updates" | |
# Run Munki makecatalogs | |
/usr/local/munki/makecatalogs > /dev/null | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment