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