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() {
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
# 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"
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=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
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..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5
countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then
@ -157,7 +172,6 @@ function sendFile() {
else
correct=1
fi
fi
done
}
@ -168,14 +182,16 @@ 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
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=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}"
echo "Retrying..."
@ -185,13 +201,11 @@ function checkChecksum() {
correct=1
fi
else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}"
correct=1
fi
done
fi
}
# 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

View File

@ -152,21 +152,36 @@ 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
# 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"
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=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
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..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5
countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then
@ -175,7 +190,6 @@ function sendFile() {
else
correct=1
fi
fi
done
}
@ -186,14 +200,16 @@ 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
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=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}"
echo "Retrying..."
@ -203,13 +219,11 @@ function checkChecksum() {
correct=1
fi
else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}"
correct=1
fi
done
fi
}
# 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

View File

@ -147,11 +147,35 @@ function showPathFile() {
# Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
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"
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

View File

@ -129,27 +129,41 @@ function showPathFile() {
echo ${pathFile}
}
# Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [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
# 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"
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=$?
if [ "${cygwin}" == "yes" ] ; then
echo "retry_disabled" > /dev/null
correct=1
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..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5
countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 3 ] ; then
@ -158,7 +172,6 @@ function sendFile() {
else
correct=1
fi
fi
done
}
@ -169,14 +182,16 @@ 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
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=$?
fi
if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}"
echo "Retrying..."
@ -186,13 +201,11 @@ function checkChecksum() {
correct=1
fi
else
checksumLocal=$(md5sum ${2})
echo "Local checksum: ${checksumLocal}"
echo "Server checksum: ${checksumServer}"
correct=1
fi
done
fi
}
# 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