-
Notifications
You must be signed in to change notification settings - Fork 1
/
git_sync
executable file
·74 lines (51 loc) · 1.83 KB
/
git_sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
SCRIPT_PATH=`realpath ${0}`
SCRIPT_DIR=`dirname ${SCRIPT_PATH}`
PHYSEVT_DIR=`realpath ${SCRIPT_DIR}`
LOG_DIR="${PHYSEVT_DIR}/log"
LOGFILE="${LOG_DIR}/git_sync.log"
# Send emails
function send_email {
for RECIPIENT in $(pts membership fccsw:access | tail -n +2); do
RECIPIENTS="${RECIPIENTS},${RECIPIENT}"
ADDRESSES="${ADDRESSES} ${RECIPIENT}@cern.ch"
done
RECIPIENTS="${RECIPIENTS:1}"
ADDRESSES="${ADDRESSES:1}"
read -r -d '' MESSAGE << EOM
Hello ${RECIPIENTS},
The FCC Physics Events website encountered an issue:
${1}
EOM
mail -s "FCC Physics Events Website" ${ADDRESSES} <<< "${MESSAGE}"
}
# Prepare log file
echo > "${LOGFILE}"
echo "`date` INFO: Syncing with git server in progress..." >> "${LOGFILE}"
SYNCLOCK="${PHYSEVT_DIR}/.sync.lock"
# Making sure the last sync went OK and there is no .sync.lock file left
if [ -f "${SYNCLOCK}" ]; then
echo "`date` WARNING: Encountered git sync lock. Aborting..." >> "${LOGFILE}"
if [ `find "${SYNCLOCK}" -mmin +720` ]; then
send_email "Git sync lock too old, please check the logs and possibly remove the lock file: ${SYNCLOCK}"
exit 3
fi
exit 0
fi
# Create sync lock
touch "${SYNCLOCK}"
cd "${PHYSEVT_DIR}"
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
echo "`date` ERROR: Git tree contains uncommited changes. Aborting..." >> "${LOGFILE}"
send_email "Git tree contains uncommited changes, please clear or commit them!"$'\n\n'"$(git status)"
exit 3
fi
git pull 2>&1 >> "${LOGFILE}"
if [ "$(git rev-parse main)" != "$(git rev-parse origin/main)" ]; then
echo "`date` ERROR: Git pull did not succeeded. Aborting..." >> "${LOGFILE}"
send_email "Git pull did not succeeded. Status of the repository:"$'\n\n'"$(git status)"
exit 3
fi
# Clear sync lock
rm -rf "${SYNCLOCK}"
echo "`date` INFO: Syncing with git server finished." >> "${LOGFILE}"