Skip to content

Commit

Permalink
#1153: improve offline capability (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
diiinesh committed Jan 30, 2024
1 parent a7769d0 commit 95b5a75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions documentation/functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ The file specified in the first parameter is then unpacked into the directory sp
=== doUpdateUrls
Uses xref:doGitPullOrClone[] to clone or pull `urls` ensuring that everything is up-to-date.

=== doCheckNetworkStatus
Checks if system is connected to the internet, if online, it returns the value 0, and if offline, it returns the value 1.

== Functions on system PATH, files, or folders

=== doExtendPath
Expand Down
30 changes: 29 additions & 1 deletion 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 @@ -1257,6 +1266,15 @@ function doGitPullOrClone() {
fi
}

# checks network connectivity status
function doCheckNetworkStatus() {
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)
Expand All @@ -1279,6 +1297,9 @@ function doInstall() {
local repository="${8}"
local url="${9}"
local target_filename="${10}"

local exitcode_offline=10

if [ -z "${target_path}" ]
then
target_path="${DEVON_IDE_HOME}/software/${software}"
Expand Down Expand Up @@ -1343,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

0 comments on commit 95b5a75

Please sign in to comment.