├── README.md └── autopkg ├── README.md ├── autopkg-wrapper.sh ├── autopkg.out └── com.example.autopkg-wrapper.plist /README.md: -------------------------------------------------------------------------------- 1 | This repository contains some of the scripts I've written to help me be more productive via automation. 2 | -------------------------------------------------------------------------------- /autopkg/README.md: -------------------------------------------------------------------------------- 1 | This is a little script I wrote to be notified (via email) when something changes when autopkg runs. You can find more info [on my blog](http://seankaiser.com/blog/2013/12/16/autopkg-change-notifications/), including how to configure the variables to get things running in your environment. If you need some help getting things set up, feel free to ping me on twitter at [@seankaiser](http://twitter.com/seankaiser). 2 | -------------------------------------------------------------------------------- /autopkg/autopkg-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # autopkg automation script which, when run with no arguments, checks current run's output against a default output and sends the output to a user if there are differences 4 | 5 | # adjust the following variables for your particular configuration 6 | # you should manually run the script with the initialize option if you change the recipe list, since that will change the output. 7 | recipe_list="AdobeFlashPlayer.munki MakeCatalogs.munki" 8 | mail_recipient="you@yourdomain.net" 9 | autopkg_user="autopkg" 10 | 11 | # don't change anything below this line 12 | 13 | # define logger behavior 14 | logger="/usr/bin/logger -t autopkg-wrapper" 15 | user_home_dir=`dscl . -read /Users/${autopkg_user} NFSHomeDirectory | awk '{ print $2 }'` 16 | 17 | # run autopkg 18 | if [ "${1}" == "help" ]; then 19 | # show some help with regards to initialization option 20 | echo "usage: ${0} [initialize]" 21 | echo "(initializes a new default log for notification checking)" 22 | exit 0 23 | 24 | elif [ "${1}" == "initialize" ]; then 25 | # initialize default log for automated run to check against for notification if things have changed 26 | $logger "starting autopkg to initialize a new default output log" 27 | 28 | echo "recipe list: ${recipe_list}" 29 | echo "autopkg user: ${autopkg_user}" 30 | echo "user home dir: ${user_home_dir}" 31 | 32 | # make sure autopkg folder exists in autopkg_user's Documents folder 33 | if [ ! -d "${user_home_dir}"/Documents/autopkg ]; then 34 | /bin/mkdir -p "${user_home_dir}"/Documents/autopkg 35 | fi 36 | 37 | # run autopkg twice, once to get any updates and the second to get a log indicating nothing changed 38 | $logger "autopkg initial run to temporary log location" 39 | echo "for this autopkg run, output will be shown" 40 | /usr/local/bin/autopkg run -v ${recipe_list} 2>&1 41 | 42 | $logger "autopkg initial run to saved log location" 43 | echo "for this autopkg run, output will not be shown, but rather saved to default log location (${user_home_dir}/Documents/autopkg/autopkg.out" 44 | /usr/local/bin/autopkg run ${recipe_list} 2>&1 > "${user_home_dir}"/Documents/autopkg/autopkg.out 45 | 46 | $logger "finished autopkg" 47 | 48 | elif [ ! -f "${user_home_dir}"/Documents/autopkg/autopkg.out ]; then 49 | # default log doesn't exist, so tell user to run this script in initialization mode and exit 50 | echo "ERROR: default log does not exist, please run this script with initialize argument to initialize the log" 51 | exit -1 52 | 53 | else 54 | # default is to just run autopkg and email log if something changed from normal 55 | $logger "starting autopkg" 56 | /usr/local/bin/autopkg repo-update all 57 | /usr/local/bin/autopkg run ${recipe_list} 2>&1 > /tmp/autopkg.out 58 | 59 | $logger "finished autopkg" 60 | 61 | # check output against the saved log and if differences exist, send current log to specified recipient 62 | if [ "`diff /tmp/autopkg.out \"${user_home_dir}\"/Documents/autopkg/autopkg.out`" != "" ]; then 63 | # there are differences from a "Nothing downloaded, packaged or imported" run... might be an update or an error 64 | $logger "sending autopkg log" 65 | /usr/bin/mail -s "autopkg log" ${mail_recipient} < /tmp/autopkg.out 66 | $logger "sent autopkg log to {$mail_recipient}, `wc -l /tmp/autopkg.out | awk '{ print $1 }'` lines in log" 67 | else 68 | $logger "autopkg did nothing, so not sending log" 69 | fi 70 | fi 71 | exit 0 72 | 73 | -------------------------------------------------------------------------------- /autopkg/autopkg.out: -------------------------------------------------------------------------------- 1 | Processing AdobeFlashPlayer.munki... 2 | Processing MakeCatalogs.munki... 3 | 4 | Nothing downloaded, packaged or imported. 5 | -------------------------------------------------------------------------------- /autopkg/com.example.autopkg-wrapper.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.example.autopkg-wrapper 7 | ProgramArguments 8 | 9 | /usr/local/bin/autopkg-wrapper.sh 10 | 11 | StartCalendarInterval 12 | 13 | 14 | Hour 15 | 0 16 | Minute 17 | 0 18 | 19 | 20 | Hour 21 | 1 22 | Minute 23 | 0 24 | 25 | 26 | Hour 27 | 2 28 | Minute 29 | 0 30 | 31 | 32 | Hour 33 | 3 34 | Minute 35 | 0 36 | 37 | 38 | Hour 39 | 4 40 | Minute 41 | 0 42 | 43 | 44 | Hour 45 | 5 46 | Minute 47 | 0 48 | 49 | 50 | Hour 51 | 6 52 | Minute 53 | 0 54 | 55 | 56 | Hour 57 | 7 58 | Minute 59 | 0 60 | 61 | 62 | Hour 63 | 8 64 | Minute 65 | 0 66 | 67 | 68 | Hour 69 | 9 70 | Minute 71 | 0 72 | 73 | 74 | Hour 75 | 10 76 | Minute 77 | 0 78 | 79 | 80 | Hour 81 | 11 82 | Minute 83 | 0 84 | 85 | 86 | Hour 87 | 12 88 | Minute 89 | 0 90 | 91 | 92 | Hour 93 | 13 94 | Minute 95 | 0 96 | 97 | 98 | Hour 99 | 14 100 | Minute 101 | 0 102 | 103 | 104 | Hour 105 | 15 106 | Minute 107 | 0 108 | 109 | 110 | Hour 111 | 16 112 | Minute 113 | 0 114 | 115 | 116 | Hour 117 | 17 118 | Minute 119 | 0 120 | 121 | 122 | Hour 123 | 18 124 | Minute 125 | 0 126 | 127 | 128 | Hour 129 | 19 130 | Minute 131 | 0 132 | 133 | 134 | Hour 135 | 20 136 | Minute 137 | 0 138 | 139 | 140 | Hour 141 | 21 142 | Minute 143 | 0 144 | 145 | 146 | Hour 147 | 22 148 | Minute 149 | 0 150 | 151 | 152 | Hour 153 | 23 154 | Minute 155 | 0 156 | 157 | 158 | UserName 159 | autopkg 160 | AbandonProcessGroup 161 | 162 | 163 | 164 | --------------------------------------------------------------------------------