Skip to content

Commit

Permalink
added auto update control from GUI; added package backups
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed Jul 25, 2021
1 parent 0830968 commit dbc1b24
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 133 deletions.
Binary file modified .DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions CommonResources
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,45 @@ function versionStringToNumber ()
}


# sets a dbus setting
# $1 is new value
# $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
}

# move a setting from setup options or from previous dbus Setting
# $1 is the setup options path
# $2 is the old dbus path
# $3 is the new dbus path
# dbus paths start with /Settings
# if specified, the setup option file must include a value
# that value has priority over the old dbus parameter

moveSetting ()
{
local setupOption="$1"
local oldDbusPath=$2
local newDbusPath=$3
if [ -f "$setupOption" ]; then
oldSetting=$(cat "$setupOption")
elif [ ! -z "$oldDbusPath" ]; then
oldSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings\
$oldDbusPath com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
else
oldSetting=""
fi
if [ ! -z $oldSetting ] && [ ! -z "$newDbusPath" ]; then
dbus -y com.victronenergy.settings $newDbusPath SetValue $oldSetting > /dev/null
fi
}

# checkFileSets validates the file sets used install package modifications
#
# It attempts to create a file set for a new Venus version
Expand Down
9 changes: 8 additions & 1 deletion ReadMe
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ There are two methods and they should NOT be used at the same time: USB and GitH

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

if GuiMods is up to date, auto updates can also be controlled from
Device List / Settings / Display & language / GuiMods / Auto update packages ...

If enabled, automatic GitHub update checks will download and install the GitHub version
if it is newer than the current version.

Expand Down Expand Up @@ -106,7 +109,11 @@ packageInstaller is called from the SetupHelper setup script by choosing the pac
The packageInstaller is a shell script and can also be run manually:
/data/SetupHelper/manualUpdate


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.
Two complete backups plus the current installation are saved.
Backups are in /data and are named with -backup1 and -backup2 appended to the package name.
-backup2 is the oldest

Setup script aids:

Expand Down
16 changes: 16 additions & 0 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ getFromGitHub ()

# install the archive and run setup script
#
# backup the last 2 versions in case
# it is necessary to revert to a previous verion
#
# $1 is the package name
# $2 is the flag to allow running the script with user interaction

Expand All @@ -133,6 +136,19 @@ doUpdate ()
else
installOk=false
fi

# backup last 2 versions
if [ -e "$packageDir-backup2" ]; then
rm -rf "$packageDir-backup2"
fi
if [ -e "$packageDir-backup1" ]; then
mv "$packageDir-backup1" "$packageDir-backup2"
fi
if [ -e "$packageDir" ]; then
mv "$packageDir""$package-backup1"
fi
# move new version into active position
mv "$packageDir-$gitHubBranch" "$packageDir"

if [ -f "$packageDir/setup" ]; then
# if options have been set previously, reinstall automatically
Expand Down
24 changes: 17 additions & 7 deletions packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ logToConsole=false

source "/data/SetupHelper/UpdateResources"

# set dbus setting
# $1 is new value
# $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
}

#### main code starts here

Expand Down Expand Up @@ -67,6 +78,8 @@ while true ; do
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}')
# media found, look for package archives
if $checkUSB && [ ! -z $mediaList ]; then
for dir in ${mediaList[@]} ; do
Expand All @@ -75,16 +88,17 @@ while true ; do
logMessage "found $package on USB"
updatedFromUsb=true
doUpdate=true
if [ -f "$setupOptionsRoot/SetupHelper/autoGitHubUpdate" ]; then
if [ $autoUpdateSetting == 1 ]; then
logMessage "USB update disables GitHub updates - must be reenabled manually !!"
rm -f "$setupOptionsRoot/SetupHelper/autoGitHubUpdate"
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
autoUpdateSetting=0
fi
break;
fi
done
checkingPackage=false
fi
if [ -f "$setupOptionsRoot/SetupHelper/autoGitHubUpdate" ]; then
if [ $autoUpdateSetting == 1 ]; then
currentTime=$(date '+%s')
# wait between GitHub updates to minimize traffic
if (( $currentTime >= $lastUpdateTime + $gitHubCheckDelay )) ; then
Expand All @@ -98,10 +112,6 @@ while true ; do
fi
fi
if $doUpdate ; then
# move unpacked archive into position
packageDir="/data/$package"
rm -rf "$packageDir"
mv "$packageDir-$gitHubBranch" "$packageDir"
# do SetupHelper update now since other setup scripts depend on it's resources
# will end this script which will start up again via supervise
if [ $package == "SetupHelper" ]; then
Expand Down
10 changes: 4 additions & 6 deletions packageInstaller
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ fi
# allow reinstallations if auto updates are not enabled
# or if they are disabled here
reinstallOk=false
if [ ! -f "$setupOptionsRoot/SetupHelper/$setupOptionsRoot/SetupHelper" ]; 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 [ $autoUpdateSetting == 1 ]; then
reinstallOk=true
else
echo "manual package reinstallation may conflict with automatic updates"
Expand All @@ -59,7 +61,7 @@ else
if $yesResponse ; then
logMessage "Disabling automatic package updates"
echo "package reinstallation is now possible"
rm -rf "$setupOptionsRoot/SetupHelper/$setupOptionsRoot/SetupHelper"
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
reinstallOk=true
fi
fi
Expand Down Expand Up @@ -115,10 +117,6 @@ for package in $allPackages; do
fi
fi
if $doUpdate ; then
# move unpacked archive into position
packageDir="/data/$package"
rm -rf "$packageDir"
mv "$packageDir-$gitHubBranch" "$packageDir"
# defer running SetupHelper script
if [ $package == "SetupHelper" ]; then
updateSetupHelper=true
Expand Down
31 changes: 27 additions & 4 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ source "/data/SetupHelper/CommonResources"

#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
# create dbus Settings if they haven't been set previously
# 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\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
if [ -z $autoUpdateSetting ]; then
logMessage "creating SetupHelper Settings"
dbus -y com.victronenergy.settings /Settings AddSettings\
'%[{"path": "/GuiMods/GitHubAutoUpdate", "default":0} ]' > /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
echo
echo "This package provides support functions and utilities for Venus modificaiton packages"
Expand Down Expand Up @@ -74,7 +94,10 @@ if [ $scriptAction == 'NONE' ] ; then
displayLog $setupLogFile
;;
[gG]*)
if [ -f "$setupOptionsDir/autoGitHubUpdate" ]; 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"
Expand All @@ -83,11 +106,11 @@ if [ $scriptAction == 'NONE' ] ; then
if [ ! -z $response ]; then
if [ $response == 'e' ] || [ $response == 'E' ]; then
logMessage "enabling automatic GitHub package updates"
touch "$setupOptionsDir/autoGitHubUpdate"
setSetting 1 /Settings/GuiMods/GitHubAutoUpdate
elif [ $response == 'd' ] || [ $response == 'D' ]; then
logMessage "disabling automatic GitHub package updates"
rm -f "$setupOptionsDir/autoGitHubUpdate"
fi
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
fi
fi
;;
[pP]*)
Expand Down
114 changes: 0 additions & 114 deletions setup (original)

This file was deleted.

2 changes: 1 addition & 1 deletion timeStamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1626985917
1627172684

0 comments on commit dbc1b24

Please sign in to comment.