From 8de980a6fc862253788788752f199eb20186267f Mon Sep 17 00:00:00 2001 From: q3aql Date: Tue, 25 Jan 2022 20:11:59 +0100 Subject: [PATCH] Add option for set port connection --- src/.ks-mp4.swp | Bin 0 -> 16384 bytes src/ks-upa | 79 +++++++++++++++++++++++++++++++++--------------- src/ks-upf | 77 ++++++++++++++++++++++++++++++++-------------- src/ks-upr | 68 +++++++++++++++++++++++++++++------------ src/ks-upv | 75 +++++++++++++++++++++++++++++++-------------- 5 files changed, 211 insertions(+), 88 deletions(-) create mode 100644 src/.ks-mp4.swp diff --git a/src/.ks-mp4.swp b/src/.ks-mp4.swp new file mode 100644 index 0000000000000000000000000000000000000000..270bcea1130f9db5a43c6330f722838b9ec7e2d6 GIT binary patch literal 16384 zcmeI3O^oEk6~`+;Hf+8KpeW%I)p%NAI&6P=men%Q%aUbwA!xFz>;MOZ9FJX|w#IE6 zS9Q+}O(zlIfVdz?S`FO};5mDZn4%Uh}8%>E~7{dH;m{iXVg)AFyR=kuld zv{;>#2b2et2b2et2b2et2b2et2b2et2b2et2b2f)@PKI(QbYMaWIm1k|1AIi%VmUo z49)=#7Uey@2{;EhVBmJJ3XX#g_%`_4*9dtPJPFQ$hrkdpunOkD2VW)RP4Fl1Ja`N| z41Nyo2L@OKSAoAG;r}!E2)qK$gGYb`t^lupnUF`p3b+!yc#x27a1zXc4==?x4dD0S zH{h2b1UG^u@J;Z}mk4^I4*>=agBBp*`~gCq0uO>^a2$LGeEda1-UqLNm%!uT z7r+8X!9noGC4@Wyeg?YW6THlL89WDm3!VYL2Ag0VoB-E>OTa(zV&)Ivci>s@GWo_&aR$C6+`y+SsYnz~M<-p6E!63V%+s^mzA(3z_L87CI0MgXNz*L{8cne!jzQ%l ztV*LIpu87sQqg17H~WkR4w~h$mJ_#&I#JN4(nQ=kLL3(jWm~S0C#x4wP0O#Yp{uZR zwd3?dwth8C2Of1f^#eg&p9|CTm_0WUpIm*9Cf}dXh3uo0Ivv(VcP#(t?5(GNIHn7= z(TZ{NO{>e}`b0@1u0!vlwGoS=ATpAtj%mYZv`z1(*UK*Xq*&Rl-AEEKLohD7wT0x4 zHX1$Vg;YQG-A*08IniU*28H#s8hyyypL&1?gUDidxE1)0yDrCKocm#DV5qvaQG6b2 z^w_Z}f;Mx^fhP>l^w$kOSd&V-%4RlT4s16lTZjv*OspBE71+#zVs=?2o(m@zRiZ;9 zj2LH$Cz8u5@ik*OX-INeC7uiKFB&n=;O@N)UCb`4ELRNJ{9J3z^;>Hu??I|Gs?6gI zF)$@G;)#>ZnHeG^4(`UiGQPK5E{r6YCV?&gdf;i9#a&@j4g?uqd-uBhq+O=Qvpw}f z`iFnak7NeC7%7u!WS?pFkI}y>~7i%DB!_u=Wn`(we8xHLhI+lfB zWm9sYVpFo{s?^Mdikex_Rdga1sqRHSI$7LQHYFEAh$MmMlp-l#Q}j1%H=>PjQXj9C z#&YQpF;g%s7hKCVJuLO)>L6ZF?OZr$tpShX-x6zkebe=IhUDT(qb_ab8uAz>}#UYv$(1rAY^+S|;cr)ZlMH?K0d=tuGPj&wSsu5V z*{YV34ZbSBxn5=cFkSd-EzuA2kFho4;m2N9cePBbDT^=?Zj_Wu1=;FTUa*E3n=~8A zSiDN^YP#O;=(Hi6t6;P=4GVSQ||X3BoMLJoIlGh+Yt- z>a!>nWTgJhm|RO#*Bk9lLvQPPp?cp-slPkTXvjVxk^~*PHVb4vv~uP!#YE}jr=)m5 z|I;1#_II*;Br^Xe$fIuoGXIw+c|3qzegq=04E~5*`~~o12;2$IfZKr7I|bCCJfJ+F zJfJ+FJfJ+FJfJ+FJn(t)K>QXoeHEIX@>ipB`Cc1^`QAXhrJ|w8F_5TX)z7g7f-Qr- zDRcQa0Wjp|%SK)nXS`XNG*#5Ajbz%%0wYerxKv`ol>f<=3RiecZsEv16(hcjw=uSv ziLDB`TTsWlmRuYrD6Wn#67@p;5?>lFwJ-3IP%?{3N%}sfXX73rQNvz> z+;_>+eA!-fM;|xyeGQUiN9k+tWH2gA /dev/null | grep -o "${2}") toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) if [ -z "${fingerprint_host}" ] ; then # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then @@ -142,13 +143,13 @@ function check_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 "" - /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + /usr/bin/ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -166,13 +167,13 @@ function check_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 "" - ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -194,39 +195,40 @@ function sendFile() { correct=0 countSend=0 toolSelected=$(cat ${dirConfig}/ks-upload-tool) + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then if [ "${toolSelected}" == "rsync" ] ; then - /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/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + /usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi # Run command for upload on Unix systems else if [ "${toolSelected}" == "rsync" ] ; then - 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + sshpass -p ${1} scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi fi @@ -252,25 +254,26 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then if [ -z "${toolSelected}" ] ; then 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 -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? 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) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi else if [ -z "${toolSelected}" ] ; then checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? else checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi fi @@ -398,6 +401,11 @@ function showConfig() { echo "- Upload Tool: ${showUpvTool}" configAvailable=1 fi + if [ -f ${dirConfig}/ks-upload-port ] ; then + showUpvPort=$(cat ${dirConfig}/ks-upload-port) + echo "- Port Connection: ${showUpvPort}" + configAvailable=1 + fi if [ ${configAvailable} -eq 0 ] ; then echo "* The configuration file does not exist!" fi @@ -424,8 +432,11 @@ function editConfig() { editDirServer=$(cat ${dirConfig}/ks-upload-dirserver 2> /dev/null) editDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal 2> /dev/null) editUpvTool=$(cat ${dirConfig}/ks-upload-tool 2> /dev/null) + editUpvPort=$(cat ${dirConfig}/ks-upload-port 2> /dev/null) echo "" - echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" + echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" + echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" echo "" echo " 1 - Edit User (${editUser})" echo " 2 - Edit Password (${editPassword})" @@ -433,8 +444,9 @@ function editConfig() { echo " 4 - Edit Dest. Path (${editDirServer})" echo " 5 - Edit Local Path (${editDirLocal})" echo " 6 - Edit Upload Tool (${editUpvTool})" + echo " 7 - Edit Port Connection (${editUpvPort})" echo "" - echo " 7 - Exit" + echo " 8 - Exit" echo "" echo -n "* Choose an option: " ; read EDIT echo "" @@ -459,7 +471,7 @@ function editConfig() { echo -n "* Enter the local path to scan: " ; read DIR dirLocal=${DIR} echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal - elif [ "${EDIT}" == "6" ] ; then + elif [ "${EDIT}" == "6" ] ; then echo "" echo "* Available options:" echo "" @@ -482,6 +494,14 @@ function editConfig() { fi echo ${upvTool} > ${dirConfig}/ks-upload-tool elif [ "${EDIT}" == "7" ] ; then + echo -n "* [Default: 22] Type port connection: " ; read PORT + if [ -z "${PORT}" ] ; then + upvPort="22" + else + upvPort="${PORT}" + fi + echo ${upvPort} > ${dirConfig}/ks-upload-port + elif [ "${EDIT}" == "8" ] ; then editConfig=1 else echo "+ Invalid option!" @@ -544,7 +564,15 @@ function createConfig() { if [ -f ${dirConfig}/ks-upload-tool ] ; then echo "+ The UPLOAD TOOL configuration already exists (Use: 'ks-upa -e' for edit)" else + echo "* Setting 'scp' as the default tool" echo "scp" > ${dirConfig}/ks-upload-tool + fi + # Configure port by default + if [ -f ${dirConfig}/ks-upload-port ] ; then + echo "+ The PORT configuration already exists (Use: 'ks-upa -e' for edit)" + else + echo "* Setting port 22 as the default port" + echo "22" > ${dirConfig}/ks-upload-port fi echo "" } @@ -564,6 +592,8 @@ function showHelp() { echo "" echo "- Upload audio file(s) to server with scp or rsync" echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" + echo "" echo "+ Syntax:" echo "" echo " $ ks-upa -i - Start upload" @@ -681,7 +711,8 @@ 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 + rm -rf ${dirConfig}/ks-upload-tool + rm -rf ${dirConfig}/ks-upload-port echo "" exit else diff --git a/src/ks-upf b/src/ks-upf index 661cfac..ee0feac 100755 --- a/src/ks-upf +++ b/src/ks-upf @@ -162,6 +162,7 @@ function showPathFile() { function check_fingerprint() { fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) if [ -z "${fingerprint_host}" ] ; then # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then @@ -169,13 +170,13 @@ function check_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 "" - /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + /usr/bin/ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -193,13 +194,13 @@ function check_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 "" - ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -221,39 +222,40 @@ function sendFile() { correct=0 countSend=0 toolSelected=$(cat ${dirConfig}/ks-upload-tool) + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then if [ "${toolSelected}" == "rsync" ] ; then - /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/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + /usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi # Run command for upload on Unix systems else if [ "${toolSelected}" == "rsync" ] ; then - 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + sshpass -p ${1} scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi fi @@ -279,25 +281,26 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then if [ -z "${toolSelected}" ] ; then 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 -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? 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) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi else if [ -z "${toolSelected}" ] ; then checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? else checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi fi @@ -428,6 +431,11 @@ function showConfig() { if [ ${configAvailable} -eq 0 ] ; then echo "* The configuration file does not exist!" fi + if [ -f ${dirConfig}/ks-upload-port ] ; then + showUpvPort=$(cat ${dirConfig}/ks-upload-port) + echo "- Port Connection: ${showUpvPort}" + configAvailable=1 + fi echo "" exit } @@ -451,8 +459,11 @@ function editConfig() { editDirServer=$(cat ${dirConfig}/ks-upload-dirserver 2> /dev/null) editDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal 2> /dev/null) editUpvTool=$(cat ${dirConfig}/ks-upload-tool 2> /dev/null) + editUpvPort=$(cat ${dirConfig}/ks-upload-port 2> /dev/null) echo "" - echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" + echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" + echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" echo "" echo " 1 - Edit User (${editUser})" echo " 2 - Edit Password (${editPassword})" @@ -460,8 +471,9 @@ function editConfig() { echo " 4 - Edit Dest. Path (${editDirServer})" echo " 5 - Edit Local Path (${editDirLocal})" echo " 6 - Edit Upload Tool (${editUpvTool})" + echo " 7 - Edit Port Connection (${editUpvPort})" echo "" - echo " 7 - Exit" + echo " 8 - Exit" echo "" echo -n "* Choose an option: " ; read EDIT echo "" @@ -509,6 +521,14 @@ function editConfig() { fi echo ${upvTool} > ${dirConfig}/ks-upload-tool elif [ "${EDIT}" == "7" ] ; then + echo -n "* [Default: 22] Type port connection: " ; read PORT + if [ -z "${PORT}" ] ; then + upvPort="22" + else + upvPort="${PORT}" + fi + echo ${upvPort} > ${dirConfig}/ks-upload-port + elif [ "${EDIT}" == "8" ] ; then editConfig=1 else echo "+ Invalid option!" @@ -571,7 +591,15 @@ function createConfig() { if [ -f ${dirConfig}/ks-upload-tool ] ; then echo "+ The UPLOAD TOOL configuration already exists (Use: 'ks-upf -e' for edit)" else + echo "* Setting 'scp' as the default tool" echo "scp" > ${dirConfig}/ks-upload-tool + fi + # Configure port by default + if [ -f ${dirConfig}/ks-upload-port ] ; then + echo "+ The PORT configuration already exists (Use: 'ks-upf -e' for edit)" + else + echo "* Setting port 22 as the default port" + echo "22" > ${dirConfig}/ks-upload-port fi echo "" } @@ -591,6 +619,8 @@ function showHelp() { echo "" echo "- Upload common file(s) to server with scp or rsync" echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" + echo "" echo "+ Syntax:" echo "" echo " $ ks-upf -i - Start upload" @@ -708,7 +738,8 @@ 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 + rm -rf ${dirConfig}/ks-upload-tool + rm -rf ${dirConfig}/ks-upload-port echo "" exit else diff --git a/src/ks-upr b/src/ks-upr index 2bde525..81c9874 100755 --- a/src/ks-upr +++ b/src/ks-upr @@ -145,6 +145,7 @@ function showFile() { function check_fingerprint() { fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) if [ -z "${fingerprint_host}" ] ; then # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then @@ -152,13 +153,13 @@ function check_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 "" - /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + /usr/bin/ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -176,13 +177,13 @@ function check_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 "" - ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -202,46 +203,47 @@ function check_fingerprint() { # Syntax: sendFile [file name] function sendFile() { toolSelected=$(cat ${dirConfig}/ks-upload-tool) + portSelected=$(cat ${dirConfig}/ks-upload-port) if [ "${cygwin}" == "yes" ] ; then if [ "${toolSelected}" == "rsync" ] ; then echo "" 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/sshpass -p ${1} /usr/bin/ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null + /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} ${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 + /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + /usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null else echo "" echo "+ Sending files from ${2} to ${5} (${4})" - /usr/bin/sshpass -p ${1} /usr/bin/scp -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/scp -P ${portSelected} -r ${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})" - 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -p ${portSelected} -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null + sshpass -p ${1} ssh -p ${portSelected} ${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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2}/ ${4}:${5}/ 2> /dev/null + sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null else echo "" echo "+ Sending files from ${2} to ${5} (${4})" - sshpass -p ${1} scp -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null + sshpass -p ${1} scp -P ${portSelected} -r ${2}/* ${3}@${4}:${5}/ 2> /dev/null fi fi } @@ -354,6 +356,11 @@ function showConfig() { echo "- Upload Tool: ${showUpvTool}" configAvailable=1 fi + if [ -f ${dirConfig}/ks-upload-port ] ; then + showUpvPort=$(cat ${dirConfig}/ks-upload-port) + echo "- Port Connection: ${showUpvPort}" + configAvailable=1 + fi if [ ${configAvailable} -eq 0 ] ; then echo "* The configuration file does not exist!" fi @@ -380,8 +387,11 @@ function editConfig() { editDirServer=$(cat ${dirConfig}/ks-upload-dirserver 2> /dev/null) editDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal 2> /dev/null) editUpvTool=$(cat ${dirConfig}/ks-upload-tool 2> /dev/null) + editUpvPort=$(cat ${dirConfig}/ks-upload-port 2> /dev/null) echo "" - echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" + echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" + echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" echo "" echo " 1 - Edit User (${editUser})" echo " 2 - Edit Password (${editPassword})" @@ -389,8 +399,9 @@ function editConfig() { echo " 4 - Edit Dest. Path (${editDirServer})" echo " 5 - Edit Local Path (${editDirLocal})" echo " 6 - Edit Upload Tool (${editUpvTool})" + echo " 7 - Edit Port Connection (${editUpvPort})" echo "" - echo " 7 - Exit" + echo " 8 - Exit" echo "" echo -n "* Choose an option: " ; read EDIT echo "" @@ -438,6 +449,14 @@ function editConfig() { fi echo ${upvTool} > ${dirConfig}/ks-upload-tool elif [ "${EDIT}" == "7" ] ; then + echo -n "* [Default: 22] Type port connection: " ; read PORT + if [ -z "${PORT}" ] ; then + upvPort="22" + else + upvPort="${PORT}" + fi + echo ${upvPort} > ${dirConfig}/ks-upload-port + elif [ "${EDIT}" == "8" ] ; then editConfig=1 else echo "+ Invalid option!" @@ -500,7 +519,15 @@ function createConfig() { if [ -f ${dirConfig}/ks-upload-tool ] ; then echo "+ The UPLOAD TOOL configuration already exists (Use: 'ks-upr -e' for edit)" else + echo "* Setting 'scp' as the default tool" echo "scp" > ${dirConfig}/ks-upload-tool + fi + # Configure port by default + if [ -f ${dirConfig}/ks-upload-port ] ; then + echo "+ The PORT configuration already exists (Use: 'ks-upr -e' for edit)" + else + echo "* Setting port 22 as the default port" + echo "22" > ${dirConfig}/ks-upload-port fi echo "" } @@ -520,6 +547,8 @@ function showHelp() { echo "" echo "- Upload recursively file(s) to server with scp or rsync" echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" + echo "" echo "+ Syntax:" echo "" echo " $ ks-upr -i - Start upload" @@ -637,7 +666,8 @@ 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 + rm -rf ${dirConfig}/ks-upload-tool + rm -rf ${dirConfig}/ks-upload-port echo "" exit else diff --git a/src/ks-upv b/src/ks-upv index 601b8ef..1c35b2b 100755 --- a/src/ks-upv +++ b/src/ks-upv @@ -135,6 +135,7 @@ function showPathFile() { function check_fingerprint() { fingerprint_host=$(cat ${HOME}/.ssh/known_hosts 2> /dev/null | grep -o "${2}") toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) if [ -z "${fingerprint_host}" ] ; then # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then @@ -142,13 +143,13 @@ function check_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 "" - /usr/bin/ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + /usr/bin/ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -166,13 +167,13 @@ function check_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 "" - ssh ${1}@${2} echo "* Connection successfuly" &> /dev/null + ssh -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null 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 + ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${1}@${2} echo "* Connection successfuly" &> /dev/null OUTPUT=$? fi if [ ${OUTPUT} -ne 0 ] ; then @@ -194,39 +195,40 @@ function sendFile() { correct=0 countSend=0 toolSelected=$(cat ${dirConfig}/ks-upload-tool) + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do # Run command for upload on Windows (Cygwin) if [ "${cygwin}" == "yes" ] ; then if [ "${toolSelected}" == "rsync" ] ; then - /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/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + /usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + /usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - /usr/bin/sshpass -p ${1} /usr/bin/scp ${2} ${3}@${4}:${5} 2> /dev/null + /usr/bin/sshpass -p ${1} /usr/bin/scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi # Run command for upload on Unix systems else if [ "${toolSelected}" == "rsync" ] ; then - 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null 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 + rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null + sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${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 + sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? else - sshpass -p ${1} scp ${2} ${3}@${4}:${5} 2> /dev/null + sshpass -p ${1} scp -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null OUTPUT=$? fi fi @@ -252,25 +254,26 @@ function checkChecksum() { echo -n "Checking checksum... " && sleep 4 echo "" toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa") + portSelected=$(cat ${dirConfig}/ks-upload-port) while [ ${correct} -eq 0 ] ; do if [ "${cygwin}" == "yes" ] ; then if [ -z "${toolSelected}" ] ; then 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 -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? 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) + checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi else if [ -z "${toolSelected}" ] ; then checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? else checksumLocal=$(md5sum ${2}) - checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa ${3}@${4} md5sum ${5} 2> /dev/null) + checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null) OUTPUT=$? fi fi @@ -398,6 +401,11 @@ function showConfig() { echo "- Upload Tool: ${showUpvTool}" configAvailable=1 fi + if [ -f ${dirConfig}/ks-upload-port ] ; then + showUpvPort=$(cat ${dirConfig}/ks-upload-port) + echo "- Port Connection: ${showUpvPort}" + configAvailable=1 + fi if [ ${configAvailable} -eq 0 ] ; then echo "* The configuration file does not exist!" fi @@ -424,17 +432,21 @@ function editConfig() { editDirServer=$(cat ${dirConfig}/ks-upload-dirserver 2> /dev/null) editDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal 2> /dev/null) editUpvTool=$(cat ${dirConfig}/ks-upload-tool 2> /dev/null) + editUpvPort=$(cat ${dirConfig}/ks-upload-port 2> /dev/null) echo "" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" + echo "" echo " 1 - Edit User (${editUser})" echo " 2 - Edit Password (${editPassword})" echo " 3 - Edit Server (${editServer})" echo " 4 - Edit Dest. Path (${editDirServer})" echo " 5 - Edit Local Path (${editDirLocal})" echo " 6 - Edit Upload Tool (${editUpvTool})" + echo " 7 - Edit Port Connection (${editUpvPort})" echo "" - echo " 7 - Exit" + echo " 8 - Exit" echo "" echo -n "* Choose an option: " ; read EDIT echo "" @@ -482,6 +494,14 @@ function editConfig() { fi echo ${upvTool} > ${dirConfig}/ks-upload-tool elif [ "${EDIT}" == "7" ] ; then + echo -n "* [Default: 22] Type port connection: " ; read PORT + if [ -z "${PORT}" ] ; then + upvPort="22" + else + upvPort="${PORT}" + fi + echo ${upvPort} > ${dirConfig}/ks-upload-port + elif [ "${EDIT}" == "8" ] ; then editConfig=1 else echo "+ Invalid option!" @@ -544,7 +564,15 @@ function createConfig() { if [ -f ${dirConfig}/ks-upload-tool ] ; then echo "+ The UPLOAD TOOL configuration already exists (Use: 'ks-upv -e' for edit)" else + echo "* Setting 'scp' as the default tool" echo "scp" > ${dirConfig}/ks-upload-tool + fi + # Configure port by default + if [ -f ${dirConfig}/ks-upload-port ] ; then + echo "+ The PORT configuration already exists (Use: 'ks-upv -e' for edit)" + else + echo "* Setting port 22 as the default port" + echo "22" > ${dirConfig}/ks-upload-port fi echo "" } @@ -564,6 +592,8 @@ function showHelp() { echo "" echo "- Upload videos file(s) to server with scp or rsync" echo "" + echo "+ Config: ${dirConfig}/ks-upload-*" + echo "" echo "+ Syntax:" echo "" echo " $ ks-upv -i - Start upload" @@ -681,7 +711,8 @@ 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 + rm -rf ${dirConfig}/ks-upload-tool + rm -rf ${dirConfig}/ks-upload-port echo "" exit else