diff options
author | Nick Hilliard <nick@foobar.org> | 2015-12-27 19:33:36 +0000 |
---|---|---|
committer | Nick Hilliard <nick@foobar.org> | 2015-12-27 19:33:36 +0000 |
commit | 18d084a99dad9c49a5123a67b19aad6540f15e11 (patch) | |
tree | 354de7fa0f4bdbf338a7ca0431622493430af179 | |
parent | 201c02551d96a070f8d55936aba350f772649465 (diff) |
Added git-to-email script
-rwxr-xr-x | extra/oxidized-report-git-commits | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/extra/oxidized-report-git-commits b/extra/oxidized-report-git-commits new file mode 100755 index 0000000..40fd2f4 --- /dev/null +++ b/extra/oxidized-report-git-commits @@ -0,0 +1,75 @@ +#!/bin/sh +# +# A script to maintain a local working copy of an oxidized configuration +# repository and mail out diffs for configuration changes +# +# Copyright 2016 Nick Hilliard <nick@foobar.org>, All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# usage: add the following hook to the oxidized config file: +# +# hooks: +# email_output: +# type: exec +# events: [post_store, node_fail] +# cmd: 'update-local-repo.sh ~/gitdir/ | mail -s "Oxidized updates for ${OX_NODE_NAME}" update-recipient@example.com' +# async: true +# timeout: 120 +# + +PATH=${PATH}:/usr/local/bin:/usr/local/sbin +export PATH + +gitdir=$1 + +if [ X${OX_REPO_COMMITREF} = "X" ]; then + echo \$OX_REPO_COMMITREF not set + exit 64 +fi + +if [ X${OX_REPO_NAME} = "X" ]; then + echo \$OX_REPO_NAME not set + exit 64 +fi + +if [ ! -d ${gitdir}/.git ]; then + git clone -q ${OX_REPO_NAME} ${gitdir} + + ret=$? + if [ X"${ret}" != X0 ] && [ X"${ret}" != X1 ]; then + echo git clone failed: aborting. + exit 128 + fi +fi + +cd ${gitdir} + +git pull -q > /dev/null 2>&1 +ret=$? +if [ X"${ret}" != X0 ] && [ X"${ret}" != X1 ]; then + echo git pull failed: aborting. + exit 128 +fi + +# Git is probably working at this stage, so safe to emit more info + +echo "Node name: ${OX_NODE_NAME}" +echo "Group Name: ${OX_NODE_GROUP}" +echo "Job Time: ${OX_JOB_TIME}" +echo "Git Commit ID: ${OX_REPO_COMMITREF}" +echo "Git Repo: ${OX_REPO_NAME}" +echo "Local working dir: ${gitdir}" +echo "" + +git diff --no-color ${OX_REPO_COMMITREF}~1..${OX_REPO_COMMITREF} |