|
Packit |
857059 |
#!/bin/bash
|
|
Packit |
857059 |
# BEGIN_ICS_COPYRIGHT8 ****************************************
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# Copyright (c) 2015-2018, Intel Corporation
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# Redistribution and use in source and binary forms, with or without
|
|
Packit |
857059 |
# modification, are permitted provided that the following conditions are met:
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
857059 |
# this list of conditions and the following disclaimer.
|
|
Packit |
857059 |
# * Redistributions in binary form must reproduce the above copyright
|
|
Packit |
857059 |
# notice, this list of conditions and the following disclaimer in the
|
|
Packit |
857059 |
# documentation and/or other materials provided with the distribution.
|
|
Packit |
857059 |
# * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
857059 |
# may be used to endorse or promote products derived from this software
|
|
Packit |
857059 |
# without specific prior written permission.
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
857059 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
857059 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Packit |
857059 |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
Packit |
857059 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
857059 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Packit |
857059 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Packit |
857059 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit |
857059 |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
857059 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# END_ICS_COPYRIGHT8 ****************************************
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# [ICS VERSION STRING: unknown]
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# optional override of defaults
|
|
Packit |
857059 |
if [ -f /etc/opa/opafastfabric.conf ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
. /etc/opa/opafastfabric.conf
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
. /usr/lib/opa/tools/opafastfabric.conf.def
|
|
Packit |
857059 |
|
|
Packit |
857059 |
. /usr/lib/opa/tools/ff_funcs
|
|
Packit |
857059 |
|
|
Packit |
857059 |
trap "exit 1" SIGHUP SIGTERM SIGINT
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Usage_full()
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
echo "Usage: opauploadall [-rp] [-f hostfile] [-d upload_dir] [-h 'hosts'] [-u user]" >&2
|
|
Packit |
857059 |
echo " source_file ... dest_file" >&2
|
|
Packit |
857059 |
echo " or" >&2
|
|
Packit |
857059 |
echo " opauploadall --help" >&2
|
|
Packit |
857059 |
echo " --help - produce full help text" >&2
|
|
Packit |
857059 |
echo " -p - perform copy in parallel on all hosts" >&2
|
|
Packit |
857059 |
echo " -r - recursive upload of directories" >&2
|
|
Packit |
857059 |
echo " -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
|
|
Packit |
857059 |
echo " -h hosts - list of hosts to upload from" >&2
|
|
Packit |
857059 |
echo " -u user - user to perform copy to, default is current user code" >&2
|
|
Packit |
857059 |
echo " -d upload_dir - directory to upload to, default is uploads" >&2
|
|
Packit |
857059 |
echo " source_file - list of source files to copy" >&2
|
|
Packit |
857059 |
echo " dest_file - destination for copy" >&2
|
|
Packit |
857059 |
echo " If more than 1 source file, this must be a directory" >&2
|
|
Packit |
857059 |
echo " Environment:" >&2
|
|
Packit |
857059 |
echo " HOSTS - list of hosts, used if -h option not supplied" >&2
|
|
Packit |
857059 |
echo " HOSTS_FILE - file containing list of hosts, used in absence of -f and -h" >&2
|
|
Packit |
857059 |
echo " UPLOADS_DIR - directory to upload to, used in absence of -d" >&2
|
|
Packit |
857059 |
echo " FF_MAX_PARALLEL - when -p option is used, maximum concurrent operations" >&2
|
|
Packit |
857059 |
echo "example:">&2
|
|
Packit |
857059 |
echo " opauploadall -h 'arwen elrond' capture.tgz /etc/init.d/ipoib.cfg ." >&2
|
|
Packit |
857059 |
echo " opauploadall -p capture.tgz /etc/init.d/ipoib.cfg ." >&2
|
|
Packit |
857059 |
echo " opauploadall capture.tgz /etc/init.d/ipoib.cfg pre-install" >&2
|
|
Packit |
857059 |
echo "user@ syntax cannot be used in filenames specified" >&2
|
|
Packit |
857059 |
echo "A local directory within upload_dir/ will be created for each hostname." >&2
|
|
Packit |
857059 |
echo "Destination file will be upload_dir/hostname/dest_file within the local system." >&2
|
|
Packit |
857059 |
echo "If copying multiple files, or dest_file has a trailing /, dest_file" >&2
|
|
Packit |
857059 |
echo " directory will be created." >&2
|
|
Packit |
857059 |
echo "To copy files from this host to hosts in the cluster use opascpall or" >&2
|
|
Packit |
857059 |
echo " opadownloadall." >&2
|
|
Packit |
857059 |
exit 0
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Usage()
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
echo "Usage: opauploadall [-rp] [-f hostfile] source_file ... dest_file" >&2
|
|
Packit |
857059 |
echo " or" >&2
|
|
Packit |
857059 |
echo " opauploadall --help" >&2
|
|
Packit |
857059 |
echo " --help - produce full help text" >&2
|
|
Packit |
857059 |
echo " -p - perform copy in parallel on all hosts" >&2
|
|
Packit |
857059 |
echo " -r - recursive upload of directories" >&2
|
|
Packit |
857059 |
echo " -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
|
|
Packit |
857059 |
echo " source_file - list of source files to copy" >&2
|
|
Packit |
857059 |
echo " dest_file - destination for copy" >&2
|
|
Packit |
857059 |
echo " If more than 1 source file, this must be a directory" >&2
|
|
Packit |
857059 |
echo "example:">&2
|
|
Packit |
857059 |
echo " opauploadall -p capture.tgz /etc/init.d/ipoib.cfg ." >&2
|
|
Packit |
857059 |
echo " opauploadall capture.tgz /etc/init.d/ipoib.cfg pre-install" >&2
|
|
Packit |
857059 |
echo "user@ syntax cannot be used in filenames specified" >&2
|
|
Packit |
857059 |
echo "A local directory within uploads/ will be created for each hostname." >&2
|
|
Packit |
857059 |
echo "Destination file will be uploads/hostname/dest_file within the local system." >&2
|
|
Packit |
857059 |
echo "If copying multiple files, or dest_file has a trailing /, dest_file" >&2
|
|
Packit |
857059 |
echo " directory will be created." >&2
|
|
Packit |
857059 |
echo "To copy files from this host to hosts in the cluster use opascpall or" >&2
|
|
Packit |
857059 |
echo " opadownloadall." >&2
|
|
Packit |
857059 |
exit 2
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if [ x"$1" = "x--help" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
Usage_full
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
user=`id -u -n`
|
|
Packit |
857059 |
opts=
|
|
Packit |
857059 |
popt=n
|
|
Packit |
857059 |
while getopts f:d:h:u:rp param
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
case $param in
|
|
Packit |
857059 |
f)
|
|
Packit |
857059 |
HOSTS_FILE="$OPTARG";;
|
|
Packit |
857059 |
d)
|
|
Packit |
857059 |
UPLOADS_DIR="$OPTARG";;
|
|
Packit |
857059 |
h)
|
|
Packit |
857059 |
HOSTS="$OPTARG";;
|
|
Packit |
857059 |
u)
|
|
Packit |
857059 |
user="$OPTARG";;
|
|
Packit |
857059 |
r)
|
|
Packit |
857059 |
opts="$opts -r";;
|
|
Packit |
857059 |
p)
|
|
Packit |
857059 |
opts="$opts -q"
|
|
Packit |
857059 |
popt=y;;
|
|
Packit |
857059 |
?)
|
|
Packit |
857059 |
Usage;;
|
|
Packit |
857059 |
esac
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
shift $((OPTIND -1))
|
|
Packit |
857059 |
if [ $# -lt 2 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
Usage
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
check_host_args opauploadall
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# remove last name from the list
|
|
Packit |
857059 |
files=
|
|
Packit |
857059 |
dest=
|
|
Packit |
857059 |
file_count=0
|
|
Packit |
857059 |
for file in "$@"
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
if [ ! -z "$dest" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
if [ ! -z "$files" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
files="$files $dest"
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
files="$dest"
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
file_count=`expr $file_count + 1`
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
dest="$file"
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# Determine if we need to create a directory
|
|
Packit |
857059 |
create_dir=y
|
|
Packit |
857059 |
if [ $file_count -le 1 ] && [ "${dest: -1}" != "/" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
create_dir=n
|
|
Packit |
857059 |
echo "$files" | grep -e "*" -e "\[" -e "?" >/dev/null
|
|
Packit |
857059 |
if [ "$?" -eq 0 ]; then
|
|
Packit |
857059 |
echo "opauploadall: Warning: possible wildcards in source_file. If multiple" >&2
|
|
Packit |
857059 |
echo " files may match, dest_file should be a directory with trailing /" >&2
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# Convert files to an array to iterate through while
|
|
Packit |
857059 |
# avoiding wildcard expansion
|
|
Packit |
857059 |
read -a files <<< $files
|
|
Packit |
857059 |
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
pids=""
|
|
Packit |
857059 |
stat=0
|
|
Packit |
857059 |
for hostname in $HOSTS
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
src_files=
|
|
Packit |
857059 |
for file in "${files[@]}"
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
src_files="$src_files $user@[$hostname]:$file"
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
mkdir -p $UPLOADS_DIR/$hostname
|
|
Packit |
857059 |
if [ "$create_dir" == "y" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
mkdir -p $UPLOADS_DIR/$hostname/$dest
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if [ "$popt" = "y" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
if [ $running -ge $FF_MAX_PARALLEL ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
for pid in $pids; do
|
|
Packit |
857059 |
wait $pid
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]; then
|
|
Packit |
857059 |
stat=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
pids=""
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
echo "scp $opts $src_files $UPLOADS_DIR/$hostname/$dest"
|
|
Packit |
857059 |
scp $opts $src_files $UPLOADS_DIR/$hostname/$dest &
|
|
Packit |
857059 |
pid=$!
|
|
Packit |
857059 |
pids="$pids $pid"
|
|
Packit |
857059 |
running=$(( $running + 1))
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
echo "scp $opts $src_files $UPLOADS_DIR/$hostname/$dest"
|
|
Packit |
857059 |
scp $opts $src_files $UPLOADS_DIR/$hostname/$dest
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]; then
|
|
Packit |
857059 |
stat=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
for pid in $pids; do
|
|
Packit |
857059 |
wait $pid
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]; then
|
|
Packit |
857059 |
stat=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
exit $stat
|