#!/bin/sh #$Id$ #Copyright (c) 2014-2021 Pierre Pronchery #This file is part of DeforaOS Devel scripts # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions #are met: #1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. #2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # #THIS SOFTWARE IS PROVIDED BY THE EDGEBSD PROJECT AND CONTRIBUTORS #``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED #TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR #PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS #BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR #CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS #INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN #CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #POSSIBILITY OF SUCH DAMAGE. #variables PREFIX="/usr/local" #executables GIT_MESSAGE="$PREFIX/libexec/deforaos-git-message" DEFORAOS_IRC="$PREFIX/libexec/deforaos-irc" DEFORAOS_JOBS="$PREFIX/bin/deforaos-jobs" MKTEMP="mktemp" RM="rm -f" #settings HOOKS="jobs" IRC_CHANNEL= IRC_SERVER= JOBS_BRANCH_MASTER="$PREFIX/libexec/deforaos-jobs/deforaos-job-git-mirror $PREFIX/libexec/deforaos-jobs/deforaos-job-git-doc $PREFIX/libexec/deforaos-jobs/deforaos-job-git-tests" PROGNAME="deforaos-git-hook" SYSCONFDIR="$PREFIX/etc" VENDOR="DeforaOS" #load local settings [ -f "$SYSCONFDIR/$VENDOR/$PROGNAME.conf" ] && . "$SYSCONFDIR/$VENDOR/$PROGNAME.conf" [ -f "$HOME/.config/$VENDOR/$PROGNAME.conf" ] && . "$HOME/.config/$VENDOR/$PROGNAME.conf" #functions #hook_jobs _hook_jobs() { res=0 while read oldrev newrev refname; do case "$refname" in refs/heads/master) _jobs_branch "${refname#refs/heads/}" \ "$GL_REPO" || res=2 ;; esac done return $res } _jobs_branch() {( branch="$1" repository="$2" res=0 if [ "$branch" = "master" -a -n "$JOBS_BRANCH_MASTER" ]; then for job in $JOBS_BRANCH_MASTER; do #warn if the job is not available [ -x "$job" ] || _error "$job: Job not available" $DEFORAOS_JOBS add "$job $repository" || res=2 done fi return $res )} #hook_irc _hook_irc() { if [ -z "$IRC_SERVER" -o -z "$IRC_CHANNEL" ]; then _error "IRC_SERVER and IRC_CHANNEL must be set for the IRC hook" return $? fi $GIT_MESSAGE "post-receive" 2>&1 | $DEFORAOS_IRC "$IRC_SERVER" "$IRC_CHANNEL" #ignore errors return 0 } #error _error() { echo "$PROGNAME: $@" 1>&2 return 2 } #main #save a copy of the output tmpfile=$($MKTEMP) [ $? -eq 0 ] || exit 2 while read line; do echo "$line" >> "$tmpfile" done #chain the hooks ret=0 [ -n "$HOOKS" ] && for hook in $HOOKS; do "_hook_$hook" < "$tmpfile" || ret=2 done #clean up $RM -- "$tmpfile" || exit 2 exit $ret