pullapply: unconditional hour now between 6am and midnight
[puppet-git.git] / ppg-push-empty-report
blob840c8609d2e76b6412bb05e6789ca2e562cc03f6
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
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"
18 exit 1
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!"
28 exit 1
31 hostname=$(xhostname)
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
42 exit 1
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}
57 git branch -D master
60 popd &>/dev/null
61 unset GIT_DIR
63 # NOTE: callers rely on getting an error through if push-reports
64 # fails
65 exec $PPG_EXEC_PATH/ppg-push-reports