3 if [[ -n "${PPG_DEBUG}" ]]; then
7 pushd /etc
/puppet
>/dev
/null ||
exit 1
9 PPG_EXEC_PATH
=$
( dirname $
(realpath
"${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 puppet apply
--detailed-exitcodes $@
34 # From http://docs.puppetlabs.com/man/apply.html
35 # 0 means ?? (guess: no changes)
36 # 2 means there were changes
38 # 6 means changes & failures
39 if [[ $pexit -eq 00 ]] ||
[[ $pexit -eq 2 ]]; then
41 lastgood_sha1
=$
(git rev-parse
--revs-only refs
/heads
/ppg
/lastgood
)
42 if [ -n "$lastgood_sha1" ]; then
43 git push . HEAD refs
/heads
/ppg
/lastgood
45 # setup with reflog - may be handy
47 git branch
-l refs
/heads
/ppg
/lastgood HEAD
50 ## TODO: do we want to warn in any way?
54 # TODO: handle reports
55 hostname
=$
(/usr
/bin
/hostname
-f)
56 worktree
='/etc/puppet/.ppg/scratch-worktree'
57 mkdir
-p ${worktree}/reports
59 export GIT_DIR
=/etc
/puppet
/.ppg
60 pushd ${worktree} &>/dev
/null
62 if ! git rev-parse
--revs-only \
63 refs
/heads
/${hostname} &>/dev
/null
; then
64 # it is going to be the first commit
65 # FIXME: any special handling?
68 cp ${REPORT_PATH} ${worktree}/reports/${hostname}.yaml
69 git update-index
--add reports
/${hostname}.yaml
70 git commit
-m 'ppg apply report'
72 headname
=$
(git rev-parse
--symbolic-full-name --revs-only HEAD
)
73 if [[ "${headname}" != "refs/heads/${hostname}" ]]; then
74 # we are in thefirst run, auto-created 'master' branch
75 git branch
${hostname} HEAD
76 git checkout
${hostname}
83 $PPG_EXEC_PATH/ppg-push-reports