Add option for legacy RSA Algorithm

This commit is contained in:
q3aql 2022-01-23 00:03:17 +01:00
parent 9e970d5e37
commit 209c2167ab
8 changed files with 337 additions and 94 deletions

BIN
src/.ks-upa.swp Normal file

Binary file not shown.

BIN
src/.ks-upf.swp Normal file

Binary file not shown.

BIN
src/.ks-upr.swp Normal file

Binary file not shown.

BIN
src/.ks-upv.swp Normal file

Binary file not shown.

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
##################################################################### ########################################################################
# ks-upa (ks-tools) - Upload audio file(s) to server with rsync+ssh # # ks-upa (ks-tools) - Upload audio file(s) to server with scp or rsync #
# Date: 22-01-2022 # # Date: 22-01-2022 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
##################################################################### ########################################################################
VERSION="8.2" VERSION="8.2"
M_DATE="220122" M_DATE="220122"
@ -134,14 +134,23 @@ function showPathFile() {
# check_fingerprint <user> <server> # check_fingerprint <user> <server>
function check_fingerprint() { function check_fingerprint() {
fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}")
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
if [ -z "${fingerprint_host}" ] ; then if [ -z "${fingerprint_host}" ] ; then
# Run command for upload on Windows (Cygwin) # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
/usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
/usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -153,11 +162,19 @@ function check_fingerprint() {
fi fi
# Run command for upload on Unix systems # Run command for upload on Unix systems
else else
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -184,6 +201,13 @@ function sendFile() {
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
/usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
/usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -194,6 +218,13 @@ function sendFile() {
rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -220,15 +251,28 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(/usr/bin/md5sum ${2}) checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else else
checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
else
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else
checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
fi fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
@ -416,11 +460,25 @@ function editConfig() {
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
echo -n "* [Default: scp] Type upload tool (scp or rsync): " ; read TOOL echo ""
echo "* Available options:"
echo ""
echo "- scp"
echo "- rsync"
echo "- scp-rsa (legacy RSA algorithm)"
echo "- rsync-rsa (legacy RSA algorithm)"
echo ""
echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL
if [ -z "${TOOL}" ] ; then if [ -z "${TOOL}" ] ; then
upvTool="scp" upvTool="scp"
elif [ "${TOOL}" == "rsync" ] ; then
upvTool="rsync"
elif [ "${TOOL}" == "rsync-rsa" ] ; then
upvTool="rsync-rsa"
elif [ "${TOOL}" == "scp-rsa" ] ; then
upvTool="scp-rsa"
else else
upvTool=${TOOL} upvTool="scp"
fi fi
echo ${upvTool} > ${dirConfig}/ks-upload-tool echo ${upvTool} > ${dirConfig}/ks-upload-tool
elif [ "${EDIT}" == "7" ] ; then elif [ "${EDIT}" == "7" ] ; then
@ -504,7 +562,7 @@ function showHelp() {
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload audio file(s) to server with rsync+ssh" echo "- Upload audio file(s) to server with scp or rsync"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
@ -673,6 +731,11 @@ elif [ "${1}" == "-i" ] ; then
echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)" echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)"
echo "" echo ""
fi 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 ""
fi
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
###################################################################### #########################################################################
# ks-upf (ks-tools) - Upload common file(s) to server with rsync+ssh # # ks-upf (ks-tools) - Upload common file(s) to server with scp or rsync #
# Date: 22-01-2022 # # Date: 22-01-2022 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
###################################################################### #########################################################################
VERSION="8.2" VERSION="8.2"
M_DATE="220122" M_DATE="220122"
@ -161,14 +161,23 @@ function showPathFile() {
# check_fingerprint <user> <server> # check_fingerprint <user> <server>
function check_fingerprint() { function check_fingerprint() {
fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}")
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
if [ -z "${fingerprint_host}" ] ; then if [ -z "${fingerprint_host}" ] ; then
# Run command for upload on Windows (Cygwin) # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
/usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
/usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -180,11 +189,19 @@ function check_fingerprint() {
fi fi
# Run command for upload on Unix systems # Run command for upload on Unix systems
else else
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -211,6 +228,13 @@ function sendFile() {
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
/usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
/usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -221,6 +245,13 @@ function sendFile() {
rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -247,15 +278,28 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(/usr/bin/md5sum ${2}) checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else else
checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
else
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else
checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
fi fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
@ -443,11 +487,25 @@ function editConfig() {
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
echo -n "* [Default: scp] Type upload tool (scp or rsync): " ; read TOOL echo ""
echo "* Available options:"
echo ""
echo "- scp"
echo "- rsync"
echo "- scp-rsa (legacy RSA algorithm)"
echo "- rsync-rsa (legacy RSA algorithm)"
echo ""
echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL
if [ -z "${TOOL}" ] ; then if [ -z "${TOOL}" ] ; then
upvTool="scp" upvTool="scp"
elif [ "${TOOL}" == "rsync" ] ; then
upvTool="rsync"
elif [ "${TOOL}" == "rsync-rsa" ] ; then
upvTool="rsync-rsa"
elif [ "${TOOL}" == "scp-rsa" ] ; then
upvTool="scp-rsa"
else else
upvTool=${TOOL} upvTool="scp"
fi fi
echo ${upvTool} > ${dirConfig}/ks-upload-tool echo ${upvTool} > ${dirConfig}/ks-upload-tool
elif [ "${EDIT}" == "7" ] ; then elif [ "${EDIT}" == "7" ] ; then
@ -531,7 +589,7 @@ function showHelp() {
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload common file(s) to server with rsync+ssh" echo "- Upload common file(s) to server with scp or rsync"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
@ -700,6 +758,11 @@ elif [ "${1}" == "-i" ] ; then
echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)" echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)"
echo "" echo ""
fi 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 ""
fi
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
########################################################################### ##############################################################################
# ks-upr (ks-tools) - Upload recursively file(s) to server with rsync+ssh # # ks-upr (ks-tools) - Upload recursively file(s) to server with scp or rsync #
# Date: 22-01-2022 # # Date: 22-01-2022 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
########################################################################### ##############################################################################
VERSION="8.2" VERSION="8.2"
M_DATE="220122" M_DATE="220122"
@ -144,14 +144,23 @@ function showFile() {
# check_fingerprint <user> <server> # check_fingerprint <user> <server>
function check_fingerprint() { function check_fingerprint() {
fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}")
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
if [ -z "${fingerprint_host}" ] ; then if [ -z "${fingerprint_host}" ] ; then
# Run command for upload on Windows (Cygwin) # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
/usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
/usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -163,11 +172,19 @@ function check_fingerprint() {
fi fi
# Run command for upload on Unix systems # Run command for upload on Unix systems
else else
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -191,6 +208,15 @@ function sendFile() {
echo "+ Syncing folder ${2} to ${5} (${4})" echo "+ Syncing folder ${2} to ${5} (${4})"
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
echo ""
echo "+ Syncing folder ${2} to ${5} (${4})"
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
elif [ "${toolSelected}" == "scp-rsa" ] ; then
echo ""
echo "+ Sending files from ${2} to ${5} (${4})"
/usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null
else else
echo "" echo ""
echo "+ Sending files from ${2} to ${5} (${4})" echo "+ Sending files from ${2} to ${5} (${4})"
@ -203,6 +229,15 @@ function sendFile() {
echo "+ Syncing folder ${2} to ${5} (${4})" echo "+ Syncing folder ${2} to ${5} (${4})"
rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
echo ""
echo "+ Syncing folder ${2} to ${5} (${4})"
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null
sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
elif [ "${toolSelected}" == "scp-rsa" ] ; then
echo ""
echo "+ Sending files from ${2} to ${5} (${4})"
sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null
else else
echo "" echo ""
echo "+ Sending files from ${2} to ${5} (${4})" echo "+ Sending files from ${2} to ${5} (${4})"
@ -381,11 +416,25 @@ function editConfig() {
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
echo -n "* [Default: scp] Type upload tool (scp or rsync): " ; read TOOL echo ""
echo "* Available options:"
echo ""
echo "- scp"
echo "- rsync"
echo "- scp-rsa (legacy RSA algorithm)"
echo "- rsync-rsa (legacy RSA algorithm)"
echo ""
echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL
if [ -z "${TOOL}" ] ; then if [ -z "${TOOL}" ] ; then
upvTool="scp" upvTool="scp"
elif [ "${TOOL}" == "rsync" ] ; then
upvTool="rsync"
elif [ "${TOOL}" == "rsync-rsa" ] ; then
upvTool="rsync-rsa"
elif [ "${TOOL}" == "scp-rsa" ] ; then
upvTool="scp-rsa"
else else
upvTool=${TOOL} upvTool="scp"
fi fi
echo ${upvTool} > ${dirConfig}/ks-upload-tool echo ${upvTool} > ${dirConfig}/ks-upload-tool
elif [ "${EDIT}" == "7" ] ; then elif [ "${EDIT}" == "7" ] ; then
@ -469,7 +518,7 @@ function showHelp() {
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload recursively file(s) to server with rsync+ssh" echo "- Upload recursively file(s) to server with scp or rsync"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
@ -632,6 +681,11 @@ elif [ "${1}" == "-i" ] ; then
echo "* NOTE: You are using 'scp' to upload files and no progress will be shown." 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' if you wish (Command: ks-upv -e)"
fi 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-upv -e)"
fi
if [ -d ${dirLocal} ] ; then if [ -d ${dirLocal} ] ; then
sendFile ${password} "${dirLocal}" ${user} ${server} ${dirServer} sendFile ${password} "${dirLocal}" ${user} ${server} ${dirServer}
echo "" echo ""

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
###################################################################### #########################################################################
# ks-upv (ks-tools) - Upload videos file(s) to server with rynsc+ssh # # ks-upv (ks-tools) - Upload videos file(s) to server with scp or rsync #
# Date: 22-01-2022 # # Date: 22-01-2022 #
# Author: q3aql # # Author: q3aql #
# Contact: q3aql@duck.com # # Contact: q3aql@duck.com #
###################################################################### #########################################################################
VERSION="8.2" VERSION="8.2"
M_DATE="220122" M_DATE="220122"
@ -134,14 +134,23 @@ function showPathFile() {
# check_fingerprint <user> <server> # check_fingerprint <user> <server>
function check_fingerprint() { function check_fingerprint() {
fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}")
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
if [ -z "${fingerprint_host}" ] ; then if [ -z "${fingerprint_host}" ] ; then
# Run command for upload on Windows (Cygwin) # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
/usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
/usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -153,11 +162,19 @@ function check_fingerprint() {
fi fi
# Run command for upload on Unix systems # Run command for upload on Unix systems
else else
if [ -z "${toolSelected}" ] ; then
echo "* INFO: First connection to a server requires saving the fingerprint." echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password." echo "* INFO: Only the first time you will have to enter the password."
echo "" echo ""
ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$? OUTPUT=$?
else
echo "* INFO: First connection to a server requires saving the fingerprint."
echo "* INFO: Only the first time you will have to enter the password."
echo ""
ssh -o HostKeyAlgorithms=+ssh-rsa ${1}@${2} echo "* Connection successfuly" &> /dev/null
OUTPUT=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "" echo ""
echo "+ ERROR: There has been a failure to connect to the server." echo "+ ERROR: There has been a failure to connect to the server."
@ -184,6 +201,13 @@ function sendFile() {
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
/usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
/usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -194,6 +218,13 @@ function sendFile() {
rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null rsync --progress -azL --rsh="sshpass -p ${1} ssh -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -l ${3}" ${2} ${4}:${5} 2> /dev/null
sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$?
elif [ "${toolSelected}" == "scp-rsa" ] ; then
sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$? OUTPUT=$?
@ -220,15 +251,28 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
if [ "${cygwin}" == "yes" ] ; then if [ "${cygwin}" == "yes" ] ; then
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(/usr/bin/md5sum ${2}) checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else else
checksumLocal=$(/usr/bin/md5sum ${2})
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
else
if [ -z "${toolSelected}" ] ; then
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
else
checksumLocal=$(md5sum ${2})
checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$?
fi
fi fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
@ -416,11 +460,25 @@ function editConfig() {
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
echo -n "* [Default: scp] Type upload tool (scp or rsync): " ; read TOOL echo ""
echo "* Available options:"
echo ""
echo "- scp"
echo "- rsync"
echo "- scp-rsa (legacy RSA algorithm)"
echo "- rsync-rsa (legacy RSA algorithm)"
echo ""
echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL
if [ -z "${TOOL}" ] ; then if [ -z "${TOOL}" ] ; then
upvTool="scp" upvTool="scp"
elif [ "${TOOL}" == "rsync" ] ; then
upvTool="rsync"
elif [ "${TOOL}" == "rsync-rsa" ] ; then
upvTool="rsync-rsa"
elif [ "${TOOL}" == "scp-rsa" ] ; then
upvTool="scp-rsa"
else else
upvTool=${TOOL} upvTool="scp"
fi fi
echo ${upvTool} > ${dirConfig}/ks-upload-tool echo ${upvTool} > ${dirConfig}/ks-upload-tool
elif [ "${EDIT}" == "7" ] ; then elif [ "${EDIT}" == "7" ] ; then
@ -504,7 +562,7 @@ function showHelp() {
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload videos file(s) to server with rynsc+ssh" echo "- Upload videos file(s) to server with scp or rsync"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
@ -674,6 +732,11 @@ elif [ "${1}" == "-i" ] ; then
echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)" echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)"
echo "" echo ""
fi 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 ""
fi
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})