#!/bin/sh # # cluster-deploy.sh, Copyright © 2013 Matteo Cypriani # # 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. print_usage() { echo "Usage: $0 [-l login] [file2 [...]]" } # Parse the optional arguments with getopt export POSIXLY_CORRECT=yes export GETOPT_COMPATIBLE=yes OPTSTRING="l:" ARGS=$(getopt $OPTSTRING $*) if [ $? -ne 0 ] ; then print_usage exit 1 fi set -- $ARGS while [ $# -ne 0 ] ; do case "$1" in -l) LOGIN="$2" shift shift ;; --) shift break ;; *) echo "Unknown argument:" $1 exit 2 esac done # Do we have at least a host list and a command? if [ $# -lt 2 ] ; then print_usage exit 3 fi # Check dependencies 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 fi # Hosts' list file 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 echo "Deploying '$FILE'..." $PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" /root done