RUNNING_FILE=$LOCAL_MIRROR_DIR/RUNNING_MIRROR
function msg () {
- if [ $QUIET -eq 0 ]
- then
- echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx $@"
+ if [ $QUIET -eq 0 ] ; then
+ echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "$@"
fi
}
MSG=$2
CHECK_FILE=$3/$NOTIFIED_FILE
- if [ -f $CHECK_FILE ]
- then
+ if [ -f $CHECK_FILE ]; then
return
fi
- for admin in $ADMINS
- do
+ for admin in $ADMINS; do
echo -e "$MSG" | mail -s "$SUBJECT" $admin
done
touch $CHECK_FILE
}
function run () {
- if [ $QUIET -eq 1 ]
- then
+ if [ $QUIET -eq 1 ]; then
COMMAND="$1 &> /dev/null"
else
COMMAND="$1"
pushd ${REPO} > /dev/null
eval $COMMAND
- if [ $? -ne 0 ]
- then
+ if [ $? -ne 0 ]; then
FAILED=1
FAILED_CMDS="$FAILED_CMDS\n$COMMAND"
fi
# if there is no remote repository it may be that we only have
# the repository locally and don't need to mirror
git ls-remote $MIRROR_REPO &> /dev/null
- if [ $? -eq 0 ]
- then
- if [ -d ${REPO_DIR} ]
- then
+ if [ $? -eq 0 ]; then
+ if [ -d ${REPO_DIR} ]; then
msg "pulling from ${NAME}"
run "git fetch origin --tags" ${REPO_DIR}
run "git fetch origin" ${REPO_DIR}
merge_all_branches $NAME origin $REPO_DIR
- if [ $? -ne 0 ]
- then
+ if [ $? -ne 0 ]; then
error "git-mirror.sh failed" "Can not fetch from ${MASTER_REPO}" $REPO_DIR
fi
else
run "git fetch local_master --tags" ${REPO_DIR}
run "git fetch local_master" ${REPO_DIR}
merge_all_branches $NAME local_master $REPO_DIR
- if [ $FAILED -ne 0 ]
- then
+ if [ $FAILED -ne 0 ]; then
pushd ${REPO_DIR} > /dev/null
STATUS_OUT=$(git status)
popd > /dev/null
}
+function failure () {
+ msg "Received signal - cleaning up $RUNNING_FILE and aborting"
+ rm -f $RUNNING_FILE
+ exit 1
+}
+
while getopts ":hq" opt
do
case $opt in
break
;;
h)
- echo "USAGE: $0 [-q] REPONAME*"
+ echo "Usage: $0 [-q] REPONAME*"
exit 1
;;
\?)
done
-if [ -f $RUNNING_FILE ]
-then
- if [ $QUIET -eq 0 ]
- then
- echo "Another git-mirror is running. Aborting... " $RUNNING_FILE
- fi
-else
- shift $((OPTIND-1))
- touch $RUNNING_FILE
- mirror $@
+# is the stamp older than an hour ?
+# in minutes
+GRACE=60
+is_old=$(find $RUNNING_FILE -mmin +$GRACE 2> /dev/null)
+if [ -n "$is_old" ] ; then
+ msg "$RUNNING_FILE is older than $GRACE minutes - removing"
rm -f $RUNNING_FILE
fi
+if [ -f $RUNNING_FILE ] ; then
+ msg "Found $RUNNING_FILE - another git-mirror seems to be running. Aborting... "
+ exit 1
+fi
+
+trap failure ERR INT
+shift $((OPTIND-1))
+date > $RUNNING_FILE
+mirror $@
+rm -f $RUNNING_FILE