[ssh_tools] multicopy: don't require pscp
Fallback to plain SCP if parallel-scp is not available.
This commit is contained in:
parent
410ac3789b
commit
2b47bb65d2
|
@ -53,12 +53,24 @@ bad_usage()
|
||||||
|
|
||||||
err()
|
err()
|
||||||
{
|
{
|
||||||
printf 'Error! %s\n' "$@" >&2
|
printf 'Error! ' >&2
|
||||||
|
printf '%s\n' "$@" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
warn()
|
warn()
|
||||||
{
|
{
|
||||||
printf 'Warning! %s\n' "$@" >&2
|
printf 'Warning! ' >&2
|
||||||
|
printf '%s\n' "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy file $FILE to the remote hosts using plain old SCP
|
||||||
|
scp_copy()
|
||||||
|
{
|
||||||
|
grep -v '^#' "$HOSTS" | while read -r host ; do
|
||||||
|
[ -z "$host" ] && continue
|
||||||
|
echo "Deploying '$FILE' to '$host'..."
|
||||||
|
scp -r "$FILE" "${SSH_LOGIN}${host}:${DEST_DIR}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse CLI options
|
# Parse CLI options
|
||||||
|
@ -84,30 +96,38 @@ shift $((OPTIND - 1))
|
||||||
[ $# -lt 2 ] && bad_usage "Wrong number of arguments."
|
[ $# -lt 2 ] && bad_usage "Wrong number of arguments."
|
||||||
|
|
||||||
# Check the usage of -r and -R
|
# Check the usage of -r and -R
|
||||||
if [ "$DELETE" = "1" ] ; then
|
if [ "$DELETE" = 1 ] ; then
|
||||||
[ "$RSYNC" = "1" ] && bad_usage "Use either -r or -R, but not both."
|
[ "$RSYNC" = 1 ] && bad_usage "Use either -r or -R, but not both."
|
||||||
RSYNC=1
|
RSYNC=1
|
||||||
DELETE="-X --delete"
|
DELETE="-X --delete"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ignore -P if rsync is going to be used
|
# Ignore -P if rsync is going to be used
|
||||||
if [ "$RSYNC" = "1" ] && [ "$PARALLEL" = "1" ] ; then
|
if [ "$RSYNC" = 1 ] && [ "$PARALLEL" = 1 ] ; then
|
||||||
warn "Cannot transfer in parallel when using rsync: ignoring -P."
|
warn "Cannot transfer in parallel when using rsync: ignoring -P."
|
||||||
PARALLEL=
|
PARALLEL=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
if [ "$RSYNC" = 1 ] ; then
|
||||||
PRSYNC=$(command -v parallel-rsync || command -v prsync)
|
PRSYNC=$(command -v parallel-rsync || command -v prsync)
|
||||||
|
if [ -z "$PRSYNC" ] ; then
|
||||||
|
err "Parallel rsync (prsync) is required for this script to work with -r or -R."
|
||||||
|
exit $EXIT_DEPENDENCY
|
||||||
|
fi
|
||||||
|
|
||||||
|
else # $RSYNC != 1
|
||||||
|
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
||||||
|
if [ -z "$PSCP" ] ; then
|
||||||
|
warn "Parallel SSH (pssh) is not installed. Install it for best results."
|
||||||
|
if [ "$PARALLEL" = 1 ] ; then
|
||||||
|
warn "Parallel copy will not work without Parallel SSH. Ignoring -P."
|
||||||
|
PARALLEL=
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
MULTIPING=$(command -v multiping)
|
MULTIPING=$(command -v multiping)
|
||||||
if [ -z "$RSYNC" ] && [ -z "$PSCP" ] ; then
|
|
||||||
err "Parallel SSH (pssh) is required for this script to work."
|
|
||||||
exit $EXIT_DEPENDENCY
|
|
||||||
fi
|
|
||||||
if [ -z "$PRSYNC" ] ; then
|
|
||||||
err "Parallel rsync (prsync) is required for this script to work."
|
|
||||||
exit $EXIT_DEPENDENCY
|
|
||||||
fi
|
|
||||||
if [ -z "$MULTIPING" ] ; then
|
if [ -z "$MULTIPING" ] ; then
|
||||||
err "multiping (which should have been provided along with this" \
|
err "multiping (which should have been provided along with this" \
|
||||||
"script) is required for this script to work."
|
"script) is required for this script to work."
|
||||||
|
@ -150,7 +170,7 @@ fi
|
||||||
echo "Destination directory: $DEST_DIR"
|
echo "Destination directory: $DEST_DIR"
|
||||||
|
|
||||||
# Transfer the files in parallel...
|
# Transfer the files in parallel...
|
||||||
if [ "$PARALLEL" = "1" ] ; then
|
if [ "$PARALLEL" = 1 ] ; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR"
|
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR"
|
||||||
fi
|
fi
|
||||||
|
@ -162,11 +182,16 @@ for FILE in "$@" ; do
|
||||||
warn "This file doesn't exist, skipping."
|
warn "This file doesn't exist, skipping."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if [ "$RSYNC" = "1" ] ; then
|
if [ "$RSYNC" = 1 ] ; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
||||||
else
|
continue
|
||||||
|
fi
|
||||||
|
if [ -n "$PSCP" ] ; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
# If we're still here, that means we'll have to copy with plain SCP
|
||||||
|
scp_copy
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue