-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppg-push-reports
executable file
·48 lines (39 loc) · 1.5 KB
/
ppg-push-reports
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
if [[ -n "${PPG_DEBUG}" ]]; then
set -x
fi
pushd /etc/puppet >/dev/null || exit 1
PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
GIT_EXEC_PATH=$(git --exec-path)
GIT_DIR=$(git rev-parse --git-dir)
export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
. ${PPG_EXEC_PATH}/ppg-functions
### FIXME PROXYSERVER
if [ -z "$GIT_DIR" ]; then
echo >&2 "Not in a git checkout"
exit 1
fi
reportsdir='/etc/puppet/.ppg/reports'
hostname=$(xhostname)
# compress each report before transfer. full reports
# are sizable and compress 10:1
gzip -9 -q ${reportsdir}/${hostname}/*yaml
remoteurl=$(git config --get remote.origin.url)
remoteurl=$(dirname ${remoteurl})/reports
if [[ "$remoteurl" =~ 'ssh:' ]] ; then
# the reports go to a "reports" directory right next to
# the puppet remote url. we must mangle the url a bit to make
# it edible to rsync/scp
# - remove the ssh:// or git+ssh:// prefix
# - add a : after hostname, before the first slash
remoteurl=$(echo $remoteurl | sed 's!^ssh://!!;s!^git+ssh://!!;s!/!:/!')
# Use sftp, which is awkward but co-exists easily with git-shell
# as we want our VMs to have very limited access.
# For recursive, easy ftp, we use lftp, in "reverse mirror mode"
# and --Remove-source-files performs the cleanup for us.
# exec so we exit with lftp's error code
exec lftp -c "set net:timeout 10; set net:max-retries 6; mirror -R --Remove-source-files ${reportsdir}/${hostname} sftp://${remoteurl}/ "
else
# local path
exec rsync -vr ${reportsdir}/${hostname} ${remoteurl}/
fi