3 if [[ -n "${PPG_DEBUG}" ]]; then
7 export GIT_DIR
=${1:-/var/lib/ppg/reports-import.git}
8 pushd ${GIT_DIR} >/dev
/null
10 if [[ "$(git config --get --bool core.bare)" != 'true' ]]; then
11 echo >&2 "ERROR: must run on a bare repository"
15 trackdir
=/var
/lib
/ppg
/reports-import.track
16 reportstmpdir
=$
(mktemp
-d --tmpdir=/var
/tmp ppg-reports-to-dashboard.XXXXXXX
)
19 for head in $
(git branch |
/bin
/grep -v '(no branch)' ); do
21 if [ -e ${trackdir}/${head} ]; then
22 lastimportstate
=$
(<${trackdir}/${head})
25 if [ -n "${lastimportstate}" ]; then
26 # we have a local head, walk deltas
27 logparams
="${lastimportstate}..refs/heads/${head}"
29 # Initial import will take only two days
31 logparams
=" --since=2.days.ago refs/heads/${head}"
33 # !? - the last line of git log has no \n so tac returns a
34 # first line that runs together the last two lines. workaround injecting
36 for commit
in $
( (git log
--pretty=format
:%H
${logparams} && echo '') |
tac); do
38 # the branchname is the hostname
39 fname
=reports
/${head}.yaml
40 epoch
=$
(git show
-s --pretty=format
:%ct
${commit})
42 # - get the file without checking out the commit
43 # - store it in a tmpdir for later import with rake
44 git show
${commit}:${fname} > ${reportstmpdir}/${epoch}-$head.yaml
45 echo ${commit} > ${trackdir}/${head}
48 if [ "${seenany}" = 'yes' ]; then
49 pushd /usr
/share
/puppet-dashboard
>/dev
/null
50 rake RAILS_ENV
=production reports
:import REPORT_DIR
=${reportstmpdir} |
grep -v 'ETA:.*Importing:'
54 # the rake/import process needs the file to stick around for a while
55 # and does not delete it when done, so this is fugly
56 find /var
/tmp
-type d
-name 'ppg-reports-to-dashboard.*' -user puppet-dashboard
-mmin +120 -print0 | \
57 xargs -0 --no-run-if-empty -L 100 rm -fr