jobs/shlib.sh: Fix bang_trap() predecleration syntax
[girocco.git] / jobs / shlib.sh
blobafe5f378deac6f2fb7a537e13d5be8dcecbae7b1
1 #!/bin/bash
4 # Import all the variables from Girocco::Config to the local environment,
5 # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now.
6 eval $(perl -I. -MGirocco::Config -le \
7 'foreach (keys %Girocco::Config::) {
8 my $val = ${$Girocco::Config::{$_}}; $val ||= "";
9 print "cfg_$_=\"$val\"";
10 }')
13 alias git="$cfg_git_bin"
16 # bang CMD... will execute the command with well-defined failure mode;
17 # set bang_action to string of the failed action ('clone', 'update', ...);
18 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
19 # not spam the owner; re-define the bang_trap() function to do custom
20 # cleanup before bailing out
21 bang() {
22 if "$@" >>"$bang_log" 2>&1; then
23 # All right. Cool.
24 return;
26 if ! [ -e .banged ]; then
28 echo "$* failed with error code $?"
29 [ "$bang_once" ] && echo "you will not receive any more notifications until recovery"
30 echo "Log follows:"
31 cat "$bang_log"
32 } | mail -s "[$cfg_name] $proj $bang_action failed" "$mail,$cfg_admin"
34 touch .banged
35 bang_trap
36 exit 1
39 # Default bang settings:
40 bang_setup() {
41 bang_action="lame_programmer"
42 bang_once=
43 bang_trap() { :; }
44 bang_log="$(mktemp -t repomgr-XXXXXX)"
45 trap "rm \"\$bang_log\"" EXIT
49 # List all Git repositories in current directory, one-per-line
50 get_repo_list_here() {
51 find . -name base_url | cut -c 3- | sed -e 's/\/base_url$//'