Fix upload & checksum fail with Cygwin (for Windows)

This commit is contained in:
q3aql 2022-01-21 22:06:47 +01:00
parent 9fc9c42f1a
commit 2c034253b4
4 changed files with 189 additions and 120 deletions

View File

@ -134,21 +134,36 @@ function showPathFile() {
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
toolSelected=$(cat ${dirConfig}/ks-upload-tool)
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then
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" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${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 sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
fi
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then if [ ${countSend} -eq 3 ] ; then
@ -157,7 +172,6 @@ function sendFile() {
else else
correct=1 correct=1
fi fi
fi
done done
} }
@ -168,14 +182,16 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" 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) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
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}"
echo "Retrying..." echo "Retrying..."
@ -185,13 +201,11 @@ function checkChecksum() {
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}" echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}" echo "Server checksum: ${checksumServer}"
correct=1 correct=1
fi fi
done done
fi
} }
# Generate random codes # Generate random codes
@ -571,6 +585,7 @@ if [ "${1}" == "-r" ] ; then
echo "+ Removing LOCAL PATH file configuration..." echo "+ Removing LOCAL PATH file configuration..."
rm -rf ${dirConfig}/ks-upload-dirlocal rm -rf ${dirConfig}/ks-upload-dirlocal
echo "* Removed all configuration" echo "* Removed all configuration"
rm -f ${dirConfig}/ks-upload-tool
echo "" echo ""
exit exit
else else

View File

@ -152,21 +152,36 @@ function showPathFile() {
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
toolSelected=$(cat ${dirConfig}/ks-upload-tool)
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then
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" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${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 sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
fi
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then if [ ${countSend} -eq 3 ] ; then
@ -175,7 +190,6 @@ function sendFile() {
else else
correct=1 correct=1
fi fi
fi
done done
} }
@ -186,14 +200,16 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" 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) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
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}"
echo "Retrying..." echo "Retrying..."
@ -203,13 +219,11 @@ function checkChecksum() {
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}" echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}" echo "Server checksum: ${checksumServer}"
correct=1 correct=1
fi fi
done done
fi
} }
# Generate random codes # Generate random codes
@ -589,6 +603,7 @@ if [ "${1}" == "-r" ] ; then
echo "+ Removing LOCAL PATH file configuration..." echo "+ Removing LOCAL PATH file configuration..."
rm -rf ${dirConfig}/ks-upload-dirlocal rm -rf ${dirConfig}/ks-upload-dirlocal
echo "* Removed all configuration" echo "* Removed all configuration"
rm -f ${dirConfig}/ks-upload-tool
echo "" echo ""
exit exit
else else

View File

@ -147,11 +147,35 @@ function showPathFile() {
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /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" comandOne="sshpass -p ${1} rsync -azlr -e"
comandTwo="--progress ${2}/ ${3}@${4}:${5}/" comandTwo="--progress ${2}/ ${3}@${4}:${5}/"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${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 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 # Generate random codes
@ -531,6 +555,7 @@ if [ "${1}" == "-r" ] ; then
echo "+ Removing LOCAL PATH file configuration..." echo "+ Removing LOCAL PATH file configuration..."
rm -rf ${dirConfig}/ks-upload-dirlocal rm -rf ${dirConfig}/ks-upload-dirlocal
echo "* Removed all configuration" echo "* Removed all configuration"
rm -f ${dirConfig}/ks-upload-tool
echo "" echo ""
exit exit
else else

View File

@ -129,27 +129,41 @@ function showPathFile() {
echo ${pathFile} echo ${pathFile}
} }
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
toolSelected=$(cat ${dirConfig}/ks-upload-tool)
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null # Run command for upload on Windows (Cygwin)
if [ "${cygwin}" == "yes" ] ; then
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" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${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 sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
else else
sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null
OUTPUT=$?
fi
fi
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then if [ ${countSend} -eq 3 ] ; then
@ -158,7 +172,6 @@ function sendFile() {
else else
correct=1 correct=1
fi fi
fi
done done
} }
@ -169,14 +182,16 @@ function checkChecksum() {
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" 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) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
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}"
echo "Retrying..." echo "Retrying..."
@ -186,13 +201,11 @@ function checkChecksum() {
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}" echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}" echo "Server checksum: ${checksumServer}"
correct=1 correct=1
fi fi
done done
fi
} }
# Generate random codes # Generate random codes
@ -572,6 +585,7 @@ if [ "${1}" == "-r" ] ; then
echo "+ Removing LOCAL PATH file configuration..." echo "+ Removing LOCAL PATH file configuration..."
rm -rf ${dirConfig}/ks-upload-dirlocal rm -rf ${dirConfig}/ks-upload-dirlocal
echo "* Removed all configuration" echo "* Removed all configuration"
rm -f ${dirConfig}/ks-upload-tool
echo "" echo ""
exit exit
else else