-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppg-pullapply
executable file
·78 lines (65 loc) · 2.14 KB
/
ppg-pullapply
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
75
76
77
78
#!/bin/bash
if [[ -n "${PPG_DEBUG}" ]]; then
set -x
fi
PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
GIT_EXEC_PATH=$(git --exec-path)
export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
. ${PPG_EXEC_PATH}/ppg-functions
pushd /etc/puppet >/dev/null || exit 1
GIT_DIR=$(git rev-parse --git-dir)
if [ -z "$GIT_DIR" ]; then
echo >&2 "Not in a git checkout"
exit 1
fi
headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
if [[ "$headname" != "refs/heads/production" ]]; then
echo >&2 "WARNING: Not on production branch"
fi
ppg_lastgood_cleanup
initial_sha1=$(git rev-parse --revs-only HEAD)
lastgood_sha1=$(git rev-parse --revs-only ppg/lastgood)
# resilient wrt server availability...
git fetch --prune || echo "WARNING: error in git fetch"
if [[ "$headname" = "refs/heads/production" ]]; then
$PPG_EXEC_PATH/ppg-update-production || exit 1
else
# On EL6, git pull does not know --prune
if ! git pull --ff-only ; then
echo "ERROR: Failed to auto-merge with ff-only,"
echo " perhaps the current branch needs to"
echo " track a remote branch or you have dirty state."
echo " You can merge by hand and use ppg-apply"
fi
fi
uptodate_sha1=$(git rev-parse --revs-only HEAD)
echo "Executing command"
echo
echo " "ppg-apply "$@"
echo
echo "Log of changes to apply"
echo
if [ -n "$lastgood_sha1" ]; then
if [[ "$uptodate_sha1" != "$lastgood_sha1" ]]; then
git --no-pager log --oneline -n 100 ${lastgood_sha1}..${uptodate_sha1}
else
echo "No changes in git"
this_hour=$(date +%H)
unconditional_hour=$(( ( $(hostnametoint) % 18 ) + 5 ))
global_ini_changed=$( test /mnt/data/conf/global.ini -nt /mnt/data/conf/global.ini.parsed )$?
# incrond triggered runs use PPG_NOTLAZY
# global.ini newer than global.ini.parsed will skip lazy too
if [[ -z "${PPG_NOTLAZY}" && $global_ini_changed -ne 0 ]]; then
# lazy 23 times a day
if [ ${this_hour} -ne ${unconditional_hour} ]; then
if [ -z "${PPG_NOREPORT}" ] ; then
exec $PPG_EXEC_PATH/ppg-push-empty-report
fi
fi
fi
fi
else
git --no-pager log --oneline -n 100 ${uptodate_sha1}
fi
echo
exec $PPG_EXEC_PATH/ppg-apply "$@"