functions: introduce xhostname and use it as a replacement for /bin/hostname
[puppet-git.git] / ppg-pullapply
blob618a56938a08ce46d8fc3cf2ea906a07dfe1f9b6
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 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 initial_sha1=$(git rev-parse --revs-only HEAD)
29 lastgood_sha1=$(git rev-parse --revs-only refs/heads/ppg/lastgood)
31 # resilient wrt server availability...
32 git fetch || echo "WARNING: error in git fetch"
34 if [[ "$headname" = "refs/heads/production" ]]; then
35 $PPG_EXEC_PATH/ppg-update-production || exit 1
36 else
37 if ! git pull --ff-only ; then
38 echo "ERROR: Failed to auto-merge with ff-only,"
39 echo " perhaps the current branch needs to"
40 echo " track a remote branch or you have dirty state."
41 echo " You can merge by hand and use ppg-apply"
45 uptodate_sha1=$(git rev-parse --revs-only HEAD)
47 echo "Executing command"
48 echo
49 echo " "ppg-apply "$@"
50 echo
51 echo "Log of changes to apply"
52 echo
53 if [ -n "$lastgood_sha1" ]; then
54 if [[ "$uptodate_sha1" != "$lastgood_sha1" ]]; then
55 git log --oneline ${lastgood_sha1}..${uptodate_sha1}
56 else
57 echo "No changes in git"
58 this_hour=$(date +%H)
59 unconditional_hour=$(( $(hostnametoint) % 24 ))
60 # lazy 23 times a day
61 if [ ${this_hour} -ne ${unconditional_hour} ]; then
62 exec $PPG_EXEC_PATH/ppg-push-empty-report
65 else
66 git log --oneline ${uptodate_sha1}
68 echo
69 exec $PPG_EXEC_PATH/ppg-apply "$@"