diff --git a/.DS_Store b/.DS_Store index dfd377b..c9615e8 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/CommonResources b/CommonResources index e00ea64..c5d410a 100755 --- a/CommonResources +++ b/CommonResources @@ -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 diff --git a/ReadMe b/ReadMe index a02cba4..312a84b 100644 --- a/ReadMe +++ b/ReadMe @@ -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. @@ -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: diff --git a/UpdateResources b/UpdateResources index ee63262..8cc19e0 100755 --- a/UpdateResources +++ b/UpdateResources @@ -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 @@ -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 diff --git a/packageAutoUpdater b/packageAutoUpdater index 00f9ac9..9fd7281 100755 --- a/packageAutoUpdater +++ b/packageAutoUpdater @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/packageInstaller b/packageInstaller index d523114..697d3a1 100755 --- a/packageInstaller +++ b/packageInstaller @@ -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" @@ -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 @@ -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 diff --git a/setup b/setup index b76401d..53aaa23 100755 --- a/setup +++ b/setup @@ -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" @@ -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" @@ -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]*) diff --git a/setup (original) b/setup (original) deleted file mode 100755 index 70fefb0..0000000 --- a/setup (original) +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash - -# this script sets up the SetupHelper service -# This service provides automatic and manual updates for Venus modificaiton packages -# - -#### following lines incorporate SetupHelper utilities into this script -# Refer to the SetupHelper ReadMe file for details. - -source "/data/SetupHelper/CommonResources" - -#### end of lines to include SetupHelper - -#### running manually and OK to proceed - prompt for input -if [ $scriptAction == 'NONE' ] ; then - # display innitial message - echo - echo "This package provides support functions and utilities for Venus modificaiton packages" - echo "Packages are automatically reinstalled following a Venus OS update" - echo "Packages may also be automatically updated from GitHub" - echo " or a USB stick" - 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 [ -f "$setupOptionsDir/optionsSet" ]; then - enableReinstall=true - else - enableReinstall=false - fi - - response='' - fullPrompt=true - while true; do - if $fullPrompt ; then - echo - echo "Available actions:" - echo " Install and activate (i)" - if $enableReinstall ; then - echo " Reinstall (r) based on options provided at last install" - fi - echo " Uninstall (u) and restores all files to stock" - echo " Quit (q) without further action" - echo " Display setup log (s) outputs the last 100 lines of the log" - echo - echo " Enable/disable automatic GitHub package updates (g)" - echo " Manually install packages from GitHub or USB stick (p)" - echo - fullPrompt=false - fi - /bin/echo -n "Choose an action from the list above: " - read response - case $response in - [iI]*) - scriptAction='INSTALL' - break;; - [rR]*) - if $enableReinstall ; then - scriptAction='INSTALL' - break - fi - ;; - [uU]*) - scriptAction='UNINSTALL' - break - ;; - [qQ]*) - exit - ;; - [sS]*) - displayLog $setupLogFile - ;; - [gG]*) - if [ -f "$setupOptionsDir/autoGitHubUpdate" ]; 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 - if [ ! -z $response ]; then - if [ $response == 'e' ] || [ $response == 'E' ]; then - logMessage "enabling automatic GitHub package updates" - touch "$setupOptionsDir/autoGitHubUpdate" - elif [ $response == 'd' ] || [ $response == 'D' ]; then - logMessage "disabling automatic GitHub package updates" - rm -f "$setupOptionsDir/autoGitHubUpdate" - fi - fi - ;; - [pP]*) - "$scriptDir/packageInstaller" - fullPrompt=true - ;; - *) - esac - done - - # next step is to install - scriptAction='INSTALL' -fi - -if [ $scriptAction == 'INSTALL' ] ; then - installService $packageName -fi - -if [ $scriptAction == 'UNINSTALL' ] ; then - removeService $packageName -fi - -# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION -endScript diff --git a/timeStamp b/timeStamp index 7a3fe0b..a32ac27 100644 --- a/timeStamp +++ b/timeStamp @@ -1 +1 @@ -1626985917 +1627172684