91 lines
1.9 KiB
Bash
Executable File
91 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
##########################################################################
|
|
|
|
tdir=''
|
|
|
|
function cleanup {
|
|
if [ -n "$tdir" -a -d "$tdir" ]
|
|
then
|
|
rm -rf "$tdir"
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
##########################################################################
|
|
# figure out args
|
|
|
|
rsync_hosts=( ${1//,/ } )
|
|
rsync_src="$2"
|
|
rsync_dst="$3"
|
|
|
|
if [ -z "$rsync_dst" ]
|
|
then
|
|
echo "Usage: $0 <hosts> <src> <dst>"
|
|
exit 1
|
|
fi
|
|
|
|
opts='-av'
|
|
extra_args=''
|
|
|
|
if [ -n "$RSYNC_CHOWN" ]
|
|
then
|
|
opts+='og'
|
|
extra_args+=" --chown ${RSYNC_CHOWN}"
|
|
fi
|
|
|
|
if [ -n "$RSYNC_CHMOD" ]
|
|
then
|
|
opts+='p'
|
|
extra_args+=" --chmod=${RSYNC_CHMOD}"
|
|
fi
|
|
|
|
##########################################################################
|
|
# drone debugging
|
|
echo "*** Network Debug ***"
|
|
|
|
echo "----- ip addr"
|
|
ip addr
|
|
|
|
echo "----- ip route"
|
|
ip route
|
|
|
|
echo "*** Network Debug ***"
|
|
##########################################################################
|
|
# generate a temporary key
|
|
|
|
tdir=$(mktemp -d rsync.XXXXXX)
|
|
key="${tdir}/rsync"
|
|
ssh-keygen -t ed25519 -a 100 -N '' -f "$key"
|
|
pubkey=$(cat "${key}.pub")
|
|
|
|
url='https://vault.burble.dn42/v1/'
|
|
url+='burble.dn42/ssh/user/sign/rsync'
|
|
|
|
json="{\"public_key\":\"${pubkey}\"}"
|
|
|
|
wget -O- -q --header "X-Vault-Token: ${VAULT_TOKEN}" \
|
|
--post-data="$json" "$url" \
|
|
| jq -r .data.signed_key > "${key}-cert.pub"
|
|
if [ ! -s "${key}-cert.pub" ]
|
|
then
|
|
echo "Failed to sign ssh key"
|
|
exit 1
|
|
fi
|
|
|
|
##########################################################################
|
|
# do the rsync thing
|
|
|
|
echo "Copying: $rsync_src -> $rsync_dst"
|
|
echo "Options: $opts $extra_args"
|
|
|
|
for host in "${rsync_hosts[@]}"
|
|
do
|
|
hostname="rsync.tier2.${host}.burble.dn42"
|
|
echo "Syncing to host: $hostname"
|
|
rsync $opts --delete -e "ssh -i '${key}'" $extra_args \
|
|
"$rsync_src" "root@${hostname}:${rsync_dst}"
|
|
done
|
|
|
|
##########################################################################
|
|
# end of file
|