Skip to content

Commit

Permalink
rewrote automatic update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kwindrem committed Aug 14, 2021
1 parent adc2287 commit 9c84f1a
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 105 deletions.
Binary file modified .DS_Store
Binary file not shown.
18 changes: 7 additions & 11 deletions ReadMe
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ to install and update packages.

packageAutoUpdater handles automatic package updates.

There are two methods and they should NOT be used at the same time: USB and GitHub.

GitHub updates are enabled from the setup menu (g) option.

if GuiMods is up to date, auto updates can also be controlled from
Expand All @@ -77,7 +75,6 @@ Automatic updates can be controlled via the GuiMods menu or options in the Setup
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 @@ -90,27 +87,26 @@ To use the USB update process:
Choose the .tar.gz download link.
(Do not download from the Code tab or download the .zip file. These won't work.)
Copy the archive files to a USB memory stick.
Do NOT unpack the archive
Insert the stick in the Venus device.

Regardless the update source (USB or GitHub),
packageAutoUpdater replaces the current copy on the Venus device with the archive contents.
packageAutoUpdater replaces the current copy on the Venus device with the archive contents
but only if the version number of the source is newer than the one that's installed.
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.
You may wish to dispalbe GitHub updates if you are updating from a USB/SD memory stick to avoid conflicts.
(GitHub and files on a USB stick could have different versions.)

packageAutoUpdater runs in the background (as a service).


packageInstaller provides the opportunity to install packages for the first time, or reinstall them.
For each package, packageInstaller prompts the user to install that package.
Reinstallation is not allowed if automatic updates are enabled.
Those packages are skipped.
The user is prompted to disable automaitc updates while running packageInstaller
before checking for packages.
Packages that are already installed will be skipped if automatic updates are enabled.

Packages can be installed from eithera USB memory stick or from GitHub.
Packages can be installed from either a USB memory stick/SD memory card or from GitHub.
After the package is copied to the Venus device it's setup script is run
and the user must answer the prompts to complete the instalation.

Expand All @@ -120,7 +116,7 @@ As with package automatic updates, GitHub is the desired source if your Venus de

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:
/data/SetupHelper/manualUpdate
/data/SetupHelper/packageInstaller

When a package is updated from GitHub or a USB stick, the currently installed package is moved to a backup directory
so that the package can be returned to a previous verison should this be necessary.
Expand Down
2 changes: 0 additions & 2 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ getFromUsb ()
local package=$1
local packageArchive="/media/$dir/$package"-$gitHubBranch.tar.gz
local packageDir="/data/$package"
local archiveTimeStamp=""
local lastUpdate=""

# archive not found on USB stick
Expand Down Expand Up @@ -113,7 +112,6 @@ getFromGitHub ()
{
local package=$1
local packageDir="/data/$package"
local archiveTimeStamp=""
local lastUpdate=""

# get the version from local copy of package
Expand Down
185 changes: 113 additions & 72 deletions packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -33,96 +33,146 @@ setSetting ()
dbus -y com.victronenergy.settings $dbusPath SetValue "$newValue" > /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
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
19 changes: 3 additions & 16 deletions packageInstaller
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,15 +65,14 @@ 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"
else
installText="install"
fi


if $updateFromUsb ; then
for dir in ${mediaList[@]} ; do
getFromUsb $package
Expand Down
Loading

0 comments on commit 9c84f1a

Please sign in to comment.