From 9c84f1ace1e6df722df36176c71e32ede5419903 Mon Sep 17 00:00:00 2001 From: kwindrem <58538395+kwindrem@users.noreply.github.com> Date: Fri, 13 Aug 2021 22:03:55 -0700 Subject: [PATCH] rewrote automatic update There were problems with USB updates when Git Hub updates were proceeding at a normal rate. packageAutoUpdater script was rewritten to recognize a USB/SD memory device within 1 second then update from it while holding off further Git Hub updates. Git Hub updates are allowed to proceed after USB/SD updates have been performed. USB/SD update checks are made only once when the device is inserted. You must remove then reinstert the card to trigger USB/SD updates again. --- .DS_Store | Bin 6148 -> 6148 bytes ReadMe | 18 ++--- UpdateResources | 2 - packageAutoUpdater | 185 +++++++++++++++++++++++++++------------------ packageInstaller | 19 +---- setup | 3 +- timeStamp | 2 +- version | 2 +- 8 files changed, 126 insertions(+), 105 deletions(-) diff --git a/.DS_Store b/.DS_Store index 89a4afafa87a47a7508572f5359dbc6a36d7458c..9a2d4ecff4ed184e4ec4ce1bef649a7cb4dcf157 100644 GIT binary patch delta 132 zcmZoMXfc=|#>CJ*F;Q%yo+2a5!~knXmdQLUQVz}B3=9k`40;Ud44Diix%nS&-v9^JIPzLq>+lHayas JV?r literal 6148 zcmeHK%T59@6g>qN1Q)V&IbR?#{=kT1Vj@Z+%9>}8WQLi*U}D_N2lzqm{Tw%bg6Fo4 zfgpyBM$NsXJ?*{sw9}KBmI5%%<>&~g1E{hHR%)z1F^Nmru#)#k(8w6^yEf@Km@isbmzydk_2^#1!JI0djF})2$>NL^=`f)~tyKY4U|oT->(=G`Kihu)Ungl#6;K8Kl>(*` zb)qJhZP#mQM4u=H5OB(HF2DXjc)Y#VYEAFx /dev/null } +# updates status message on GUI +# $1 is the message identifier (not the actual message + +lastMessage='' +lastPackage='' + +updateStatus () +{ + updateDbus=false + checkPackage=false + if [[ $1 == 'IDLE' ]] ; then + message="Fast updates: 10 sec/pkg, Normal updates: 10 min/pkg" + elif [[ $1 == 'USB_DISABLED' ]] ; then + message="USB/SD updates disabled auto GitHub updates" + elif [[ $1 == 'CHECKING' ]] ; then + message="checking $package" + checkPackage=true + elif [[ $1 == 'WAIT' ]] ; then + message="waiting to check $package" + checkPackage=true + elif [[ $1 == 'USB_CHECK' ]] ; then + message="Checking USB/SD for updates" + else + message="" + fi + if [[ $1 != $lastMessage ]]; then + updateDbus=true + elif $checkPackage && [[ $package != $lastPackage ]]; then + updateDbus=true + fi + # update GUI status message + if $updateDbus ; then + setSetting "$message" /Settings/GuiMods/CheckingPackage + fi + lastMessage=$1 + lastPackage=$package +} + + #### main code starts here logMessage "starting up" -checkUSB=true +usbCheck=false +mediaDetected=false lastUpdateTime=0 checkingPackage=false updateSetupHelper=false -checkingMessage='' # 10 minutes between GitHub checks to minimize network traffic @@ -49,80 +88,91 @@ gitHubSlowCheckDelay=600 # 10 seconds for first pass gitHubFastCheckDelay=10 gitHubCheckDelay=0 -speedUpLoop=false lastGitHubUpdateSetting=0 + # loop forever while true ; do rebootNeeded=false - updatedFromUsb=false - # loop through packages, but don't look at new package until time has expired - # this loop will run every 5 seconds even if waiting to access GitHub again + # loop through packages, but don't look at new package until it's been checked for an update + # this loop will run every second even if waiting to access GitHub again # this permits detection of USB media during the long wait for the next GitHub check - i=0 pkgArray=($allPackages) + i=0 while (( i < ${#pkgArray[@]} )); do - speedUpLoop=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 + # look for installed package if ! $checkingPackage ; then package=${pkgArray[i]} packageDir="/data/$package" setupOptionsDir="$setupOptionsRoot"/$package if [ ! -f "$setupOptionsDir/optionsSet" ]; then - ((i++)) + (( i++ )) continue - # package has been installed, look for it's archives + # package has been installed, continue else checkingPackage=true fi fi + + doUpdate=false + + # pull Git Hub autoupdate mode from dbus + 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 + + # check for USB / SD media + mediaList=($(ls /media)) + # no media + if [ -z $mediaList ] ; then + mediaDetected=false + usbCheck=false + # media first detected, start loop over and enable USB checks + elif ! $mediaDetected ; then + mediaDetected=true + usbCheck=true + updateStatus 'USB_CHECK' + i=0 + continue + fi + + # nothing to do - reset loop and wait + if (( $autoUpdateSetting == 0 )) && ! $usbCheck ; then + i=0 + checkingPackage=false + updateStatus 'IDLE' + sleep 1 + continue + 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 + # USB / SD updates + if $usbCheck ; then for dir in ${mediaList[@]} ; do getFromUsb $package if [ $? -eq 1 ]; then logMessage "found $package on USB" - updatedFromUsb=true doUpdate=true - checkingPackage=false - if [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting != 0 )); then - logMessage "USB update disables GitHub updates - must be reenabled manually !!" - setSetting 0 /Settings/GuiMods/GitHubAutoUpdate - autoUpdateSetting=0 - fi + updateStatus 'CHECKING' break; fi done - fi - - # if USB update not pending and auto update enabled, look for GitHub updates - if ! $doUpdate && (( $autoUpdateSetting != 0 )); then + # done checking for this package, time to move on + checkingPackage=false + + # Git Hub updates + elif (( $autoUpdateSetting != 0 )); then # if speeding up the loop, start package scan over if (( $autoUpdateSetting >= 2 )) && (( $lastGitHubUpdateSetting <= 1 )); then checkingPackage=false - # prevent end processing that changes update mode - speedUpLoop=true lastGitHubUpdateSetting=$autoUpdateSetting + i=0 + continue fi - if $speedUpLoop ; then - break - fi - # set update delay based on update mode if (( $autoUpdateSetting >= 2 )) ; then @@ -134,8 +184,7 @@ while true ; do currentTime=$(date '+%s') # wait between GitHub updates to minimize traffic if (( $currentTime >= $lastUpdateTime + $gitHubCheckDelay )) ; then - setSetting "checking $package" /Settings/GuiMods/CheckingPackage - checkingMessage='CHECKING' + updateStatus 'CHECKING' lastUpdateTime=$currentTime getFromGitHub $package if [ $? -eq 1 ]; then @@ -144,10 +193,7 @@ while true ; do fi checkingPackage=false elif (( $autoUpdateSetting != 0 )); then - if [[ $checkingMessage != 'WAIT' ]] ; then - setSetting "waiting to check $package" /Settings/GuiMods/CheckingPackage - checkingMessage='WAIT' - fi + updateStatus 'WAIT' fi fi if $doUpdate ; then @@ -161,29 +207,34 @@ while true ; do # update via unattended reinstall only logMessage "updating $package" doUpdate $package + if $usbCheck ; then + sleep 1 + fi fi - elif [ ! -z $autoUpdateSetting ] && (( $autoUpdateSetting == 0 )); then + elif (( $autoUpdateSetting == 0 )); then rm -rf "$packageDir-$gitHubBranch" fi - if (( $autoUpdateSetting == 0 )); then - if [[ $checkingMessage != 'IDLE' ]] ; then - setSetting "Fast updates: 10 sec/pkg, Normal updates: 10 min/pkg" /Settings/GuiMods/CheckingPackage - checkingMessage='IDLE' - fi - fi fi # end if checkingPackage - # current package was checked - move on to the next one - # if checking was deferred, stay on this package + # go to next package if done with this one if ! $checkingPackage ; then - ((i++)) + (( i++ )) + fi + if $usbCheck ; then + usleep 200000 + else + sleep 1 fi - sleep 1 done - # prevent further USB updates until media is removed and reinserted - if $updatedFromUsb ; then - checkUSB=false + # 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 + usbCheck=false + # continue execution in packageAutoUpdateCleanup # so that this script and the service can exit cleanly if $updateSetupHelper || $rebootNeeded ; then @@ -198,15 +249,5 @@ while true ; do sleep 10000 fi - # skip processing if we've brokend out of the loop and starting with first package - if ! $speedUpLoop ; 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 sleep 1 done diff --git a/packageInstaller b/packageInstaller index 697d3a1..1bc92cf 100755 --- a/packageInstaller +++ b/packageInstaller @@ -48,26 +48,14 @@ if $updateFromUsb ; then fi # allow reinstallations if auto updates are not enabled -# or if they are disabled here -reinstallOk=false 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 [ $autoUpdateSetting == 1 ]; then +if [ -z $autoUpdateSetting ] || [ $autoUpdateSetting == 0 ]; then reinstallOk=true else - echo "manual package reinstallation may conflict with automatic updates" - echo "automatic must be disabled to manually reinstall packages" - yesNoPrompt "Do you wish to disable automatic updates? (y/n): " - if $yesResponse ; then - logMessage "Disabling automatic package updates" - echo "package reinstallation is now possible" - setSetting 0 /Settings/GuiMods/GitHubAutoUpdate - reinstallOk=true - fi + reinstallOk=false fi - - rebootNeeded=false updateSetupHelper=false for package in $allPackages; do @@ -77,7 +65,7 @@ for package in $allPackages; do # if automatic updates are enabled, skip packages that have alreay been installed if [ -e $packageDir ] && [ -f "$setupOptionsRoot/$package/optionsSet" ]; then if ! $reinstallOk ; then - echo "$package found on but has already been installed - skipping" + echo "$package has already been installed and will be automatically updated - skipping" continue fi installText="reinstall" @@ -85,7 +73,6 @@ for package in $allPackages; do installText="install" fi - if $updateFromUsb ; then for dir in ${mediaList[@]} ; do getFromUsb $package diff --git a/setup b/setup index 2ef68d1..79847e9 100755 --- a/setup +++ b/setup @@ -43,8 +43,7 @@ if [ $scriptAction == 'NONE' ] ; then echo "Prevouslly uninstalled packages can also be installed and configured" echo " as an option from the menu either from GitHub or from a USB stick" echo - echo "If internet access is not available, you can manually update/install from a USB stick" - echo "Note: installing from a USB stick disables automatic GitHub updates" + echo "If internet access is not available, you can manually update/install from a USB stick or SD card" echo if [ -f "$setupOptionsDir/optionsSet" ]; then diff --git a/timeStamp b/timeStamp index 25132b0..b2ee970 100644 --- a/timeStamp +++ b/timeStamp @@ -1 +1 @@ -1628488795 +1628916919 diff --git a/version b/version index 92491a0..62c36de 100644 --- a/version +++ b/version @@ -1 +1 @@ -v2.5 +v2.6