3 # This is generic shell library for all the scripts used by Girocco;
4 # most importantly, it introduces all the $cfg_* shell variables.
7 # Import all the variables from Girocco::Config to the local environment,
8 # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now.
9 __girocco_conf
="$GIROCCO_CONF"
10 [ -n "$__girocco_conf" ] || __girocco_conf
="Girocco::Config"
11 [ -z "$basedir" ] || __girocco_extrainc
="-I$basedir"
12 eval $
(perl
-I@basedir@
$__girocco_extrainc -M$__girocco_conf -le \
13 'foreach (keys %Girocco::Config::) {
14 my $val = ${$Girocco::Config::{$_}}; $val ||= "";
15 print "cfg_$_=\"$val\"";
20 # some poorly behaving /bin/sh implementations do not
21 # properly export variables when the command is actually
22 # a shell function -- they are set for the function call
23 # but not exported into the environment for anything the
24 # function executes. Export the two Git variables we
25 # care about if they are set. Since this is a subshell
26 # the export will be temporary.
27 [ -z "$GIT_DIR" ] ||
export GIT_DIR
28 [ -z "$GIT_SSL_NO_VERIFY" ] ||
export GIT_SSL_NO_VERIFY
29 exec "$cfg_git_bin" "$@"
32 nc_openbsd
() { "$cfg_nc_openbsd_bin" "$@"; }
37 [ -z "$_list" ] || _list
="$_list, "
44 _mailer
="${cfg_sendmail_bin:-/usr/sbin/sendmail}"
45 if [ -n "$cfg_sender" ]; then
46 "$_mailer" -i -f "$cfg_sender" "$@"
54 if [ "$1" = "-s" ]; then
60 echo "From: \"$cfg_name\" ($cfg_title) <$cfg_admin>"
61 echo "To: $(_addrlist "$@
")"
62 [ -z "$_subject" ] ||
echo "Subject: $_subject"
63 echo "Auto-Submitted: auto-generated"
69 # Supports both the bang CMD... and bang_eval CMD... functions
70 # Called when the command fails
71 # Should only be called from bang and bang_eval functions
73 if ! [ -e .banged
]; then
75 ! [ -f HEAD
-a -f config
-a -d objects
] ||
76 bangmailok
="$(GIT_DIR=. git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
78 [ "$bangmailok" = "false" -o -z "$mail" ] || bangaddrs
="$mail"
79 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] ||
80 if [ -z "$bangaddrs" ]; then bangaddrs
="$cfg_admin"; else bangaddrs
="$bangaddrs,$cfg_admin"; fi
81 [ -z "$bangaddrs" ] ||
83 echo "$* failed with error code $errcode"
85 [ ! -n "$bang_once" ] ||
echo "you will not receive any more notifications until recovery"
86 echo "this status message may be disabled on the project admin page"
91 } |
mail -s "[$cfg_name] $proj $bang_action failed" "$bangaddrs"
98 # bang CMD... will execute the command with well-defined failure mode;
99 # set bang_action to string of the failed action ('clone', 'update', ...);
100 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
101 # not spam the owner; re-define the bang_trap() function to do custom
102 # cleanup before bailing out
104 if [ -n "$show_progress" ]; then
107 read -r errcode
<<-EOT || :
109 exec 4>&3 3>&1 1>&4 4>&-
110 { "$@" 3>&- || echo $? >&3; } 2>&1 | tee -a "$bang_log"
114 if [ -z "$errcode" ]; then
119 if "$@" >>"$bang_log" 2>&1; then
129 # bang_eval CMD... will evaluate the command with well-defined failure mode;
130 # Identical to bang CMD... except the command is eval'd instead of executed.
132 if [ -n "$show_progress" ]; then
135 read -r errcode
<<-EOT || :
137 exec 4>&3 3>&1 1>&4 4>&-
138 { eval "$*" 3>&- || echo $? >&3; } 2>&1 | tee -a "$bang_log"
142 if [ -z "$errcode" ]; then
147 if eval "$*" >>"$bang_log" 2>&1; then
157 # Default bang settings:
159 bang_action
="lame_programmer"
162 bang_log
="$(mktemp -t repomgr-XXXXXX)"
163 trap "rm \"\$bang_log\"" EXIT
167 # Progress report - if show_progress is set, shows the given message.
169 [ ! -n "$show_progress" ] ||
echo "$@"
173 # Project config accessors; must be run in project directory
175 git config
"gitweb.$1"
179 git config
"gitweb.$1" "$2" && chgrp repo config
&& chmod g
+w config
183 git config
"$1" "$2" && chgrp repo config
&& chmod g
+w config
187 # Tool for checking whether given number of seconds has not passed yet
189 od="$(config_get "$1" || :)"
190 [ -n "$od" ] ||
return 1
191 os
="$(perl -I@basedir@ -MGirocco::Util -e "print parse_rfc2822_date
('$od')")"
192 [ -n "$os" ] ||
return 1
194 [ $ns -lt $
(($os+$2)) ]
198 # List all Git repositories, with given prefix if specified, one-per-line
201 cut
-d : -f 1,3 "$cfg_chroot"/etc
/group |
grep "^$1"
203 cut
-d : -f 1,3 "$cfg_chroot"/etc
/group
204 fi |
while IFS
=: read name id
; do
205 [ $id -lt 65536 ] ||
echo "$name"