# global list - errors to report
FAILED_CMDS=()
+VERBOSE=
+function verbose () {
+ [ -n "$VERBOSE" ] && echo "--------------------" "$@"
+}
+
function msg () {
[ -n "$QUIET" ] || echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "$@"
}
local REPO=$1; shift
local SUBJECT=$1; shift
local BODY=$1; shift
+ verbose "error" $SUBJECT
# already notified within a half day ?
GRACE=$((60*12))
- is_old=$(find $REPO/$NOTIFIED_FILE -mmin +$GRACE 2> /dev/null)
+ is_recent=$(find $REPO/$NOTIFIED_FILE -mmin -$GRACE 2> /dev/null)
# not there or less than 12 our old: don't notify
- [ -z "$is_old" ] && return
+ if [ -n "$is_recent" ] ; then
+ verbose "skipping recent notification -- $SUBJECT"
+ return
+ fi
for admin in $ADMINS; do
echo -e "$BODY" | mail -s "$SUBJECT" $admin
$COMMAND || ok=
TORECORD="$COMMAND"
fi
+
# failed ?
if [ -z "$ok" ]; then
# let's record the failure unless ignore is set
FAILED_CMDS=("${FAILED_CMDS[@]}" "$TORECORD")
fi
fi
+ verbose "after run with $COMMAND" "ok=$ok" "#failed=${#FAILED_CMDS[@]}"
popd > /dev/null
}
run ${REPO_DIR} git fetch origin --tags
run ${REPO_DIR} git fetch origin
merge_all_branches $REPO_DIR $NAME origin
- if [ $? -ne 0 ]; then
+ if [ -n "$FAILED_CMDS" ]; then
# format mail body
body="Can not fetch from ${MASTER_REPO}\n\n------------\n FAILED COMMANDS:\n"
for line in "${FAILED_CMDS[@]}"; do body="$body$line\n"; done
error $REPO_DIR "git-mirror.sh failed to merge remote with module ${NAME}" "$body"
+ return
fi
else
msg "mirroring ${NAME} for the first time"
fi
run ${REPO_DIR} git push --tags local_master
push_all_branches $REPO_DIR $NAME local_master origin
- if [ $? -ne 0 ]; then
+ if [ -n "$FAILED_CMDS" ]; then
# format mail body
body="FAILED COMMANDS:\n"
for line in "${FAILED_CMDS[@]}"; do body="$body$line\n"; done
}
function usage () {
- echo "Usage $COMMAND [-a admin-mails] [-r remote-git-url] [-q] REPONAME*"
+ echo "Usage $COMMAND [-a admin-mails] [-r remote-git-url] [-q] [-v] REPONAME*"
exit 1
}
-while getopts "a:r:qh" opt; do
+while getopts "a:r:qvh" opt; do
case $opt in
a) ADMINS=$OPTARG ;;
r) REMOTE_GIT=$OPTARG ;;
q) QUIET=true ;;
+ v) VERBOSE=true ;;
h) usage ;;
\?) echo "Invalid option: -$opt" >&2 ;;
esac
done
+shift $((OPTIND-1))
# is the stamp older than an hour ?
# in minutes
trap failure INT
-shift $((OPTIND-1))
date > $RUNNING_FILE
for gitrepo in "$@"; do mirror_repo $gitrepo ; done
rm -f $RUNNING_FILE