Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # reposado_auto_munkiimport_aswupd_configdata_items
  4. #
  5. # automatically create apple_update_metadata pkginfo files for Munki: XProtectPlistConfigData, Gatekeeper Configuration Data
  6. #
  7.  
  8. # path to your Munki repo (local or mounted share)
  9. munkiRepoDir="/Users/Shared/munki/repo"
  10.  
  11. # path to pkgsinfo in Munki repo
  12. munkiPkgsInfoDir="${munkiRepoDir}/pkgsinfo"
  13.  
  14. # path to Apple Software Updates metadata directory in Munki repo, it is cleaner to separate them from other updates
  15. munki_ASWUPD_META_Dir="${munkiPkgsInfoDir}/ASWUPD_META"
  16.  
  17. # path to your executable repoutil command
  18. repoUtilCmd="/path/to/your/reposado/code/repoutil"
  19.  
  20. # file owner and group, needed if this script is run as root
  21. fileOwner=jenkins
  22. fileGroup=munki
  23.  
  24. ###
  25. # functions
  26.  
  27. function logTyper () {
  28. timeStamp=$(date '+%h %d %T')
  29. echo "${timeStamp}: ${1}"
  30. }
  31.  
  32. ###
  33. # actions
  34.  
  35. if [ ! -d "${munki_ASWUPD_META_Dir}" ]; then
  36. logTyper "Munki directory '${munki_ASWUPD_META_Dir}' is not available"
  37. exit 1
  38. fi
  39.  
  40. if ! [ -x "${repoUtilCmd}" ]; then
  41. logTyper "'${repoUtilCmd}' not found"
  42. exit 1
  43. fi
  44.  
  45. logTyper "Checking for config-data updates..."
  46.  
  47. listSysConfigUpdates=$("${repoUtilCmd}" --products | egrep 'XProtectPlistConfigData|Gatekeeper Configuration Data' | grep -v '(Deprecated)')
  48.  
  49. OLD_IFS=${IFS}
  50. IFS=$'\n'
  51.  
  52. # process updates
  53. for item in ${listSysConfigUpdates}
  54. do
  55. itemID=$(echo "${item}" | awk '{print $1}')
  56.  
  57. if [ "" == "${itemID}" ]; then
  58. continue
  59. fi
  60.  
  61. getItemInfo=$("${repoUtilCmd}" --info "${itemID}")
  62.  
  63. itemTitle=$(echo "${getItemInfo}" | grep 'Title:' | awk -F 'Title:' '{print $NF}' | sed 's/^ *//;s/ *$//')
  64.  
  65. if [ "" == "${itemTitle}" ]; then
  66. continue
  67. fi
  68.  
  69. itemVers=$(echo "${getItemInfo}" | grep 'Version:' | awk -F 'Version:' '{print $NF}' | tr -d ' ')
  70.  
  71. itemDescr="${itemTitle} ${itemVers} [${itemID}] from Apple."
  72.  
  73. itemFileName=$(echo "${itemTitle}" | tr ' ' '_')-"${itemVers}"-"${itemID}".plist
  74.  
  75. # check if metadata file is laready in Munki repo
  76. if [ -e "${munki_ASWUPD_META_Dir}/${itemFileName}" ]; then
  77. logTyper "Metadata '${itemFileName}' is already in Munki repo."
  78. continue
  79. fi
  80.  
  81. # create a pkginfo for metadata
  82. /usr/local/munki/makepkginfo --apple-update "${itemID}" --displayname="${itemTitle}" --catalog testing --catalog another_one --description="${itemDescr}" --unattended_install > /tmp/"${itemFileName}"
  83. chmod a+rw /tmp/"${itemFileName}"
  84.  
  85. # copy pkginfo to proper location
  86. cp /tmp/"${itemFileName}" "${munki_ASWUPD_META_Dir}/${itemFileName}"
  87. if [ $? -ne 0 ]
  88. then
  89. logTyper "ERROR: could not copy '${itemFileName}' to '${munki_ASWUPD_META_Dir}"
  90. fi
  91.  
  92. logTyper "Copied '${itemFileName}' to '${munki_ASWUPD_META_Dir}"
  93.  
  94. chown "${fileOwner}":"${fileGroup}" "${munki_ASWUPD_META_Dir}/${itemFileName}"
  95. chmod ug+rw,a+r "${munki_ASWUPD_META_Dir}/${itemFileName}"
  96.  
  97. done
  98.  
  99. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement