Skip to content

Commit

Permalink
switched auto updates to versions
Browse files Browse the repository at this point in the history
previously a time stamp was used to trigger updates. Now that version numbers exist, the updates are now based on that number.

Also, increased control of the automatic updates (see ReadMe)
  • Loading branch information
kwindrem committed Aug 7, 2021
1 parent f104d41 commit 2407702
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 96 deletions.
Binary file modified .DS_Store
Binary file not shown.
27 changes: 1 addition & 26 deletions CommonResources
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gitHubUser="kwindrem"
setupHelperDir="/data/SetupHelper"
source "$setupHelperDir/LogHandler"
source "$setupHelperDir/ServiceResources"
source "$setupHelperDir/UpdateResources"
reinstallParam="reinstall"


Expand Down Expand Up @@ -296,32 +297,6 @@ restoreActiveFile ()
fi
}

# converts a Venus version string to a version number
#
# beta numbers are handled in a special way.
# the released verison has no beta string
# it's number would be less than a beta version
# we bump the version number by 999
# so the release is always greater than any beta
#
# the "-large-n" portion is discarded so those versions
# can be compared to non-large versions
#
# the version string is passed as $1
# the number is returned in versionNumber

function versionStringToNumber ()
{
local versionBeta=""

read versionNumber versionBeta <<< $(echo $1 | sed -e 's/v//' -e 's/-.*$//' | \
awk -v FS='[v.~-]' '{printf "%d%03d%03d %d\n", $1, $2, $3, $3}')
if (( $versionBeta == 0 )); then
((versionNumber += 999))
fi
}


# sets a dbus setting
# $1 is new value
# $2 is the dbus path
Expand Down
15 changes: 12 additions & 3 deletions ReadMe
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ if GuiMods is up to date, auto updates can also be controlled from
If enabled, automatic GitHub update checks will download and install the GitHub version
if it is newer than the current version.

One update check is made every 10 minutes, so it takes up to an hour check all packages.
Version numbers use the same syntax as Venus OS:
v<major>.<minor>~<test>
v2.45 would replace v2.45~68 as test versions lead up to an eventual release

Automatic updates can be controlled via the GuiMods menu or options in the SetupHelper setup script
Normal checks GitHub for a package once every 10 minutes
Fast checks GitHub for a package once every 10 seconds
Once checks GitHub for a package once every 10 minutes, but only once, then updates are turned off
Disable disables GitHub updates
Updates from USB/SD media disable Git Hub updates to avoid conflicts

If you are experimenting with modificaitons and wish to avoid GitHub updates overriding your work,
disable automatic updates.
Expand All @@ -89,7 +98,7 @@ Then the package's setup script is run to reinstall the modificaitons.
No user interaction is needed in this process.

A USB package update disables automatic GitHub updates to avoid conflicts.
(GitHub and files on a USB stick could have different timestamps.)
(GitHub and files on a USB stick could have different versions.)

packageAutoUpdater runs in the background (as a service).

Expand All @@ -107,7 +116,7 @@ and the user must answer the prompts to complete the instalation.

The method of putting an archive on a USB stick for manaul install is the same as the one for automatic updates.

As with package updates, GitHub is the desired source if your Venus device has an internet connection.
As with package automatic updates, GitHub is the desired source if your Venus device has an internet connection.

packageInstaller is called from the SetupHelper setup script by choosing the package (p) option at the main prompt.
The packageInstaller is a shell script and can also be run manually:
Expand Down
19 changes: 16 additions & 3 deletions ServiceResources
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
# starting with v2.80~10, services are stored in this directory which is overlayed onto /service
# all services need to be added there rather than /service
# Note: service calls (eg svc) are still made on /service/...
# there is an unknown interaction between /service and the overlay source
# so code here operates on both directories

victronServicesDir="/opt/victronenergy/service"
if [ -d "$victronServicesDir" ]; then
serviceDir="$victronServicesDir"
serviceOverlay=true
else
serviceDir="/service"
serviceOverlay=false
fi
echo "#### serviceDir $serviceDir"

_killServiceProcesses ()
{
Expand All @@ -44,9 +47,15 @@ _startService ()
{
local pkg=$1
rm -f "$serviceDir/$pkg/down"
if $serviceOverlay ; then
rm -f "/service/$pkg/down"
fi
svc -u "/service/$pkg"
if [ -e "$serviceDir/$pkg/log" ]; then
rm -f "$serviceDir/$pkg/log/down"
if $serviceOverlay ; then
rm -f "/service/$pkg/log/down"
fi
svc -u "/service/$pkg/log"
fi
}
Expand Down Expand Up @@ -103,8 +112,12 @@ _removeService ()
svc -d "/service/$pkg"

# remove the active service directory
rm -rf "$serviceDir/$pkg"

# removing the service in the overlayed service directory doesn't remove it from /service
# so that needs to be removed FIRST
rm -rf "/service/$pkg"
if $serviceOverlay ; then
rm -rf "$serviceDir/$pkg"
fi
# kill related processes
_killServiceProcesses $pkg
}
Expand Down
103 changes: 71 additions & 32 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@ setupOptionsRoot="/data/setupOptions"

