From 53fedec45c908658f8b0c4366870ab86e5d5f3ca Mon Sep 17 00:00:00 2001 From: q3aql Date: Sun, 12 Feb 2023 13:07:50 +0100 Subject: [PATCH] Rewrite function for check dependencies (ks-upv/upa/upf/upr) --- src/ks-upa | 72 +++++++++++++++++++++--------------------------------- src/ks-upf | 72 +++++++++++++++++++++--------------------------------- src/ks-upr | 72 +++++++++++++++++++++--------------------------------- src/ks-upv | 72 +++++++++++++++++++++--------------------------------- 4 files changed, 112 insertions(+), 176 deletions(-) diff --git a/src/ks-upa b/src/ks-upa index 364cf77..f78ca25 100755 --- a/src/ks-upa +++ b/src/ks-upa @@ -2,12 +2,12 @@ ######################################################################## # ks-upa (ks-tools) - Upload audio file(s) to server with scp or rsync # -# Date: 10-02-2023 # +# Date: 12-02-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################## VERSION="8.4-dev" -M_DATE="100223" +M_DATE="120223" # Global parameters. dirTemp="/tmp" @@ -658,49 +658,33 @@ function showHelp() { # Function to check if all the necessary tools # for the execution are installed. function checkDependencies() { - dependence=0 - echo -n "* Checking necessary tools... " - sleep 3 && echo "" - sshpass -h &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'sshpass' tool is not installed!" - dependence=1 - fi - expect -v &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'expect' tool is not installed!" - dependence=1 - fi - md5sum --help &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'md5sum' tool is not installed!" - dependence=1 - fi - rsync --version &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'rsync' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/scp ] ; then - echo "OK" > /dev/null - else - echo "* The 'scp' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/ssh ] ; then - echo "OK" > /dev/null - else - echo "* The 'ssh' tool is not installed!" - dependence=1 - fi - if [ ${dependence} -eq 0 ] ; then - echo "* Necessary tools installed!" + path_check="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin" + dependencies="sshpass expect rsync md5sum scp ssh" + dependencies_found="" + dependencies_not_found="" + for checkPath in ${path_check} ; do + for checkDependencies in ${dependencies} ; do + if [ -f ${checkPath}/${checkDependencies} ] ; then + dependencies_found="${dependencies_found} ${checkDependencies}" + fi + done + done + for notFound in ${dependencies} ; do + check_found_one=$(echo ${dependencies_found} | grep " ${notFound}") + check_found_two=$(echo ${dependencies_found} | grep "${notFound} ") + if_not_found="${check_found_one}${check_found_two}" + if [ -z "${if_not_found}" ] ; then + dependencies_not_found="${dependencies_not_found} ${notFound}" + fi + done + echo "* Checking necessary tools... " + # Show if all tools are installed + if [ -z "${dependencies_not_found}" ] ; then + echo "* The necessary tools are installed" echo "" else + echo "* Some required tools are not installed:${dependencies_not_found}" + echo "* The process has been stopped" echo "" exit fi @@ -801,7 +785,7 @@ elif [ "${1}" == "-i" ] ; then dirServer=$(cat ${dirConfig}/ks-upload-dirserver) dirLocal=$(cat ${dirConfig}/ks-upload-dirlocal) # Call the functions to perform the whole process. - echo -n "* Scanning ${dirLocal} " && sleep 4 + echo -n "* Scanning ${dirLocal} " echo "" if [ -d ${dirLocal} ] ; then listArchives "${dirLocal}" diff --git a/src/ks-upf b/src/ks-upf index 074261f..fc83805 100755 --- a/src/ks-upf +++ b/src/ks-upf @@ -2,12 +2,12 @@ ######################################################################### # ks-upf (ks-tools) - Upload common file(s) to server with scp or rsync # -# Date: 10-02-2023 # +# Date: 12-02-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="100223" +M_DATE="120223" # Global parameters. dirTemp="/tmp" @@ -685,49 +685,33 @@ function showHelp() { # Function to check if all the necessary tools # for the execution are installed. function checkDependencies() { - dependence=0 - echo -n "* Checking necessary tools... " - sleep 3 && echo "" - sshpass -h &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'sshpass' tool is not installed!" - dependence=1 - fi - expect -v &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'expect' tool is not installed!" - dependence=1 - fi - md5sum --help &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'md5sum' tool is not installed!" - dependence=1 - fi - rsync --version &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'rsync' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/scp ] ; then - echo "OK" > /dev/null - else - echo "* The 'scp' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/ssh ] ; then - echo "OK" > /dev/null - else - echo "* The 'ssh' tool is not installed!" - dependence=1 - fi - if [ ${dependence} -eq 0 ] ; then - echo "* Necessary tools installed!" + path_check="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin" + dependencies="sshpass expect rsync md5sum scp ssh" + dependencies_found="" + dependencies_not_found="" + for checkPath in ${path_check} ; do + for checkDependencies in ${dependencies} ; do + if [ -f ${checkPath}/${checkDependencies} ] ; then + dependencies_found="${dependencies_found} ${checkDependencies}" + fi + done + done + for notFound in ${dependencies} ; do + check_found_one=$(echo ${dependencies_found} | grep " ${notFound}") + check_found_two=$(echo ${dependencies_found} | grep "${notFound} ") + if_not_found="${check_found_one}${check_found_two}" + if [ -z "${if_not_found}" ] ; then + dependencies_not_found="${dependencies_not_found} ${notFound}" + fi + done + echo "* Checking necessary tools... " + # Show if all tools are installed + if [ -z "${dependencies_not_found}" ] ; then + echo "* The necessary tools are installed" echo "" else + echo "* Some required tools are not installed:${dependencies_not_found}" + echo "* The process has been stopped" echo "" exit fi @@ -828,7 +812,7 @@ elif [ "${1}" == "-i" ] ; then dirServer=$(cat ${dirConfig}/ks-upload-dirserver) dirLocal=$(cat ${dirConfig}/ks-upload-dirlocal) # Call the functions to perform the whole process. - echo -n "* Scanning ${dirLocal} " && sleep 4 + echo -n "* Scanning ${dirLocal} " echo "" if [ -d ${dirLocal} ] ; then listArchives "${dirLocal}" diff --git a/src/ks-upr b/src/ks-upr index 886a936..da8669f 100755 --- a/src/ks-upr +++ b/src/ks-upr @@ -2,12 +2,12 @@ ############################################################################## # ks-upr (ks-tools) - Upload recursively file(s) to server with scp or rsync # -# Date: 10-02-2023 # +# Date: 12-02-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################################## VERSION="8.4-dev" -M_DATE="100223" +M_DATE="120223" # Global parameters. dirTemp="/tmp" @@ -562,49 +562,33 @@ function showHelp() { # Function to check if all the necessary tools # for the execution are installed. function checkDependencies() { - dependence=0 - echo -n "* Checking necessary tools... " - sleep 3 && echo "" - sshpass -h &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'sshpass' tool is not installed!" - dependence=1 - fi - expect -v &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'expect' tool is not installed!" - dependence=1 - fi - md5sum --help &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'md5sum' tool is not installed!" - dependence=1 - fi - rsync --version &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'rsync' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/scp ] ; then - echo "OK" > /dev/null - else - echo "* The 'scp' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/ssh ] ; then - echo "OK" > /dev/null - else - echo "* The 'ssh' tool is not installed!" - dependence=1 - fi - if [ ${dependence} -eq 0 ] ; then - echo "* Necessary tools installed!" + path_check="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin" + dependencies="sshpass expect rsync md5sum scp ssh" + dependencies_found="" + dependencies_not_found="" + for checkPath in ${path_check} ; do + for checkDependencies in ${dependencies} ; do + if [ -f ${checkPath}/${checkDependencies} ] ; then + dependencies_found="${dependencies_found} ${checkDependencies}" + fi + done + done + for notFound in ${dependencies} ; do + check_found_one=$(echo ${dependencies_found} | grep " ${notFound}") + check_found_two=$(echo ${dependencies_found} | grep "${notFound} ") + if_not_found="${check_found_one}${check_found_two}" + if [ -z "${if_not_found}" ] ; then + dependencies_not_found="${dependencies_not_found} ${notFound}" + fi + done + echo "* Checking necessary tools... " + # Show if all tools are installed + if [ -z "${dependencies_not_found}" ] ; then + echo "* The necessary tools are installed" echo "" else + echo "* Some required tools are not installed:${dependencies_not_found}" + echo "* The process has been stopped" echo "" exit fi @@ -705,7 +689,7 @@ elif [ "${1}" == "-i" ] ; then dirServer=$(cat ${dirConfig}/ks-upload-dirserver) dirLocal=$(cat ${dirConfig}/ks-upload-dirlocal) # Call the functions to perform the whole process. - echo -n "* Scanning ${dirLocal} " && sleep 4 + echo -n "* Scanning ${dirLocal} " echo "" current_tool=$(cat ${dirConfig}/ks-upload-tool) if [ "${current_tool}" == "scp" ] ; then diff --git a/src/ks-upv b/src/ks-upv index 434c78c..4ed0c43 100755 --- a/src/ks-upv +++ b/src/ks-upv @@ -2,12 +2,12 @@ ######################################################################### # ks-upv (ks-tools) - Upload videos file(s) to server with scp or rsync # -# Date: 10-02-2023 # +# Date: 12-02-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="100223" +M_DATE="120223" # Global parameters. dirTemp="/tmp" @@ -658,49 +658,33 @@ function showHelp() { # Function to check if all the necessary tools # for the execution are installed. function checkDependencies() { - dependence=0 - echo -n "* Checking necessary tools... " - sleep 3 && echo "" - sshpass -h &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'sshpass' tool is not installed!" - dependence=1 - fi - expect -v &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'expect' tool is not installed!" - dependence=1 - fi - md5sum --help &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'md5sum' tool is not installed!" - dependence=1 - fi - rsync --version &> /dev/null - OUTPUT=$? - if [ ${OUTPUT} -ne 0 ] ; then - echo "* The 'rsync' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/scp ] ; then - echo "OK" > /dev/null - else - echo "* The 'scp' tool is not installed!" - dependence=1 - fi - if [ -f /usr/bin/ssh ] ; then - echo "OK" > /dev/null - else - echo "* The 'ssh' tool is not installed!" - dependence=1 - fi - if [ ${dependence} -eq 0 ] ; then - echo "* Necessary tools installed!" + path_check="/usr/bin /bin /usr/local/bin ${HOME}/.local/bin" + dependencies="sshpass expect rsync md5sum scp ssh" + dependencies_found="" + dependencies_not_found="" + for checkPath in ${path_check} ; do + for checkDependencies in ${dependencies} ; do + if [ -f ${checkPath}/${checkDependencies} ] ; then + dependencies_found="${dependencies_found} ${checkDependencies}" + fi + done + done + for notFound in ${dependencies} ; do + check_found_one=$(echo ${dependencies_found} | grep " ${notFound}") + check_found_two=$(echo ${dependencies_found} | grep "${notFound} ") + if_not_found="${check_found_one}${check_found_two}" + if [ -z "${if_not_found}" ] ; then + dependencies_not_found="${dependencies_not_found} ${notFound}" + fi + done + echo "* Checking necessary tools... " + # Show if all tools are installed + if [ -z "${dependencies_not_found}" ] ; then + echo "* The necessary tools are installed" echo "" else + echo "* Some required tools are not installed:${dependencies_not_found}" + echo "* The process has been stopped" echo "" exit fi @@ -802,7 +786,7 @@ elif [ "${1}" == "-i" ] ; then dirServer=$(cat ${dirConfig}/ks-upload-dirserver) dirLocal=$(cat ${dirConfig}/ks-upload-dirlocal) # Call the functions to perform the whole process. - echo -n "* Scanning ${dirLocal} " && sleep 4 + echo -n "* Scanning ${dirLocal} " echo "" if [ -d ${dirLocal} ] ; then listArchives "${dirLocal}"