Skip to content

Commit

Permalink
bug fixes in auto update
Browse files Browse the repository at this point in the history
auto update would hang if some packages in the all packages list were not in stalled.

Also added autoupdate status to GuiMods menu
  • Loading branch information
kwindrem committed Aug 9, 2021
1 parent 2407702 commit 31596dc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion CommonResources
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ endScript ()
fi
# flag verison not installed
if [ $scriptAction == 'UNINSTALL' ] ; then
packageVersion="("$packageVersion")"
packageVersion="(not installed) $packageVersion"
fi
# update version Setting - will fail silently if dbus setting doesn't exist
dbus -y com.victronenergy.settings /Settings/GuiMods/PackageVersions/$packageName SetValue "$packageVersion" &> /dev/null
Expand Down
45 changes: 30 additions & 15 deletions packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ source "/data/SetupHelper/UpdateResources"
# $2 is the dbus path
setSetting ()
{
local newValue=$1
local dbusPath=$2
if [ ! -z $newValue ]; then
dbus -y com.victronenergy.settings $dbusPath SetValue $newValue > /dev/null
fi
local newValue="$1"
local dbusPath="$2"
dbus -y com.victronenergy.settings $dbusPath SetValue "$newValue" > /dev/null
}

#### main code starts here
Expand All @@ -43,13 +41,15 @@ checkUSB=true
lastUpdateTime=0
checkingPackage=false
updateSetupHelper=false
checkingMessage=''


# 10 minutes between GitHub checks to minimize network traffic
gitHubSlowCheckDelay=600
# 10 seconds for first pass
gitHubFastCheckDelay=10
gitHubCheckDelay=0
skipEndProcessing=false
speedUpLoop=false

lastGitHubUpdateSetting=0

Expand All @@ -64,7 +64,7 @@ while true ; do
i=0
pkgArray=($allPackages)
while (( i < ${#pkgArray[@]} )); do
skipEndProcessing=false
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
Expand All @@ -78,7 +78,7 @@ while true ; do
packageDir="/data/$package"
setupOptionsDir="$setupOptionsRoot"/$package
if [ ! -f "$setupOptionsDir/optionsSet" ]; then
sleep 1
((i++))
continue
# package has been installed, look for it's archives
else
Expand Down Expand Up @@ -112,12 +112,14 @@ while true ; do

# 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
# if speeding up the loop, start package scan over
if (( $autoUpdateSetting >= 2 )) && (( $lastGitHubUpdateSetting <= 1 )); then
checkingPackage=false
skipEndProcessing=true
# prevent end processing that changes update mode
speedUpLoop=true
lastGitHubUpdateSetting=$autoUpdateSetting
fi
if $speedUpLoop ; then
break
fi

Expand All @@ -132,13 +134,20 @@ 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'
lastUpdateTime=$currentTime
getFromGitHub $package
if [ $? -eq 1 ]; then
logMessage "found $package on GitHub"
doUpdate=true
fi
checkingPackage=false
elif (( $autoUpdateSetting != 0 )); then
if [[ $checkingMessage != 'WAIT' ]] ; then
setSetting "waiting to check $package" /Settings/GuiMods/CheckingPackage
checkingMessage='WAIT'
fi
fi
fi
if $doUpdate ; then
Expand All @@ -156,21 +165,25 @@ while true ; do
elif [ ! -z $autoUpdateSetting ] && (( $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
if ! $checkingPackage ; then
((i++))
fi
sleep 1
lastGitHubUpdateSetting=$autoUpdateSetting
done

# prevent further USB updates until media is removed and reinserted
if $updatedFromUsb ; then
checkUSB=false
fi

# continue execution in packageAutoUpdateCleanup
# so that this script and the service can exit cleanly
if $updateSetupHelper || $rebootNeeded ; then
Expand All @@ -185,7 +198,8 @@ while true ; do
sleep 10000
fi

if ! $skipEndProcessing ; then
# 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
Expand All @@ -194,4 +208,5 @@ while true ; do
setSetting 1 /Settings/GuiMods/GitHubAutoUpdate
fi
fi
sleep 1
done
9 changes: 5 additions & 4 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ if [ $scriptAction == 'NONE' ] ; then
# if one setting exists, assume they are all there
# NOTE: if new settings are added in the future, change test for that one
# to avoid creating that new parameter !!!!
autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/GitHubAutoUpdate\

lastSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiModsCheckingPackage\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
if [ -z $autoUpdateSetting ]; then
if [ -z $lastSetting ]; then
logMessage "creating SetupHelper Settings"
dbus -y com.victronenergy.settings /Settings AddSettings\
'%[{"path": "/GuiMods/GitHubAutoUpdate", "default":0} ]' > /dev/null
'%[ {"path": "/GuiMods/GitHubAutoUpdate", "default":0},\
{"path": "/GuiMods/CheckingPackage", "default":""},]' > /dev/null
# move setup option flag to dbus setting
if [ -f "$setupOptionsDir/autoGitHubUpdate" ]; then
setSetting 1 /Settings/GuiMods/GitHubAutoUpdate
rm -f "$setupOptionsDir/autoGitHubUpdate"
else
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
fi

fi

# display innitial message
Expand Down
2 changes: 1 addition & 1 deletion timeStamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1628380139
1628488795
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.3
v2.4

0 comments on commit 31596dc

Please sign in to comment.