125 lines
3.1 KiB
Bash
Executable File
125 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
toolName="ssh"
|
|
toolIdentity="~/.ssh/id_rsa"
|
|
|
|
aList=""
|
|
aHost=""
|
|
# default ssh port
|
|
aPort="22"
|
|
|
|
step_3_info() { echo "Create $toolName authentication keys"; }
|
|
step_3_alias() { ALIAS="create"; }
|
|
step_3() {
|
|
exep "ssh-keygen -l -f $toolIdentity 2>>/dev/null"
|
|
if [ $? -ne 0 ]; then
|
|
saveReturn 1
|
|
else
|
|
saveReturn 1
|
|
fi
|
|
endReturn -f "Identity found. Skipping creation"
|
|
echo "Creating..."
|
|
}
|
|
|
|
step_10_info() { echo "Update remote(s) [CMDLIST] <USER:HOST>"; }
|
|
step_10_alias() { ALIAS="send"; }
|
|
step_10() {
|
|
aList=$2
|
|
aHost=$3
|
|
# Set port only if not empty
|
|
if [ ! -z "$4" ] || [ "$4" != "" ]; then
|
|
aPort=$4
|
|
fi
|
|
parseList $aList
|
|
saveReturn $?
|
|
endReturn
|
|
}
|
|
|
|
# parseList [CMDFILE]
|
|
# Parse a list to transfer files and/or execute commands on one or different hosts
|
|
#
|
|
# List format
|
|
# [COMMAND h,f,u]|[STRING]|[STRING2]
|
|
# COMMAND h|H|host - Change user@host:port for the following ssh/scp commands
|
|
# f|F|file - Source- and destination file path combination
|
|
# u|U|update - Execute command on the remote host
|
|
#
|
|
# STRING h - user@host
|
|
# f - source file path
|
|
# u - shell command string
|
|
#
|
|
# STRING2 h - port
|
|
# f - destination file path
|
|
# u - not used
|
|
#
|
|
parseList() {
|
|
if [ -z "$1" ] || [ ! -f "$1" ]; then
|
|
if [ -z "$1" ] || [ "$1" == "" ] ; then
|
|
echo " [E] No Command list found"
|
|
else
|
|
echo " [E] Command list not found: $1"
|
|
fi
|
|
if [ ! -z "$1" ] && [ $DRY == 0 ] && [ $QUIET == 0 ] ; then
|
|
read -p " Create template there y/[n]? " answer
|
|
case "$answer" in
|
|
y|Y)
|
|
addConf -s "$listFileTemplate" "$1"
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
fi
|
|
return 1
|
|
fi
|
|
echo " [I] Parsing $1 ..."
|
|
while IFS='|' read -r lcmd lsrc ldst; do
|
|
case "$lcmd" in
|
|
h|H|host)
|
|
aHost="$lsrc"
|
|
if [ ! -z "$ldst" ] || [ "$ldst" != "" ]; then
|
|
aPort=$ldst
|
|
else
|
|
# Set port (back) to default in case no port is given
|
|
# after previous change
|
|
aPort=22
|
|
fi
|
|
echo Host update: ${aHost}:$aPort
|
|
;;
|
|
f|F|file)
|
|
if [ -z "$aHost" ] || [ "$aHost" == "" ]; then
|
|
echo " [E] No host found"
|
|
return 1
|
|
fi
|
|
echo "scp -p $aPort $lsrc ${aHost}:$ldst"
|
|
;;
|
|
u|U|update)
|
|
if [ -z "$aHost" ] || [ "$aHost" == "" ]; then
|
|
echo " [E] No host found"
|
|
return 1
|
|
fi
|
|
echo "ssh -p $aPort $aHost $lsrc"
|
|
;;
|
|
*)
|
|
continue
|
|
;;
|
|
esac
|
|
done < "$1"
|
|
}
|
|
|
|
listFileTemplate="# following files are send to host given on command line
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
# host and port are changed for the following files
|
|
h|user@host2|port2
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
u|/destdir/updatescript.sh
|
|
# host is changed and port set to default 22 for the following files
|
|
h|user@host
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
f|/sourcedir/sourcefile|/destdir/destfile
|
|
u|/destdir2/update.sh"
|
|
|
|
VERSION_SEQREV=6
|
|
. sequencer.sh
|