3 # This is generic shell library for all the scripts used by Girocco;
4 # most importantly, it introduces all the $cfg_* shell variables.
6 # A well-known UTF-8 locale is required for some of the fast-import providers
7 # in order to avoid mangling characters. Ideally we could use "POSIX.UTF-8"
8 # but that is not reliably UTF-8 but rather usually US-ASCII.
9 # So we choose a well-known UTF-8 locale that should be understood everywhere
10 # and always means UTF-8. We only set LC_ALL to this when running the
11 # fast-import providers. Also to avoid complaints from sort we temporarily set
12 # the locale to "C" when running sort.
13 use_locale
=en_US.UTF-8
16 octet
='[0-9a-f][0-9a-f]'
17 octet4
="$octet$octet$octet$octet"
18 octet19
="$octet4$octet4$octet4$octet4$octet$octet$octet"
19 octet20
="$octet4$octet4$octet4$octet4$octet4"
21 get_girocco_config_var_list
() {
22 # Export all the variables from Girocco::Config to suitable var= lines
23 # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now
24 # and also setting a 'defined_cfg_' prefix to 1 if they are not undef.
25 __girocco_conf
="$GIROCCO_CONF"
26 [ -n "$__girocco_conf" ] || __girocco_conf
="Girocco::Config"
27 [ -z "$basedir" ] || __girocco_extrainc
="-I$basedir"
28 perl
-I@basedir@
$__girocco_extrainc -M$__girocco_conf -le \
29 'foreach (sort {uc($a) cmp uc($b)} keys %Girocco::Config::) {
30 my $val = ${$Girocco::Config::{$_}}; defined($val) or $val="";
31 $val =~ s/([\\"\$\`])/\\$1/gos;
32 $val =~ s/(?:\r\n|\r|\n)$//os;
33 print "cfg_$_=\"$val\"";
34 print "defined_cfg_$_=",
35 (defined(${$Girocco::Config::{$_}})?"1":"");
39 # If basedir has been replaced, and shlib_vars.sh exists, get the config
40 # definitions from it rather than running Perl.
41 if [ "@basedir@" = '@'basedir
'@' ] ||
! [ -r "@basedir@/shlib_vars.sh" ]; then
42 # Import all the variables from Girocco::Config to the local environment,
43 eval "$(get_girocco_config_var_list)"
45 # Import the variables from shlib_vars.sh which avoids needlessly
46 # running another copy of Perl
47 .
"@basedir@/shlib_vars.sh"
51 # some poorly behaving /bin/sh implementations do not
52 # properly export variables when the command is actually
53 # a shell function -- they are set for the function call
54 # but not exported into the environment for anything the
55 # function executes. Export the two Git variables we
56 # care about if they are set. Since this is a subshell
57 # the export will be temporary.
58 [ -z "$GIT_DIR" ] ||
export GIT_DIR
59 [ -z "$GIT_SSL_NO_VERIFY" ] ||
export GIT_SSL_NO_VERIFY
60 exec "$cfg_git_bin" "$@"
63 nc_openbsd
() { "$cfg_nc_openbsd_bin" "$@"; }
68 [ -z "$_list" ] || _list
="$_list, "
75 _mailer
="${cfg_sendmail_bin:-/usr/sbin/sendmail}"
76 if [ -n "$cfg_sender" ]; then
77 "$_mailer" -i -f "$cfg_sender" "$@"
85 if [ "$1" = "-s" ]; then
91 echo "From: \"$cfg_name\" ($cfg_title) <$cfg_admin>"
92 echo "To: $(_addrlist "$@
")"
93 [ -z "$_subject" ] ||
echo "Subject: $_subject"
94 echo "MIME-Version: 1.0"
95 echo "Content-Type: text/plain; charset=utf-8"
96 echo "Content-Transfer-Encoding: 8bit"
97 echo "Auto-Submitted: auto-generated"
103 # bang CMD... will execute the command with well-defined failure mode;
104 # set bang_action to string of the failed action ('clone', 'update', ...);
105 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
106 # not spam the owner; re-define the bang_trap() function to do custom
107 # cleanup before bailing out
109 if [ -n "$show_progress" ]; then
112 read -r errcode
<<-EOT || :
114 exec 4>&3 3>&1 1>&4 4>&-
115 { "$@" 3>&- || echo $? >&3; } 2>&1 | tee -a "$bang_log"
119 if [ -z "$errcode" ]; then
124 if "$@" >>"$bang_log" 2>&1; then
131 if ! [ -e .banged
] ||
[ -e .bangagain
]; then
134 ! [ -f HEAD
-a -f config
-a -d objects
] ||
135 bangmailok
="$(GIT_DIR=. git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
137 [ "$bangmailok" = "false" -o -z "$mail" ] || bangaddrs
="$mail"
138 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] ||
139 if [ -z "$bangaddrs" ]; then bangaddrs
="$cfg_admin"; else bangaddrs
="$bangaddrs,$cfg_admin"; fi
140 [ -z "$bangaddrs" ] ||
142 echo "$* failed with error code $errcode"
144 [ ! -n "$bang_once" ] ||
echo "you will not receive any more notifications until recovery"
145 echo "this status message may be disabled on the project admin page"
150 } |
mail -s "[$cfg_name] $proj $bang_action failed" "$bangaddrs"
157 # bang_eval CMD... will evaluate the command with well-defined failure mode;
158 # Identical to bang CMD... except the command is eval'd instead of executed.
163 # Default bang settings:
165 bang_action
="lame_programmer"
168 bang_log
="$(mktemp -t repomgr-XXXXXX)"
169 trap "rm \"\$bang_log\"" EXIT
173 # Progress report - if show_progress is set, shows the given message.
175 [ ! -n "$show_progress" ] ||
echo "$@"
179 # Project config accessors; must be run in project directory
181 git config
"gitweb.$1"
185 git config
"gitweb.$1" "$2" && chgrp repo config
&& chmod g
+w config
189 git config
"$1" "$2" && chgrp repo config
&& chmod g
+w config
192 config_get_date_seconds
() {
193 _dt
="$(config_get "$1" || :)"
194 [ -n "$_dt" ] ||
return 1
195 _ds
="$(perl -I@basedir@ -MGirocco::Util -e "print parse_rfc2822_date
('$_dt')")"
196 [ -n "$_ds" ] ||
return 1
200 # Tool for checking whether given number of seconds has not passed yet
202 os
="$(config_get_date_seconds "$1")" ||
return 1
204 [ $ns -lt $
(($os+$2)) ]
208 # List all Git repositories, with given prefix if specified, one-per-line
211 cut
-d : -f 1,3 "$cfg_chroot"/etc
/group |
grep "^$1"
213 cut
-d : -f 1,3 "$cfg_chroot"/etc
/group
214 fi |
while IFS
=: read name id
; do
215 [ $id -lt 65536 ] ||
echo "$name"
219 # returns true if the passed in git dir (defaults to ".") is a mirror using git fast-import
222 # always return false for non-mirrors
223 [ ! -e "$_gitdir/.nofetch" ] ||
return 1
224 _url
="$(GIT_DIR="$_gitdir" config_get baseurl 2>/dev/null || :)"
226 svn
://* | svn
+http
://* | svn
+https
://*)
227 # Don't think git-svn currently uses git fast-import
231 # darcs mirrors use git fast-import
235 # bzr mirrors use git fast-import
238 hg
+http
://* | hg
+https
://*)
239 # hg mirrors use git fast-import
243 # assume it does not use git fast-import
247 # hg-fast-export | git fast-import with error handling in current directory GIT_DIR
251 _python
="${PYTHON:-python}"
255 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
257 exec 4>&3 3>&1 1>&4 4>&-
260 [ -f hg2git-marks ] || touch hg2git-marks
261 _af="$(git config hg.authorsfile || :)"
262 _cmd='GIT_DIR="$(pwd)" "$_python" "$cfg_basedir/bin/hg-fast-export.py" \
263 --repo "$(pwd)/repo.hg" \
264 --marks "$(pwd)/hg2git-marks" \
265 --mapping "$(pwd)/hg2git-mapping" \
266 --heads "$(pwd)/hg2git-heads" \
267 --status "$(pwd)/hg2git-state" \
268 -U unknown --force --flatten --hg-hash'
269 [ -z "$_af" ] || _cmd="$_cmd"' --authors "$_af"'
270 eval "$_cmd" 3>&- || _e1=$?
275 rm -f hg2git-marks.new
277 --export-marks="$(pwd)/hg2git-marks.new" \
278 --export-pack-edges="$(pwd)/gfi-packs" \
279 --force 3>&- || _e2=$?
285 [ "$_err1" = 0 -a "$_err2" = 0 ] ||
return 1
286 if [ -f hg2git-marks
]; then
287 rm -f hg2git-marks.old
288 mv hg2git-marks hg2git-marks.old
290 touch hg2git-marks.old
292 cat hg2git-marks.old hg2git-marks.new | \
293 LC_ALL
=C
sort -t : -k2,2n
-u | \
294 sed -ne "/^:[1-9][0-9]* $octet20\$/p" > hg2git-marks
295 rm hg2git-marks.old hg2git-marks.new
297 git branch
--no-color | \
298 while IFS
= read -r _head
; do
299 echo ":${_head#??} $(git rev-parse "refs
/heads
/${_head#??}")"