3 if [[ -n "${PPG_DEBUG}" ]]; then
7 pushd /etc
/puppet
>/dev
/null ||
exit 1
9 PPG_EXEC_PATH
=$
( dirname $
(readlink
-f "${BASH_SOURCE[0]}" ) )
10 GIT_EXEC_PATH
=$
(git
--exec-path)
11 GIT_DIR
=$
(git rev-parse
--git-dir)
13 if [ -z "$GIT_DIR" ]; then
14 echo >&2 "Not in a git checkout"
18 ## FIXME?: check whether these are overriden
19 PUPPETCONF
=/etc
/puppet
/puppet.conf
20 REPORT_PATH
=/var
/lib
/puppet
/state
/last_run_report.yaml
22 # puppet.conf syntax is compat with git config syntax
23 # (both are INI style). How lucky can we be? :-)
24 report_bool
=$
(git config
-f $PUPPETCONF --bool --get agent.report
)
26 # note: default is true
27 if [ "$report_bool" = 'false' ]; then
28 echo >&2 "ERROR: reports are disabled!"
31 if [ -x /etc
/puppet
/local-puppet-apply
]; then
32 /etc
/puppet
/local-puppet-apply
35 puppet apply
--detailed-exitcodes $@
39 # From http://docs.puppetlabs.com/man/apply.html
40 # 0 means ?? (guess: no changes)
41 # 2 means there were changes
43 # 6 means changes & failures
44 if [[ $pexit -eq 00 ]] ||
[[ $pexit -eq 2 ]]; then
46 lastgood_sha1
=$
(git rev-parse
--revs-only refs
/heads
/ppg
/lastgood
)
47 if [ -n "$lastgood_sha1" ]; then
48 git push . HEAD refs
/heads
/ppg
/lastgood
50 # setup with reflog - may be handy
52 git branch
-l refs
/heads
/ppg
/lastgood HEAD
55 ## TODO: do we want to warn in any way?
59 # TODO: handle reports
60 hostname
=$
(/bin
/hostname
-f)
61 worktree
='/etc/puppet/.ppg/scratch-worktree'
62 mkdir
-p ${worktree}/reports
64 export GIT_DIR
=/etc
/puppet
/.ppg
65 pushd ${worktree} &>/dev
/null
67 if ! git rev-parse
--revs-only \
68 refs
/heads
/${hostname} &>/dev
/null
; then
69 # it is going to be the first commit
70 # FIXME: any special handling?
73 cp ${REPORT_PATH} ${worktree}/reports/${hostname}.yaml
74 git update-index
--add reports
/${hostname}.yaml
75 git commit
-m 'ppg apply report'
77 headname
=$
(git rev-parse
--symbolic-full-name --revs-only HEAD
)
78 if [[ "${headname}" != "refs/heads/${hostname}" ]]; then
79 # we are in thefirst run, auto-created 'master' branch
80 git branch
${hostname} HEAD
81 git checkout
${hostname}
88 $PPG_EXEC_PATH/ppg-push-reports