From 24077025700274f4c21354ef3c566392ed29de79 Mon Sep 17 00:00:00 2001 From: kwindrem <58538395+kwindrem@users.noreply.github.com> Date: Sat, 7 Aug 2021 16:51:37 -0700 Subject: [PATCH] switched auto updates to versions 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) --- .DS_Store | Bin 6148 -> 6148 bytes CommonResources | 27 +----------- ReadMe | 15 +++++-- ServiceResources | 19 +++++++-- UpdateResources | 103 +++++++++++++++++++++++++++++++-------------- packageAutoUpdater | 73 ++++++++++++++++++++++++-------- setup | 49 +++++++++++++++------ timeStamp | 2 +- version | 2 +- 9 files changed, 194 insertions(+), 96 deletions(-) diff --git a/.DS_Store b/.DS_Store index 0d964166fcee4b02bfb1511928df8caf05752513..6cc6a1c395cc4288e0f300625e3b7e5ebf564271 100644 GIT binary patch literal 6148 zcmeHK%T59@6g>qJ37W`~<$Qri;s=a4CMKdLj^M6!?n@$hTX<0frbM$$Yt;IZtQ*F47%^a99(__9nX%d0rhiJt92Xp|uNfhI34JkVDy*3KjIrxi zaA{Ytj}!JX;V)vZ*W}GvT9Dn-WnhOM=}l%#UuFkTd*&ElBC`8{SGy0nsMXzA7nRu) z9C9!o;O-(qS|A05o} z6M$HvTN}&rmJp6-(YKfyWD89hD$!7tePSp>r{A-2zQxp_p+ninhq5Cp`$AEAboTG* za46rP%bfyFfvf^WQ?1JVf4cttpC!4PQ@|;(RSKw55C%;y$=CJ*F;Q%yo+2a5!~knXmdQLUQuaxl3=9k`40;Ud44Diix%nDvQ!)Q4S%NjRo(RHnVf^a{z7GEXeVlc{0C.~ + 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. @@ -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). @@ -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: diff --git a/ServiceResources b/ServiceResources index c0ba903..5806aee 100755 --- a/ServiceResources +++ b/ServiceResources @@ -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 () { @@ -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 } @@ -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 } diff --git a/UpdateResources b/UpdateResources index db0ef1f..49aba2e 100755 --- a/UpdateResources +++ b/UpdateResources @@ -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 @@ -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 } @@ -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 diff --git a/packageAutoUpdater b/packageAutoUpdater index 9665137..550fdf0 100755 --- a/packageAutoUpdater +++ b/packageAutoUpdater @@ -46,8 +46,12 @@ updateSetupHelper=false # 10 minutes between GitHub checks to minimize network traffic gitHubSlowCheckDelay=600 -# 30 seconds for first pass -gitHubCheckDelay=30 +# 10 seconds for first pass +gitHubFastCheckDelay=10 +gitHubCheckDelay=0 +skipEndProcessing=false + +lastGitHubUpdateSetting=0 # loop forever while true ; do @@ -60,26 +64,33 @@ while true ; do i=0 pkgArray=($allPackages) while (( i < ${#pkgArray[@]} )); do + skipEndProcessing=false doUpdate=false + # if no removable media is present allow usbUpdates to occur next time there is + # this prevents repeated processing of same files + mediaList=($(ls /media)) + if [ -z $mediaList ] ; then + checkUSB=true + fi # look for new package if ! $checkingPackage ; then package=${pkgArray[i]} packageDir="/data/$package" setupOptionsDir="$setupOptionsRoot"/$package + if [ ! -f "$setupOptionsDir/optionsSet" ]; then + sleep 1 + continue # package has been installed, look for it's archives - if [ -f "$setupOptionsDir/optionsSet" ]; then + else checkingPackage=true fi fi - # if no removable media is present allow usbUpdates to occur next time there is - # this prevents repeated processing of same files - mediaList=($(ls /media)) - if [ -z $mediaList ] ; then - checkUSB=true - fi if $checkingPackage ; then autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/GitHubAutoUpdate\ com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}') + if [ -z $autoUpdateSetting ]; then + autoUpdateSetting=0 + fi # media found, look for package archives if $checkUSB && [ ! -z $mediaList ]; then for dir in ${mediaList[@]} ; do @@ -89,7 +100,7 @@ while true ; do updatedFromUsb=true doUpdate=true checkingPackage=false - if [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting == 1 )); then + if [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting != 0 )); then logMessage "USB update disables GitHub updates - must be reenabled manually !!" setSetting 0 /Settings/GuiMods/GitHubAutoUpdate autoUpdateSetting=0 @@ -98,8 +109,27 @@ while true ; do fi done fi - if [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting == 1 )); then - currentTime=$(date '+%s') + + # if USB update not pending and auto update enabled, look for GitHub updates + if ! $doUpdate && (( $autoUpdateSetting != 0 )); then + # change in update mode, start package scan over + if (( $autoUpdateSetting != $lastGitHubUpdateSetting )); then + # start with first package, but don't break out of the loop + checkingPackage=false + skipEndProcessing=true + lastGitHubUpdateSetting=$autoUpdateSetting + break + fi + + + # set update delay based on update mode + if (( $autoUpdateSetting >= 2 )) ; then + gitHubCheckDelay=$gitHubFastCheckDelay + else + gitHubCheckDelay=$gitHubSlowCheckDelay + fi + + currentTime=$(date '+%s') # wait between GitHub updates to minimize traffic if (( $currentTime >= $lastUpdateTime + $gitHubCheckDelay )) ; then lastUpdateTime=$currentTime @@ -117,22 +147,23 @@ while true ; do if [ $package == "SetupHelper" ]; then updateSetupHelper=true break - # reinstall the package without user interactionl + # reinstall the package without user interaction else # update via unattended reinstall only logMessage "updating $package" doUpdate $package fi - elif [ -f "$setupOptionsRoot/SetupHelper/autoGitHubUpdate" ]; then + elif [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting == 0 )); then rm -rf "$packageDir-$gitHubBranch" fi - fi + fi # end if checkingPackage # current package was checked - move on to the next one # if checking was deferred, stay on this package if ! $checkingPackage ; then ((i++)) fi - sleep 5 + sleep 1 + lastGitHubUpdateSetting=$autoUpdateSetting done # prevent further USB updates until media is removed and reinserted @@ -154,5 +185,13 @@ while true ; do sleep 10000 fi - gitHubCheckDelay=$gitHubSlowCheckDelay + if ! $skipEndProcessing ; then + # single pass + if (( $autoUpdateSetting == 3 )) ; then + setSetting 0 /Settings/GuiMods/GitHubAutoUpdate + # end of first pass, switch to slow updates + elif (( $autoUpdateSetting == 2 )) ; then + setSetting 1 /Settings/GuiMods/GitHubAutoUpdate + fi + fi done diff --git a/setup b/setup index 53aaa23..31a2b2c 100755 --- a/setup +++ b/setup @@ -97,20 +97,43 @@ if [ $scriptAction == 'NONE' ] ; then autoUpdate=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings\ /Settings/GuiMods/GitHubAutoUpdate\ com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}') - if [ $autoUpdate == '1' ] ; then - echo "Automatic GitHub updates are currently ENABLED" - else - echo "Automatic GitHub updates are currently disabled" - fi - read -p "Enable (e) / Disable (d) / no change(cr)?: " response + case $autoUpdate in + 1) + echo "Automatic GitHub updates are at normal rate" + ;; + 2) + echo "Automatic GitHub updates are at fast rate" + ;; + 3) + echo "Automatic GitHub updates will occur only once" + ;; + *) + echo "Automatic GitHub updates are currently disabled" + ;; + esac + echo "Available modes:" + echo " Normal (n) - one package is checked once every 10 minutes" + echo " Fast (f) - one package is checked once every 10 seconds" + echo " Once (o) - each package is checked once then auto updates are turned off" + echo " Disable (d) - auto updates are disabled" + + read -p "Choose a mode from the above list: (cr for no change): " response if [ ! -z $response ]; then - if [ $response == 'e' ] || [ $response == 'E' ]; then - logMessage "enabling automatic GitHub package updates" - setSetting 1 /Settings/GuiMods/GitHubAutoUpdate - elif [ $response == 'd' ] || [ $response == 'D' ]; then - logMessage "disabling automatic GitHub package updates" - setSetting 0 /Settings/GuiMods/GitHubAutoUpdate - fi + case $response in + [nN]* | [eE]*) + setSetting 1 /Settings/GuiMods/GitHubAutoUpdate + ;; + [fF]*) + setSetting 2 /Settings/GuiMods/GitHubAutoUpdate + ;; + [oO]*) + setSetting 3 /Settings/GuiMods/GitHubAutoUpdate + ;; + [dD]*) + setSetting 0 /Settings/GuiMods/GitHubAutoUpdate + ;; + *) + esac fi ;; [pP]*) diff --git a/timeStamp b/timeStamp index 94a195a..5c46865 100644 --- a/timeStamp +++ b/timeStamp @@ -1 +1 @@ -1628293383 +1628380139 diff --git a/version b/version index eb41430..e70ef1d 100644 --- a/version +++ b/version @@ -1 +1 @@ -v2.2 +v2.3