scripts/cluster/cluster-deploy.sh

60 lines
1.3 KiB
Bash
Raw Normal View History

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.
#set -x
2013-04-29 22:43:41 +02:00
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list> <file1> [file2 [...]]"
}
# Do we have at least a host list and a file?
if [ $# -lt 2 ] ; then
print_usage
2013-04-29 22:43:41 +02:00
exit 1
fi
# Parse the optional arguments
if [ "$1" = "-l" ] ; then
LOGIN="$2"
shift
shift
# Do we still have at least a host list and a file?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
fi
2013-04-29 22:43:41 +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."
exit 4
2013-04-29 22:43:41 +02:00
fi
# 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."
# Login
if [ "$LOGIN" != "" ] ; then
echo "Login: $LOGIN"
LOGIN="-l $LOGIN"
fi
for FILE in "$@" ; do
2013-04-29 22:43:41 +02:00
echo "Deploying '$FILE'..."
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~
2013-04-29 22:43:41 +02:00
done