Skip to content

Instantly share code, notes, and snippets.

@mistaka0s
Last active April 16, 2017 20:56
Show Gist options
  • Save mistaka0s/5f2fa70ca194cb4947a2 to your computer and use it in GitHub Desktop.
Save mistaka0s/5f2fa70ca194cb4947a2 to your computer and use it in GitHub Desktop.
Git post-recieve hook to update Splunk deployment-apps directory on push.
#!/bin/bash
umask 022
# Uncomment to debug.
#set -x
# Modify GITWORKDIR to suit you.
#GITWORKDIR=/tmp/deployment-apps/
GITWORKDIR=/opt/splunk/etc/deployment-apps/
# Modify AUTOPUSHBRANCH with the branch you want to automatically push.
AUTOPUSHBRANCH=master
# Internals:
GITDIR=${GITWORKDIR}.git
GITEXEC="git --git-dir=${GITDIR} --work-tree=${GITWORKDIR}"
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
branch="${REF[2]}"
if [ "${AUTOPUSHBRANCH}" == "${branch}" ]; then
echo "${AUTOPUSHBRANCH} was pushed. updating deployment-apps"
cd ${GITWORKDIR}
if [[ -z $(${GITEXEC} status -s) ]]; then
${GITEXEC} fetch origin
${GITEXEC} checkout ${branch}
${GITEXEC} pull -f origin ${branch}
else
echo -e "\e[1;31;107mWARNING: Local changes found in deployment-apps directory!\e[0m"
echo -e "\e[1;31;107mWARNING: Not automatically pushing changes to deployment apps.\e[0m"
echo -e "\e[1;31;107mWARNING: Fix the splunk deployment-apps directory before next commit!\e[0m"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment