From 2c034253b48fa37cc0cc46988a5cdd718487a4cc Mon Sep 17 00:00:00 2001 From: q3aql Date: Fri, 21 Jan 2022 22:06:47 +0100 Subject: [PATCH] Fix upload & checksum fail with Cygwin (for Windows) --- src/ks-upa | 91 +++++++++++++++++++++++++++++++---------------------- src/ks-upf | 91 +++++++++++++++++++++++++++++++---------------------- src/ks-upr | 35 ++++++++++++++++++--- src/ks-upv | 92 +++++++++++++++++++++++++++++++----------------------- 4 files changed, 189 insertions(+), 120 deletions(-) diff --git a/src/ks-upa b/src/ks-upa index 62a0cbc..7877b9a 100755 --- a/src/ks-upa +++ b/src/ks-upa @@ -134,29 +134,43 @@ function showPathFile() { function sendFile() { correct=0 countSend=0 + toolSelected=$(cat ${dirConfig}/ks-upload-tool) while [ ${correct} -eq 0 ] ; do - #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null - comandOne="sshpass -p ${1} rsync -azL -e" - comandTwo="--progress ${2} ${3}@${4}:${5}" - ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - OUTPUT=$? + # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then - echo "retry_disabled" > /dev/null - correct=1 - else - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failure to send ${2}" - echo "Retrying..." - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - sleep 5 - countSend=$(expr ${countSend} + 1) - if [ ${countSend} -eq 3 ] ; then - correct=1 - fi + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="/usr/bin/sshpass -p ${1} /usr/bin/rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? else + /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + # Run command for upload on Unix systems + else + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="sshpass -p ${1} rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? + else + sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failure to send ${2}" + echo "Retrying..." + sleep 5 + countSend=$(expr ${countSend} + 1) + if [ ${countSend} -eq 3 ] ; then correct=1 fi + else + correct=1 fi done } @@ -168,30 +182,30 @@ function checkChecksum() { countChecksum=0 echo -n "Checking checksum... " && sleep 4 echo "" - if [ "${cygwin}" == "yes" ] ; then - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: checksum_disabled" - else - while [ ${correct} -eq 0 ] ; do + while [ ${correct} -eq 0 ] ; do + if [ "${cygwin}" == "yes" ] ; then + checksumLocal=$(/usr/bin/md5sum ${2}) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) + OUTPUT=$? + else + checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failed to get checksum for ${5}" - echo "Retrying..." - sleep 5 - countChecksum=$(expr ${countChecksum} + 1) - if [ ${countChecksum} -eq 3 ] ; then - correct=1 - fi - else - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: ${checksumServer}" + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failed to get checksum for ${5}" + echo "Retrying..." + sleep 5 + countChecksum=$(expr ${countChecksum} + 1) + if [ ${countChecksum} -eq 3 ] ; then correct=1 fi - done - fi + else + echo "Local checksum: ${checksumLocal}" + echo "Server checksum: ${checksumServer}" + correct=1 + fi + done } # Generate random codes @@ -571,6 +585,7 @@ if [ "${1}" == "-r" ] ; then echo "+ Removing LOCAL PATH file configuration..." rm -rf ${dirConfig}/ks-upload-dirlocal echo "* Removed all configuration" + rm -f ${dirConfig}/ks-upload-tool echo "" exit else diff --git a/src/ks-upf b/src/ks-upf index d5e48cd..35ed411 100755 --- a/src/ks-upf +++ b/src/ks-upf @@ -152,29 +152,43 @@ function showPathFile() { function sendFile() { correct=0 countSend=0 + toolSelected=$(cat ${dirConfig}/ks-upload-tool) while [ ${correct} -eq 0 ] ; do - #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null - comandOne="sshpass -p ${1} rsync -azL -e" - comandTwo="--progress ${2} ${3}@${4}:${5}" - ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - OUTPUT=$? + # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then - echo "retry_disabled" > /dev/null - correct=1 - else - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failure to send ${2}" - echo "Retrying..." - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - sleep 5 - countSend=$(expr ${countSend} + 1) - if [ ${countSend} -eq 3 ] ; then - correct=1 - fi + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="/usr/bin/sshpass -p ${1} /usr/bin/rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? else + /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + # Run command for upload on Unix systems + else + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="sshpass -p ${1} rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? + else + sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failure to send ${2}" + echo "Retrying..." + sleep 5 + countSend=$(expr ${countSend} + 1) + if [ ${countSend} -eq 3 ] ; then correct=1 fi + else + correct=1 fi done } @@ -186,30 +200,30 @@ function checkChecksum() { countChecksum=0 echo -n "Checking checksum... " && sleep 4 echo "" - if [ "${cygwin}" == "yes" ] ; then - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: checksum_disabled" - else - while [ ${correct} -eq 0 ] ; do + while [ ${correct} -eq 0 ] ; do + if [ "${cygwin}" == "yes" ] ; then + checksumLocal=$(/usr/bin/md5sum ${2}) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) + OUTPUT=$? + else + checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failed to get checksum for ${5}" - echo "Retrying..." - sleep 5 - countChecksum=$(expr ${countChecksum} + 1) - if [ ${countChecksum} -eq 3 ] ; then - correct=1 - fi - else - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: ${checksumServer}" + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failed to get checksum for ${5}" + echo "Retrying..." + sleep 5 + countChecksum=$(expr ${countChecksum} + 1) + if [ ${countChecksum} -eq 3 ] ; then correct=1 fi - done - fi + else + echo "Local checksum: ${checksumLocal}" + echo "Server checksum: ${checksumServer}" + correct=1 + fi + done } # Generate random codes @@ -589,6 +603,7 @@ if [ "${1}" == "-r" ] ; then echo "+ Removing LOCAL PATH file configuration..." rm -rf ${dirConfig}/ks-upload-dirlocal echo "* Removed all configuration" + rm -f ${dirConfig}/ks-upload-tool echo "" exit else diff --git a/src/ks-upr b/src/ks-upr index 4d4a503..f8d0907 100755 --- a/src/ks-upr +++ b/src/ks-upr @@ -147,11 +147,35 @@ function showPathFile() { # Function to send file to server. # Syntax: sendFile [file name] function sendFile() { - #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null - comandOne="sshpass -p ${1} rsync -azlr -e" - comandTwo="--progress ${2}/ ${3}@${4}:${5}/" - ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + toolSelected=$(cat ${dirConfig}/ks-upload-tool) + if [ "${cygwin}" == "yes" ] ; then + if [ "${toolSelected}" == "rsync" ] ; then + echo "" + echo "+ Syncing folder ${2} to ${5} (${4})" + comandOne="/usr/bin/sshpass -p ${1} /usr/bin/rsync -azL -e" + comandTwo="--progress ${2}/ ${3}@${4}:${5}/" + ${comandOne} "/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + else + echo "" + echo "+ Sending files from ${2} to ${5} (${4})" + /usr/bin/sshpass -p ${1} /usr/bin/scp ${2}/* ${3}@${4}:${5}/ 2> /dev/null + fi + # Run command for upload on Unix systems + else + if [ "${toolSelected}" == "rsync" ] ; then + echo "" + echo "+ Syncing folder ${2} to ${5} (${4})" + comandOne="sshpass -p ${1} rsync -azlr -e" + comandTwo="--progress ${2}/ ${3}@${4}:${5}/" + ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + else + echo "" + echo "+ Sending files from ${2} to ${5} (${4})" + sshpass -p ${1} scp -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null + fi + fi } # Generate random codes @@ -531,6 +555,7 @@ if [ "${1}" == "-r" ] ; then echo "+ Removing LOCAL PATH file configuration..." rm -rf ${dirConfig}/ks-upload-dirlocal echo "* Removed all configuration" + rm -f ${dirConfig}/ks-upload-tool echo "" exit else diff --git a/src/ks-upv b/src/ks-upv index f8727dd..af5c43f 100755 --- a/src/ks-upv +++ b/src/ks-upv @@ -129,35 +129,48 @@ function showPathFile() { echo ${pathFile} } - # Function to send file to server. # Syntax: sendFile [file name] function sendFile() { correct=0 countSend=0 + toolSelected=$(cat ${dirConfig}/ks-upload-tool) while [ ${correct} -eq 0 ] ; do - #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null - comandOne="sshpass -p ${1} rsync -azL -e" - comandTwo="--progress ${2} ${3}@${4}:${5}" - ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - OUTPUT=$? + # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then - echo "retry_disabled" > /dev/null - correct=1 - else - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failure to send ${2}" - echo "Retrying..." - sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null - sleep 5 - countSend=$(expr ${countSend} + 1) - if [ ${countSend} -eq 3 ] ; then - correct=1 - fi + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="/usr/bin/sshpass -p ${1} /usr/bin/rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? else + /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + # Run command for upload on Unix systems + else + if [ "${toolSelected}" == "rsync" ] ; then + comandOne="sshpass -p ${1} rsync -azL -e" + comandTwo="--progress ${2} ${3}@${4}:${5}" + ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null + sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + OUTPUT=$? + else + sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + OUTPUT=$? + fi + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failure to send ${2}" + echo "Retrying..." + sleep 5 + countSend=$(expr ${countSend} + 1) + if [ ${countSend} -eq 3 ] ; then correct=1 fi + else + correct=1 fi done } @@ -169,30 +182,30 @@ function checkChecksum() { countChecksum=0 echo -n "Checking checksum... " && sleep 4 echo "" - if [ "${cygwin}" == "yes" ] ; then - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: checksum_disabled" - else - while [ ${correct} -eq 0 ] ; do + while [ ${correct} -eq 0 ] ; do + if [ "${cygwin}" == "yes" ] ; then + checksumLocal=$(/usr/bin/md5sum ${2}) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh ${3}@${4} md5sum ${5} 2> /dev/null) + OUTPUT=$? + else + checksumLocal=$(md5sum ${2}) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "Failed to get checksum for ${5}" - echo "Retrying..." - sleep 5 - countChecksum=$(expr ${countChecksum} + 1) - if [ ${countChecksum} -eq 3 ] ; then - correct=1 - fi - else - checksumLocal=$(md5sum ${2}) - echo "Local checksum: ${checksumLocal}" - echo "Server checksum: ${checksumServer}" + fi + if [ ${OUTPUT} -ne 0 ] ; then + echo "Failed to get checksum for ${5}" + echo "Retrying..." + sleep 5 + countChecksum=$(expr ${countChecksum} + 1) + if [ ${countChecksum} -eq 3 ] ; then correct=1 fi - done - fi + else + echo "Local checksum: ${checksumLocal}" + echo "Server checksum: ${checksumServer}" + correct=1 + fi + done } # Generate random codes @@ -572,6 +585,7 @@ if [ "${1}" == "-r" ] ; then echo "+ Removing LOCAL PATH file configuration..." rm -rf ${dirConfig}/ks-upload-dirlocal echo "* Removed all configuration" + rm -f ${dirConfig}/ks-upload-tool echo "" exit else