From ea2629c2a5d46b9efdef8a99278f694104b7a520 Mon Sep 17 00:00:00 2001 From: q3aql Date: Fri, 10 Feb 2023 18:28:20 +0100 Subject: [PATCH] Add support for using expect for login uploads (ks-upv/upf/upa/upr) --- cygwin/bin/cygwin-alias.sh | 1 + src/ks-upa | 131 +++++++++++++++++++++++++++++++++++-- src/ks-upf | 131 +++++++++++++++++++++++++++++++++++-- src/ks-upr | 72 ++++++++++++++++++-- src/ks-upv | 131 +++++++++++++++++++++++++++++++++++-- 5 files changed, 443 insertions(+), 23 deletions(-) diff --git a/cygwin/bin/cygwin-alias.sh b/cygwin/bin/cygwin-alias.sh index 6ffa9e9..c92b41e 100755 --- a/cygwin/bin/cygwin-alias.sh +++ b/cygwin/bin/cygwin-alias.sh @@ -34,6 +34,7 @@ alias ssh-keygen="/usr/bin/ssh-keygen" alias ssh-keyscan="/usr/bin/ssh-keyscan" alias ssh="/usr/bin/ssh" alias sshpass="/usr/bin/sshpass" +alias expect="/usr/bin/expect" alias tail="/usr/bin/tail" alias touch="/usr/bin/touch" alias tr="/usr/bin/tr" diff --git a/src/ks-upa b/src/ks-upa index 8d8c238..364cf77 100755 --- a/src/ks-upa +++ b/src/ks-upa @@ -7,7 +7,7 @@ # Contact: q3aql@duck.com # ######################################################################## VERSION="8.4-dev" -M_DATE="040222" +M_DATE="100223" # Global parameters. dirTemp="/tmp" @@ -144,6 +144,46 @@ function sendFile() { /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + /usr/bin/ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + /usr/bin/expect < /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -161,6 +201,46 @@ function sendFile() { rsync --progress -azL --rsh="sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + expect < /dev/null sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -195,6 +275,7 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + selectedTool=$(cat ${dirConfig}/ks-upload-tool) portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then @@ -202,6 +283,12 @@ function checkChecksum() { checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + OUTPUT=0 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + OUTPUT=0 else checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -212,6 +299,10 @@ function checkChecksum() { checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null else checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -227,9 +318,17 @@ function checkChecksum() { correct=1 fi else + if [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + correct=1 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + correct=1 + else echo "Local checksum: ${checksumLocal}" echo "Server checksum: ${checksumServer}" correct=1 + fi fi done } @@ -420,8 +519,12 @@ function editConfig() { echo "- rsync" echo "- scp-rsa (legacy RSA algorithm)" echo "- rsync-rsa (legacy RSA algorithm)" + echo "- scp-e" + echo "- rsync-e" echo "" - echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL + echo "* Note: 'scp-e' and 'rsync-e' use 'expect' instead of 'sshpass'." + echo "" + echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa/scp-e/rsync-e): " ; read TOOL if [ -z "${TOOL}" ] ; then upvTool="scp" elif [ "${TOOL}" == "rsync" ] ; then @@ -430,6 +533,10 @@ function editConfig() { upvTool="rsync-rsa" elif [ "${TOOL}" == "scp-rsa" ] ; then upvTool="scp-rsa" + elif [ "${TOOL}" == "scp-e" ] ; then + upvTool="scp-e" + elif [ "${TOOL}" == "rsync-e" ] ; then + upvTool="rsync-e" else upvTool="scp" fi @@ -560,6 +667,12 @@ function checkDependencies() { echo "* The 'sshpass' tool is not installed!" dependence=1 fi + expect -v &> /dev/null + OUTPUT=$? + if [ ${OUTPUT} -ne 0 ] ; then + echo "* The 'expect' tool is not installed!" + dependence=1 + fi md5sum --help &> /dev/null OUTPUT=$? if [ ${OUTPUT} -ne 0 ] ; then @@ -699,12 +812,12 @@ elif [ "${1}" == "-i" ] ; then current_tool=$(cat ${dirConfig}/ks-upload-tool) if [ "${current_tool}" == "scp" ] ; then echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upa -e)" + echo "* IMPORTANT: It's possible switch to 'rsync' or 'scp-e' if you wish (Command: ks-upa -e)" echo "" fi if [ "${current_tool}" == "scp-rsa" ] ; then - echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upa -e)" + echo "* NOTE: You are using 'scp-rsa' to upload files and no progress will be shown." + echo "* IMPORTANT: It's possible switch to 'rsync-rsa' if you wish (Command: ks-upa -e)" echo "" fi while [ ${count} -le ${totalFiles} ] ; do @@ -712,7 +825,13 @@ elif [ "${1}" == "-i" ] ; then fullPathFile=$(showPathFile ${count}) echo "Uploading '${fullNameFile}' " sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} - checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + if [ "${current_tool}" == "scp-e" ] ; then + echo > /dev/null + elif [ "${current_tool}" == "rsync-e" ] ; then + echo > /dev/null + else + checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + fi echo "" count=$(expr ${count} + 1) done diff --git a/src/ks-upf b/src/ks-upf index e6b0390..074261f 100755 --- a/src/ks-upf +++ b/src/ks-upf @@ -7,7 +7,7 @@ # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="040222" +M_DATE="100223" # Global parameters. dirTemp="/tmp" @@ -171,6 +171,46 @@ function sendFile() { /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + /usr/bin/ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + /usr/bin/expect < /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -188,6 +228,46 @@ function sendFile() { rsync --progress -azL --rsh="sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + expect < /dev/null sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -222,6 +302,7 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + selectedTool=$(cat ${dirConfig}/ks-upload-tool) portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then @@ -229,6 +310,12 @@ function checkChecksum() { checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + OUTPUT=0 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + OUTPUT=0 else checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -239,6 +326,10 @@ function checkChecksum() { checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null else checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -254,9 +345,17 @@ function checkChecksum() { correct=1 fi else + if [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + correct=1 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + correct=1 + else echo "Local checksum: ${checksumLocal}" echo "Server checksum: ${checksumServer}" correct=1 + fi fi done } @@ -447,8 +546,12 @@ function editConfig() { echo "- rsync" echo "- scp-rsa (legacy RSA algorithm)" echo "- rsync-rsa (legacy RSA algorithm)" + echo "- scp-e" + echo "- rsync-e" echo "" - echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL + echo "* Note: 'scp-e' and 'rsync-e' use 'expect' instead of 'sshpass'." + echo "" + echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa/scp-e/rsync-e): " ; read TOOL if [ -z "${TOOL}" ] ; then upvTool="scp" elif [ "${TOOL}" == "rsync" ] ; then @@ -457,6 +560,10 @@ function editConfig() { upvTool="rsync-rsa" elif [ "${TOOL}" == "scp-rsa" ] ; then upvTool="scp-rsa" + elif [ "${TOOL}" == "scp-e" ] ; then + upvTool="scp-e" + elif [ "${TOOL}" == "rsync-e" ] ; then + upvTool="rsync-e" else upvTool="scp" fi @@ -587,6 +694,12 @@ function checkDependencies() { echo "* The 'sshpass' tool is not installed!" dependence=1 fi + expect -v &> /dev/null + OUTPUT=$? + if [ ${OUTPUT} -ne 0 ] ; then + echo "* The 'expect' tool is not installed!" + dependence=1 + fi md5sum --help &> /dev/null OUTPUT=$? if [ ${OUTPUT} -ne 0 ] ; then @@ -726,12 +839,12 @@ elif [ "${1}" == "-i" ] ; then current_tool=$(cat ${dirConfig}/ks-upload-tool) if [ "${current_tool}" == "scp" ] ; then echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upf -e)" + echo "* IMPORTANT: It's possible switch to 'rsync' or 'scp-e' if you wish (Command: ks-upf -e)" echo "" fi if [ "${current_tool}" == "scp-rsa" ] ; then - echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upf -e)" + echo "* NOTE: You are using 'scp-rsa' to upload files and no progress will be shown." + echo "* IMPORTANT: It's possible switch to 'rsync-rsa' if you wish (Command: ks-upf -e)" echo "" fi while [ ${count} -le ${totalFiles} ] ; do @@ -739,7 +852,13 @@ elif [ "${1}" == "-i" ] ; then fullPathFile=$(showPathFile ${count}) echo "Uploading '${fullNameFile}' " sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} - checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + if [ "${current_tool}" == "scp-e" ] ; then + echo > /dev/null + elif [ "${current_tool}" == "rsync-e" ] ; then + echo > /dev/null + else + checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + fi echo "" count=$(expr ${count} + 1) done diff --git a/src/ks-upr b/src/ks-upr index 5d760dc..30901f9 100755 --- a/src/ks-upr +++ b/src/ks-upr @@ -7,7 +7,7 @@ # Contact: q3aql@duck.com # ############################################################################## VERSION="8.4-dev" -M_DATE="040222" +M_DATE="100223" # Global parameters. dirTemp="/tmp" @@ -151,6 +151,30 @@ function sendFile() { echo "+ Syncing folder ${2} to ${5} (${4})" /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + /usr/bin/ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + /usr/bin/expect < /dev/null sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + expect < /dev/null + OUTPUT=$? + if [ ${OUTPUT} -ne 0 ] ; then + echo "* The 'expect' tool is not installed!" + dependence=1 + fi md5sum --help &> /dev/null OUTPUT=$? if [ ${OUTPUT} -ne 0 ] ; then @@ -649,12 +711,12 @@ elif [ "${1}" == "-i" ] ; then if [ "${current_tool}" == "scp" ] ; then echo "" echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upr -e)" + echo "* IMPORTANT: It's possible switch to 'rsync' or 'scp-e' if you wish (Command: ks-upr -e)" fi if [ "${current_tool}" == "scp-rsa" ] ; then echo "" - echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upr -e)" + echo "* NOTE: You are using 'scp-rsa' to upload files and no progress will be shown." + echo "* IMPORTANT: It's possible switch to 'rsync-rsa' if you wish (Command: ks-upr -e)" fi if [ -d ${dirLocal} ] ; then sendFile ${password} "${dirLocal}" ${user} ${server} ${dirServer} diff --git a/src/ks-upv b/src/ks-upv index 5f975b9..434c78c 100755 --- a/src/ks-upv +++ b/src/ks-upv @@ -7,7 +7,7 @@ # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="040222" +M_DATE="100223" # Global parameters. dirTemp="/tmp" @@ -144,6 +144,46 @@ function sendFile() { /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + /usr/bin/ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + /usr/bin/expect < /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -161,6 +201,46 @@ function sendFile() { rsync --progress -azL --rsh="sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null OUTPUT=$? + elif [ "${toolSelected}" == "rsync-e" ] ; then + keyscan_host=$(cat ~/.ssh/known_hosts | grep ${4}) + if [ -z "${keyscan_host}" ] ; then + ssh-keyscan -p ${portSelected} ${4} >> ~/.ssh/known_hosts + fi + # Sync files using rsync with expect + expect < /dev/null sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null @@ -195,6 +275,7 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + selectedTool=$(cat ${dirConfig}/ks-upload-tool) portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then @@ -202,6 +283,12 @@ function checkChecksum() { checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + OUTPUT=0 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + OUTPUT=0 else checksumLocal=$(/usr/bin/md5sum ${2}) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -212,6 +299,10 @@ function checkChecksum() { checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? + elif [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null else checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) @@ -227,9 +318,17 @@ function checkChecksum() { correct=1 fi else + if [ "${selectedTool}" == "rsync-e" ] ; then + echo > /dev/null + correct=1 + elif [ "${selectedTool}" == "scp-e" ] ; then + echo > /dev/null + correct=1 + else echo "Local checksum: ${checksumLocal}" echo "Server checksum: ${checksumServer}" correct=1 + fi fi done } @@ -420,8 +519,12 @@ function editConfig() { echo "- rsync" echo "- scp-rsa (legacy RSA algorithm)" echo "- rsync-rsa (legacy RSA algorithm)" + echo "- scp-e" + echo "- rsync-e" echo "" - echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL + echo "* Note: 'scp-e' and 'rsync-e' use 'expect' instead of 'sshpass'." + echo "" + echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa/scp-e/rsync-e): " ; read TOOL if [ -z "${TOOL}" ] ; then upvTool="scp" elif [ "${TOOL}" == "rsync" ] ; then @@ -430,6 +533,10 @@ function editConfig() { upvTool="rsync-rsa" elif [ "${TOOL}" == "scp-rsa" ] ; then upvTool="scp-rsa" + elif [ "${TOOL}" == "scp-e" ] ; then + upvTool="scp-e" + elif [ "${TOOL}" == "rsync-e" ] ; then + upvTool="rsync-e" else upvTool="scp" fi @@ -560,6 +667,12 @@ function checkDependencies() { echo "* The 'sshpass' tool is not installed!" dependence=1 fi + expect -v &> /dev/null + OUTPUT=$? + if [ ${OUTPUT} -ne 0 ] ; then + echo "* The 'expect' tool is not installed!" + dependence=1 + fi md5sum --help &> /dev/null OUTPUT=$? if [ ${OUTPUT} -ne 0 ] ; then @@ -700,12 +813,12 @@ elif [ "${1}" == "-i" ] ; then current_tool=$(cat ${dirConfig}/ks-upload-tool) if [ "${current_tool}" == "scp" ] ; then echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)" + echo "* IMPORTANT: It's possible switch to 'rsync' or 'scp-e' if you wish (Command: ks-upv -e)" echo "" fi if [ "${current_tool}" == "scp-rsa" ] ; then - echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." - echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)" + echo "* NOTE: You are using 'scp-rsa' to upload files and no progress will be shown." + echo "* IMPORTANT: It's possible switch to 'rsync-rsa' if you wish (Command: ks-upv -e)" echo "" fi while [ ${count} -le ${totalFiles} ] ; do @@ -713,7 +826,13 @@ elif [ "${1}" == "-i" ] ; then fullPathFile=$(showPathFile ${count}) echo "Uploading '${fullNameFile}' " sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} - checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + if [ "${current_tool}" == "scp-e" ] ; then + echo > /dev/null + elif [ "${current_tool}" == "rsync-e" ] ; then + echo > /dev/null + else + checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} + fi echo "" count=$(expr ${count} + 1) done