Skip to content

Commit

Permalink
implemented suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
diiinesh committed Jan 26, 2024
1 parent 9c82f57 commit 79c16d2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 9 deletions.
74 changes: 74 additions & 0 deletions patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From 8dbd26d746f8812694084e152f5ec79717eb4b44 Mon Sep 17 00:00:00 2001
From: diiinesh <[email protected]>
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 <[email protected]>
---
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

30 changes: 21 additions & 9 deletions scripts/src/main/resources/scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 79c16d2

Please sign in to comment.