2013-04-29 22:43:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# cluster-deploy.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr>
|
|
|
|
#
|
|
|
|
# This program is free software. It comes without any warranty, to
|
|
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
#
|
|
|
|
# Deploy files on a number of remote hosts using Parallel SCP.
|
2013-05-02 17:18:24 +02:00
|
|
|
|
2013-05-02 16:56:28 +02:00
|
|
|
#set -x
|
2013-04-29 22:43:41 +02:00
|
|
|
|
2013-05-01 22:12:09 +02:00
|
|
|
print_usage()
|
|
|
|
{
|
2013-05-02 17:18:24 +02:00
|
|
|
echo "Usage:"
|
|
|
|
echo " $0 [-P] [-l login] <hosts_list> <file1> [file2 [...]]"
|
|
|
|
echo "-P: transfer files in parallel instead of one by one."
|
2013-05-01 22:12:09 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 17:18:24 +02:00
|
|
|
# Parse the optional arguments
|
|
|
|
while [ $# -gt 2 ] ; do
|
|
|
|
case $1 in
|
|
|
|
"-l")
|
|
|
|
LOGIN="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"-P")
|
|
|
|
PARALLEL=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Do we still have at least a host list and a file?
|
|
|
|
# Note: if the program was wrongly called but still has 2 arguments, for
|
|
|
|
# example with "cluster-deploy -l root -P my_file", it will try to use
|
|
|
|
# "-P" as hosts' list and "my_file" as the file to be transfered.
|
2013-05-02 16:56:28 +02:00
|
|
|
if [ $# -lt 2 ] ; then
|
2013-05-01 22:12:09 +02:00
|
|
|
print_usage
|
2013-04-29 22:43:41 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2013-05-01 22:12:09 +02:00
|
|
|
|
|
|
|
# Check dependencies
|
2013-04-29 22:43:41 +02:00
|
|
|
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
|
|
|
if [ "$PSCP" = "" ] ; then
|
|
|
|
echo "Parallel SSH (pssh) is required for this script to work."
|
2013-05-01 22:12:09 +02:00
|
|
|
exit 4
|
2013-04-29 22:43:41 +02:00
|
|
|
fi
|
|
|
|
|
2013-05-01 22:12:09 +02:00
|
|
|
# Hosts' list file
|
2013-04-29 22:43:41 +02:00
|
|
|
HOSTS="$HOME/.config/cluster/$1.lst"
|
|
|
|
shift
|
|
|
|
echo "Using file '$HOSTS' as hosts' list."
|
|
|
|
|
2013-05-01 22:12:09 +02:00
|
|
|
# Login
|
|
|
|
if [ "$LOGIN" != "" ] ; then
|
|
|
|
echo "Login: $LOGIN"
|
|
|
|
LOGIN="-l $LOGIN"
|
|
|
|
fi
|
|
|
|
|
2013-05-02 17:18:24 +02:00
|
|
|
# Transfer the files in parallel...
|
|
|
|
if [ "$PARALLEL" = "1" ] ; then
|
|
|
|
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" ~
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ... or one by one
|
2013-05-02 16:56:28 +02:00
|
|
|
for FILE in "$@" ; do
|
2013-04-29 22:43:41 +02:00
|
|
|
echo "Deploying '$FILE'..."
|
2013-05-02 16:57:30 +02:00
|
|
|
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~
|
2013-04-29 22:43:41 +02:00
|
|
|
done
|