You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
VDN_PATH=$(readlink -f $(dirname $(command -v vdn))/..)
|
|
. $VDN_PATH/bin/functions.sh
|
|
GUEST_OWNER=$USER
|
|
|
|
rewrite_connection() {
|
|
if [[ $1 != *:* ]]; then
|
|
connection="$1"
|
|
else
|
|
connection=${1%:*}
|
|
local path=${1#*:}
|
|
local user=${connection%@*}
|
|
guest=${connection#*@}
|
|
connection="${user}@localhost:${path}"
|
|
fi
|
|
}
|
|
|
|
determine_redir_port() {
|
|
local redirs="$TMPDIR/vdn-$guest-${GUEST_OWNER}-redirs"
|
|
[[ ! -e $redirs ]] && error "Impossible de joindre $guest"
|
|
sshRedirPort=$(awk -F ':' '$1 == "tcp" && $3 == "22" {print $2}' "$redirs")
|
|
[[ -n $sshRedirPort ]] || error "Aucune redirection vers le port 22 du système $guest"
|
|
}
|
|
|
|
declare -a options=()
|
|
declare -a srcs=()
|
|
declare -a dest=()
|
|
guest=''
|
|
while [[ $# -ne 0 ]]; do
|
|
if [[ $1 == -* ]]; then
|
|
options+=("$1")
|
|
elif [[ $# -ne 1 ]]; then
|
|
rewrite_connection "$1"
|
|
srcs+=("$connection")
|
|
else
|
|
rewrite_connection "$1"
|
|
dest+=("$connection")
|
|
fi
|
|
shift
|
|
done
|
|
|
|
if [[ $guest ]]; then
|
|
determine_redir_port
|
|
rsync "${options[@]}" -e "ssh -g -p $sshRedirPort $SSH_OPTS -o StrictHostKeyChecking=no" "${srcs[@]}" "$dest"
|
|
else
|
|
rsync "${options[@]}" "${srcs[@]}" "${dest[@]}"
|
|
fi
|