2011-08-12 18:38:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# arguments: reponame, list of slaves
|
|
|
|
|
|
|
|
# optional flag after reponame: "-fg" to run in foreground. This is only
|
|
|
|
# going to be given by one specific invocation, and if given will only work
|
|
|
|
# for one slave.
|
|
|
|
|
|
|
|
# if list of slaves not given, get it from '...slaves' config
|
|
|
|
|
|
|
|
die() { echo gl-mirror-push${hn:+ on $hn}: "$@" >&2; exit 1; }
|
|
|
|
get_rc_val() { ${0%/*}/gl-query-rc $1; }
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# is mirroring even enabled?
|
|
|
|
hn=`get_rc_val GL_HOSTNAME`
|
|
|
|
[ -z "$hn" ] && exit
|
|
|
|
|
|
|
|
# we should not be invoked directly from the command line
|
|
|
|
[ -z "$GL_LOG" ] && die fatal: do not run $0 directly
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# get repo name then check if it's a local or slave (ie we're not the master)
|
|
|
|
[ -z "$1" ] && die fatal: missing reponame argument
|
|
|
|
repo=$1; shift
|
|
|
|
|
|
|
|
REPO_BASE=`get_rc_val REPO_BASE`
|
2011-08-14 04:53:15 +02:00
|
|
|
cd $REPO_BASE/$repo.git 2>/dev/null || die fatal: could not change directory to "$repo"
|
2011-08-12 18:38:28 +02:00
|
|
|
gmm=`git config --get gitolite.mirror.master`
|
|
|
|
|
|
|
|
# is it local? (remember, empty/undef ==> local
|
|
|
|
gmm=${gmm:-local}
|
|
|
|
[ "$gmm" = "local" ] && exit
|
|
|
|
|
|
|
|
# is it a slave?
|
|
|
|
[ "$hn" = "$gmm" ] || die fatal: wrong master. Try $gmm...
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# now see if we want to be foregrounded. Fg mode accepts only one slave
|
|
|
|
[ "$1" = "-fg" ] && {
|
|
|
|
[ -z "$2" ] && die fatal: missing slavename argument
|
|
|
|
[ -n "$3" ] && die fatal: too many slavenames
|
|
|
|
git push --mirror $2:$repo 2>&1 | sed -e "s/^/$hn:/"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
2011-08-14 06:36:16 +02:00
|
|
|
# normal (self-backgrounding) mode, one or more slaves
|
2011-08-12 18:38:28 +02:00
|
|
|
|
2011-08-14 06:36:16 +02:00
|
|
|
[ -z "$1" ] && die fatal: missing list of slaves
|
2011-08-12 18:38:28 +02:00
|
|
|
export slaves
|
2011-08-14 06:36:16 +02:00
|
|
|
slaves="$*"
|
2011-08-12 18:38:28 +02:00
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# print out the job ID, then redirect all 3 FDs
|
|
|
|
export job_id=$$ # can change to something else if needed
|
|
|
|
echo "($job_id&) $hn ==== ($repo) ===>" $slaves >&2
|
|
|
|
logfile=${GL_LOG/%.log/-mirror-pushes.log}
|
|
|
|
exec >>$logfile 2>&1 </dev/null
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# and finally...
|
|
|
|
|
|
|
|
# double fork, no zombies
|
|
|
|
(
|
|
|
|
(
|
|
|
|
echo `date +%T` $repo '===>'
|
|
|
|
|
|
|
|
for s in $slaves
|
|
|
|
do
|
|
|
|
[ "$s" = "$hn" ] && continue # skip ourselves
|
2011-08-15 17:19:07 +02:00
|
|
|
git push --mirror $s:$repo || echo ==== WARNING: RC=$? from git push --mirror $s:$repo ====
|
2011-08-12 18:38:28 +02:00
|
|
|
done 2>&1 | sed -e "s/^/ /"
|
|
|
|
echo `date +%T` '===>' $slaves
|
|
|
|
echo
|
|
|
|
) 2>&1 | sed -e "s/^/$job_id:/" & # background the whole thing
|
|
|
|
)
|