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)
12 GIT_SSH
="${PPG_EXEC_PATH}/ppg-ssh"
14 .
${PPG_EXEC_PATH}/ppg-functions
16 if [ -z "$GIT_DIR" ]; then
17 echo >&2 "Not in a git checkout"
21 # puppet.conf syntax is compat with git config syntax
22 # (both are INI style). How lucky can we be? :-)
23 report_bool
=$
(git config
-f $PUPPETCONF --bool --get agent.report
)
25 # note: default is true
26 if [ "$report_bool" = 'false' ]; then
27 echo >&2 "ERROR: reports are disabled!"
32 worktree
='/etc/puppet/.ppg/scratch-worktree'
33 mkdir
-p ${worktree}/reports
35 export GIT_DIR
=/etc
/puppet
/.ppg
36 pushd ${worktree} &>/dev
/null
38 if ! git rev-parse
--revs-only \
39 refs
/heads
/${hostname} &>/dev
/null
; then
40 # it is going to be the first commit
41 echo Refusing to fake first report
>&2
45 cp ${PPG_EXEC_PATH}/unchanged.report ${worktree}/reports/${hostname}.yaml
46 report_time
=$
(echo time: $
(date +"%Y-%m-%d %H:%M:%S.%6N %:z"))
47 /bin
/sed -i "s,REPLACEMEDATESTAMP,${report_time},g" ${worktree}/reports/${hostname}.yaml
48 /bin/sed -i "s
,REPLACEMEHOSTNAME
,${hostname},g" ${worktree}/reports/${hostname}.yaml
49 git update-index
--add reports
/${hostname}.yaml
50 git commit
-m 'ppg apply report'
52 headname
=$
(git rev-parse
--symbolic-full-name --revs-only HEAD
)
53 if [[ "${headname}" != "refs/heads/${hostname}" ]]; then
54 # we are in thefirst run, auto-created 'master' branch
55 git branch
${hostname} HEAD
56 git checkout
${hostname}
63 # NOTE: callers rely on getting an error through if push-reports
65 exec $PPG_EXEC_PATH/ppg-push-reports