exitReboot=123

# converts a Venus version string to a version number
#
# beta numbers are handled in a special way.
# the released verison has no beta string
# it's number would be less than a beta version
# we bump the version number by 999
# so the release is always greater than any beta
#
# the "-large-n" portion is discarded so those versions
# can be compared to non-large versions
#
# the version string is passed as $1
# the number is returned in versionNumber

function versionStringToNumber ()
{
local versionBeta=""

read versionNumber versionBeta <<< $(echo $1 | sed -e 's/v//' -e 's/-.*$//' | \
awk -v FS='[v.~-]' '{printf "%d%03d%03d %d\n", $1, $2, $3, $3}')
if (( $versionBeta == 0 )); then
((versionNumber += 999))
fi
}


# get the package from a USB file
# The package is left in $package-$gitHubBranch for processing later
# $1 is the name of the package
Expand All @@ -40,34 +66,40 @@ getFromUsb ()
return 0
fi

# get the timeStamp from local copy of package
if [ -f "$packageDir/timeStamp" ]; then
lastUpdate=$(cat "$packageDir/timeStamp")
# get the version from local copy of package
if [ -f "$packageDir/version" ]; then
installedVersion=$(cat "$packageDir/version")
else
lastUpdate=""
installedVersion=""
fi

# get archive timeStamp
archiveTimeStamp=$(cat "/data/$package-$gitHubBranch/timeStamp")
# get archive version
archiveVersion=$(cat "/data/$package-$gitHubBranch/version")
if [ ! -e "$packageDir" ]; then
if $logToConsole ; then
echo "$package not yet installed"
fi
return 1
elif [ -z $archiveTimeStamp ]; then
logMessage "ERROR: No timestamp in $package archive - can't update"
elif [ -z $archiveVersion ]; then
logMessage "ERROR: No version in $package archive - can't update"
return 0
elif [ -z $lastUpdate ]; then
logMessage "WARNING: no timestamp for $package current installation - proceeding"
elif [ -z $installedVersion ]; then
logMessage "WARNING: no version for $package current installation - proceeding"
return 1
elif (( $lastUpdate >= $archiveTimeStamp )); then
if $logToConsole ; then
echo "$package is up to date"
fi
return 0
# archive is newer
else
return 1
# convert versions to numbers and compare them
versionStringToNumber $archiveVersion
archiveVersionNumber=$versionNumber
versionStringToNumber $installedVersion
if (( $versionNumber >= $archiveVersionNumber )); then
if $logToConsole ; then
echo "$package is up to date"
fi
return 0
# archive is newer
else
return 1
fi
fi
}

Expand All @@ -83,29 +115,36 @@ getFromGitHub ()
local packageDir="/data/$package"
local archiveTimeStamp=""
local lastUpdate=""
# get the timeStamp from local copy of package
if [ -f "$packageDir/timeStamp" ]; then
lastUpdate=$(cat "$packageDir/timeStamp")

# get the version from local copy of package
if [ -f "$packageDir/version" ]; then
installedVersion=$(cat "$packageDir/version")
else
lastUpdate=""
installedVersion=""
fi
# fetch archive timeStamp
archiveTimeStamp=$(wget -qO - https://raw.githubusercontent.com/$gitHubUser/$package/$gitHubBranch/timeStamp)

# fetch archive version
archiveVersion=$(wget -qO - https://raw.githubusercontent.com/$gitHubUser/$package/$gitHubBranch/version)
if [ ! -e "$packageDir" ]; then
if $logToConsole ; then
echo "$package not yet installed"
fi
elif [ -z $archiveTimeStamp ]; then
logMessage "ERROR: Can't access GitHub archive or no timestamp for $package - can't update"
elif [ -z $archiveVersion ]; then
logMessage "ERROR: Can't access GitHub archive or no version for $package - can't update"
return 0
elif [ -z $lastUpdate ]; then
logMessage "WARNING: no timestamp for $package current installation - proceeding"
elif (( $lastUpdate >= $archiveTimeStamp )); then
if $logToConsole ; then
echo "$package is up to date"
elif [ -z $installedVersion ]; then
logMessage "WARNING: no version for $package current installation - proceeding"
else
# convert versions to numbers and compare them
versionStringToNumber $archiveVersion
archiveVersionNumber=$versionNumber
versionStringToNumber $installedVersion
if (( $versionNumber >= $archiveVersionNumber )); then
if $logToConsole ; then
echo "$package is up to date"
fi
return 0
fi
return 0
fi
# update the package and reinstall it
wget -qO - https://github.com/$gitHubUser/$package/archive/$gitHubBranch.tar.gz | tar -xzf - -C /data
Expand Down
Loading

0 comments on commit 2407702

Please sign in to comment.