From 79c16d2cb57ab5edb4a74c4ab16ebbcaefe0826b Mon Sep 17 00:00:00 2001 From: diiinesh <63147290+diiinesh@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:29:43 +0100 Subject: [PATCH] implemented suggested changes --- patch.diff | 74 ++++++++++++++++++++ scripts/src/main/resources/scripts/functions | 30 +++++--- 2 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 patch.diff diff --git a/patch.diff b/patch.diff new file mode 100644 index 000000000..5fb62175d --- /dev/null +++ b/patch.diff @@ -0,0 +1,74 @@ +From 8dbd26d746f8812694084e152f5ec79717eb4b44 Mon Sep 17 00:00:00 2001 +From: diiinesh <63147290+diiinesh@users.noreply.github.com> +Date: Fri, 13 Oct 2023 14:27:05 +0200 +Subject: [PATCH] #1153 - Implemented a check to see whether user is online and + adjusted the conditions for executing the functions doGitPullOrClone, + DoUpdateUrls and doDownload when user is online, otherwise skip these + functions. + +Signed-off-by: diiinesh <63147290+diiinesh@users.noreply.github.com> +--- + scripts/src/main/resources/scripts/functions | 22 +++++++++++++++++--- + 1 file changed, 19 insertions(+), 3 deletions(-) + +diff --git a/scripts/src/main/resources/scripts/functions b/scripts/src/main/resources/scripts/functions +index 5ba30b2..1f5ec6e 100755 +--- a/scripts/src/main/resources/scripts/functions ++++ b/scripts/src/main/resources/scripts/functions +@@ -1257,6 +1257,15 @@ function doGitPullOrClone() { + fi + } + ++# checks network connectivity status ++function checkNetworkStatus() { ++ if curl -s --head --fail https://www.google.com > /dev/null; then ++ return 0 # Online ++ else ++ return 1 # Offline ++ fi ++} ++ + # $1: name of software + # $2: version of software + # $3: optional silent flag ('silent' to suppress output if already up-to-date or empty for version output) +@@ -1279,6 +1288,10 @@ function doInstall() { + local repository="${8}" + local url="${9}" + local target_filename="${10}" ++ ++ checkNetworkStatus ++ local isOnline=$? ++ + if [ -z "${target_path}" ] + then + target_path="${DEVON_IDE_HOME}/software/${software}" +@@ -1291,12 +1304,15 @@ function doInstall() { + doFail "Missing software argument for doInstall: ${*}" + fi + local result=0 +- if [ "${url/.git/}" != "${url}" ] ++ if [ "${url/.git/}" != "${url}" ] && [ "$isOnline" = 0 ] + then + doGitPullOrClone "${target_path}" "${url}" + return + fi +- doUpdateUrls ++ if [ "$isOnline" = 0 ] ++ then ++ doUpdateUrls ++ fi + if [ -z "${version}" ] + then + version=$(doGetLatestSoftwareVersion "${software}") +@@ -1381,7 +1397,7 @@ function doInstall() { + install_path="${DEVON_SOFTWARE_PATH}/${repo}/${software}/${version}" + version_file="${install_path}/.devon.software.version" + fi +- if [ ! -d "${install_path}" ] || [ "${install_path}" == "${target_path}" ] ++ if [ ! -d "${install_path}" ] || [ "${install_path}" == "${target_path}" ] && [ "$isOnline" = 0 ] + then + doDownload "${url}" "${download_dir}" "${software}" "${version}" "${edition}" "${os}" "${arch}" "${ext}" "${target_filename}" + doDebug "Received download file ${DOWNLOAD_FILENAME} with file name ${target_filename}" +-- +2.40.0.windows.1 + diff --git a/scripts/src/main/resources/scripts/functions b/scripts/src/main/resources/scripts/functions index 811dffdb1..5f6ea7bd8 100755 --- a/scripts/src/main/resources/scripts/functions +++ b/scripts/src/main/resources/scripts/functions @@ -1196,6 +1196,8 @@ function doGitPullOrClone() { local dir="${1}" local url="${2}" local git_opts="" + + if [ -d "${dir}/.git" ] then pushd "${dir}" > /dev/null || exit 255 @@ -1220,7 +1222,14 @@ function doGitPullOrClone() { then message="${message}It seems you are working on a local branch. For testing, you may continue...\n" else - doFail "${message}See above error for details - check your network connectivity and retry." + # Check network connectivity + doCheckNetworkStatus + local isOnline=$? + if [ "$isOnline" = 1 ] + then + doWarning "You are offline - git repo could not be updated." + return + fi fi fi popd > /dev/null || exit 255 @@ -1289,8 +1298,7 @@ function doInstall() { local url="${9}" local target_filename="${10}" - doCheckNetworkStatus - local isOnline=$? + local exitcode_offline=10 if [ -z "${target_path}" ] then @@ -1304,15 +1312,12 @@ function doInstall() { doFail "Missing software argument for doInstall: ${*}" fi local result=0 - if [ "${url/.git/}" != "${url}" ] && [ "$isOnline" = 0 ] + if [ "${url/.git/}" != "${url}" ] then doGitPullOrClone "${target_path}" "${url}" return fi - if [ "$isOnline" = 0 ] - then - doUpdateUrls - fi + doUpdateUrls if [ -z "${version}" ] then version=$(doGetLatestSoftwareVersion "${software}") @@ -1359,6 +1364,13 @@ function doInstall() { fi return 1 else + doCheckNetworkStatus + local isOnline=$? + if [ "$isOnline" = 1 ] + then + doWarning "You are offline - can not install update." + return ${exitcode_offline} + fi doEcho "Updating ${software} from version ${current_version} to version ${version}..." fi fi @@ -1409,7 +1421,7 @@ function doInstall() { install_path="${DEVON_SOFTWARE_PATH}/${repo}/${software}/${version}" version_file="${install_path}/.devon.software.version" fi - if [ ! -d "${install_path}" ] || [ "${install_path}" == "${target_path}" ] && [ "$isOnline" = 0 ] + if [ ! -d "${install_path}" ] || [ "${install_path}" == "${target_path}" ] then doDownload "${url}" "${download_dir}" "${software}" "${version}" "${edition}" "${os}" "${arch}" "${ext}" "${target_filename}" doDebug "Received download file ${DOWNLOAD_FILENAME} with file name ${target_filename}"