Implement NVIT export settings.
[sitka/sitka-tools.git] / deployment / deployfile.sh
CommitLineData
0155bbac
JD
1#!/bin/bash
2
3usage()
4{
5 cat <<EOF
6USAGE:
7./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
8
9OPTIONS:
10 -f Name of file to be deployed
11 -p Path on remote server where file should be deployed to
12 -u Username to use when logging into remote server; if not provided, defaults to current user
13 -b Backup flag (optional); creates a backup instead of overwriting file on remote server
14 -h Print this message and exit
15EOF
16}
17
18while getopts ":f:p:u:bh" opt
19do
20 case $opt in
21 f ) FILE=$OPTARG;;
22 p ) DEST=$OPTARG;;
23 u ) USER=$OPTARG;;
24 b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
25 h ) usage && exit 0;;
26 esac
27done
28shift $(($OPTIND - 1))
29
30if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
31then
32 usage
33 exit 1
34else
35
36 if [[ -z "$BACKUP" ]]
37 then
38 SSH="ssh"
39 else
40 SSH="ssh -l${USER}"
41 fi
42
43 for HOST in "$@"
44 do
45 RSYNC_DEST="${HOST}:${DEST}"
46 #echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
47 rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
48 done
49fi