jobs/shlib.sh: $GIROCCO_CONF support
[girocco.git] / jobs / shlib.sh
blob5a4db28abe85509c068ff89dabb273b9db170466
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 __girocco_conf="$GIROCCO_CONF"
7 [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config"
8 eval $(perl -I. -M$__girocco_conf -le \
9 'foreach (keys %Girocco::Config::) {
10 my $val = ${$Girocco::Config::{$_}}; $val ||= "";
11 print "cfg_$_=\"$val\"";
12 }')
15 alias git="$cfg_git_bin"
18 # bang CMD... will execute the command with well-defined failure mode;
19 # set bang_action to string of the failed action ('clone', 'update', ...);
20 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
21 # not spam the owner; re-define the bang_trap() function to do custom
22 # cleanup before bailing out
23 bang() {
24 if "$@" >>"$bang_log" 2>&1; then
25 # All right. Cool.
26 return;
28 if ! [ -e .banged ]; then
30 echo "$* failed with error code $?"
31 [ "$bang_once" ] && echo "you will not receive any more notifications until recovery"
32 echo "Log follows:"
33 cat "$bang_log"
34 } | mail -s "[$cfg_name] $proj $bang_action failed" "$mail,$cfg_admin"
36 touch .banged
37 bang_trap
38 exit 1
41 # Default bang settings:
42 bang_setup() {
43 bang_action="lame_programmer"
44 bang_once=
45 bang_trap() { :; }
46 bang_log="$(mktemp -t repomgr-XXXXXX)"
47 trap "rm \"\$bang_log\"" EXIT
51 # List all Git repositories in current directory, one-per-line
52 get_repo_list_here() {
53 find . -name base_url | cut -c 3- | sed -e 's/\/base_url$//'