Force a non-lazy run if global.ini has changed
[puppet-git.git] / ppg-pullapply
bloba463e7d134bc1990f9fb932e6a088a6c90775af3
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
8 PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
9 GIT_EXEC_PATH=$(git --exec-path)
10 export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
12 . ${PPG_EXEC_PATH}/ppg-functions
14 pushd /etc/puppet >/dev/null || exit 1
15 GIT_DIR=$(git rev-parse --git-dir)
17 if [ -z "$GIT_DIR" ]; then
18 echo >&2 "Not in a git checkout"
19 exit 1
22 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
24 if [[ "$headname" != "refs/heads/production" ]]; then
25 echo >&2 "WARNING: Not on production branch"
28 ppg_lastgood_cleanup
29 initial_sha1=$(git rev-parse --revs-only HEAD)
30 lastgood_sha1=$(git rev-parse --revs-only ppg/lastgood)
32 # resilient wrt server availability...
33 git fetch --prune || echo "WARNING: error in git fetch"
35 if [[ "$headname" = "refs/heads/production" ]]; then
36 $PPG_EXEC_PATH/ppg-update-production || exit 1
37 else
38 # On EL6, git pull does not know --prune
39 if ! git pull --ff-only ; then
40 echo "ERROR: Failed to auto-merge with ff-only,"
41 echo " perhaps the current branch needs to"
42 echo " track a remote branch or you have dirty state."
43 echo " You can merge by hand and use ppg-apply"
47 uptodate_sha1=$(git rev-parse --revs-only HEAD)
49 echo "Executing command"
50 echo
51 echo " "ppg-apply "$@"
52 echo
53 echo "Log of changes to apply"
54 echo
55 if [ -n "$lastgood_sha1" ]; then
56 if [[ "$uptodate_sha1" != "$lastgood_sha1" ]]; then
57 git --no-pager log --oneline -n 100 ${lastgood_sha1}..${uptodate_sha1}
58 else
59 echo "No changes in git"
60 this_hour=$(date +%H)
61 unconditional_hour=$(( ( $(hostnametoint) % 18 ) + 5 ))
62 global_ini_changed=$( test /mnt/data/conf/global.ini -nt /mnt/data/conf/global.ini.parsed )$?
63 # incrond triggered runs use PPG_NOTLAZY
64 # global.ini newer than global.ini.parsed will skip lazy too
65 if [[ -z "${PPG_NOTLAZY}" && $global_ini_changed -ne 0 ]]; then
66 # lazy 23 times a day
67 if [ ${this_hour} -ne ${unconditional_hour} ]; then
68 exec $PPG_EXEC_PATH/ppg-push-empty-report
72 else
73 git --no-pager log --oneline -n 100 ${uptodate_sha1}
75 echo
76 exec $PPG_EXEC_PATH/ppg-apply "$@"