Skip to content

Commit

Permalink
enhancements to manual package installer
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed Nov 17, 2021
1 parent 7768a99 commit 9e5dbab
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 62 deletions.
Binary file modified .DS_Store
Binary file not shown.
39 changes: 30 additions & 9 deletions DbusSettingsResources
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,23 @@ updateDbusIntSetting ()
}


# removeDbusSetting removes the setting from dbus Settings
# removeDbusSettings removes the setting from dbus Settings
#
# $1 is the path to the setting to be removed starting with /Settings
# all parameters are each a quoted path to the setting to be removed
# e.g., removeDbusSettings "/Settings/foo" "/Settings/bar"
# (including all settings in one dbus call is much faster)

removeDbusSetting ()
removeDbusSettings ()
{
logMessage "removing dbus Setting $1"
dbus -y com.victronenergy.settings / RemoveSettings "%[\"$1\" ]" &> /dev/null
logMessage "removing dbus Settings $@"
local settings=$(echo "$@" | sed -e s_^_\"_ -e s_\$_\"_ -e s_\ _'", "'_g)
dbus -y com.victronenergy.settings / RemoveSettings "%[ $settings ]" &> /dev/null
}


# setSetting updates the dbus setting parameter
# the setting must already exist or the update will fail
# (the setting can not be created without knowing the data type(s))
#
# $1 is the new value
# $2 is the setting path
Expand All @@ -86,22 +90,39 @@ setSetting ()

# move a setting from setup options or from previous dbus Setting
# $1 is the setup options path
# $2 is the old dbus path
# $2 is the old dbus path (has priority over setup option)
# $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
#
# setup options can either contain a value or be a flag file
# for flag files, the file will be empty and the state of the option
# depends on the presence of the file (true) or absense of the file (false)
#
# Note: this function does NOT create or remove any old option or Setting
# use other functions or commands to do so

moveSetting ()
{
local setupOption="$1"
local oldDbusPath=$2
local newDbusPath=$3
if [ -f "$setupOption" ]; then
oldSetting=$(cat "$setupOption")
elif [ ! -z "$oldDbusPath" ]; then

if [ ! -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}')
elif [ ! -z $setupOption ]; then
if [ -f "$setupOption" ]; then
oldSetting=$(cat "$setupOption")
# flag file - old setting is true (1)
if [ -z $oldSetting ]; then
oldSetting=1
fi
# file did not exist - assume a false value for a flag file
else
oldSetting=0
fi
else
oldSetting=""
fi
Expand Down
2 changes: 1 addition & 1 deletion FileSets/PageSettingsPackageControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.victron.velib 1.0
MbPage {
id: root
title: qsTr("Package Versions")
property string bindPrefix: "com.victronenergy.settings/Settings/GuiMods"
property string bindPrefix: "com.victronenergy.settings/Settings/PackageVersion"
VBusItem { id: checkingPackageItem; bind: Utils.path(bindPrefix, "/CheckingPackage") }
property string checkingPackage: checkingPackageItem.valid ? checkingPackageItem.value : ""

Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 22 additions & 8 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ getFromUsb ()
archiveVersion=$(cat "/data/$package-$fileSuffix/version")
if [ ! -e "$packageDir" ]; then
if $logToConsole ; then
echo "$package not yet installed"
echo "$package not yet installed - proceeding"
fi
return 1
elif [ -z $archiveVersion ]; then
Expand All @@ -135,29 +135,41 @@ getFromUsb ()
# get the package from a GitHub
# The package is left in $package-$gitHubBranch for processing later
# $1 is the name of the package
#
# $2 is a boolean: when true archive download is skipped
# used by packageInstaller when a package is aready installed and auto updates are enabled
# if auto updates are enabled and update will be skipped anyway
# returns 0 if update should NOT occur or 1 if update is acceptable

getFromGitHub ()
{
local package=$1
local packageDir="/data/$package"
local lastUpdate=""

local skipDownload
if [ $# -gt 1 ] && $2 ; then
checkOnly=true
else
checkOnly=false
fi

# get the version from local copy of package
if [ -f "$packageDir/version" ]; then
installedVersion=$(cat "$packageDir/version")
else
installedVersion=""
fi

# fetch archive version
archiveVersion=$(wget -qO - https://raw.githubusercontent.com/$gitHubUser/$package/$gitHubBranch/version)
if [ ! -e "$packageDir" ]; then
if $logToConsole ; then
echo "$package not yet installed"
echo "$package not yet installed - proceeding"
fi
elif [ -z $archiveVersion ]; then
logMessage "ERROR: Can't access GitHub archive or no version for $package - can't update"
fi

# fetch archive version
archiveVersion=$(wget -qO - https://raw.githubusercontent.com/$gitHubUser/$package/$gitHubBranch/version)
if [ -z $archiveVersion ]; then
logMessage "ERROR: no version for $package $gitHubUser $gitHubBranch on GitHub - can't continue"
return 0
elif [ -z $installedVersion ]; then
logMessage "WARNING: no version for $package current installation - proceeding"
Expand All @@ -168,14 +180,16 @@ getFromGitHub ()
echo "$package is up to date"
fi
return 0
elif $checkOnly ; then
return 1
fi
fi
# update the package and reinstall it
wget -qO - https://github.com/$gitHubUser/$package/archive/$gitHubBranch.tar.gz | tar -xzf - -C /data
if [ $? -eq 0 ]; then
return 1
else
logMessage "ERROR: $package $gitHubUser $gitHubBranch not available"
logMessage "ERROR: can't access $package $gitHubUser $gitHubBranch on GitHub"
return 0
fi
}
Expand Down
8 changes: 4 additions & 4 deletions packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ updateStatus ()
fi
# update GUI status message
if $updateDbus ; then
updateDbusStringSetting "/Settings/GuiMods/CheckingPackage" "$message"
updateDbusStringSetting "/Settings/PackageVersion/CheckingPackage" "$message"
fi
lastMessage=$1
lastPackage=$package
Expand Down Expand Up @@ -127,7 +127,7 @@ while true ; do
doUpdate=false

# pull Git Hub autoupdate mode from dbus
autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/GitHubAutoUpdate\
autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/PackageVersion/GitHubAutoUpdate\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
if [ -z $autoUpdateSetting ]; then
autoUpdateSetting=0
Expand Down Expand Up @@ -243,10 +243,10 @@ while true ; do
if ! $restartFromFirstPackage && ! $updateSetupHelper; then
# single pass
if (( $autoUpdateSetting == 3 )) ; then
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
setSetting 0 /Settings/PackageVersion/GitHubAutoUpdate
# end of first pass, switch to slow updates
elif (( $autoUpdateSetting == 2 )) ; then
setSetting 1 /Settings/GuiMods/GitHubAutoUpdate
setSetting 1 /Settings/PackageVersion/GitHubAutoUpdate
fi
fi
usbCheck=false
Expand Down
24 changes: 13 additions & 11 deletions packageInstaller
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if $updateFromUsb ; then
fi

# allow reinstallations if auto updates are not enabled
autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/GitHubAutoUpdate\
autoUpdateSetting=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/PackageVersion/GitHubAutoUpdate\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
if [ -z $autoUpdateSetting ] || [ $autoUpdateSetting == 0 ]; then
autoUpdatesEnabled=false
Expand Down Expand Up @@ -78,16 +78,14 @@ while read -u 9 package gitHubUser gitHubBranch; do
doUpdate=false
packageDir="/data/$package"



##########################################################
# if automatic updates are enabled, skip packages that have alreay been installed
if [ -e $packageDir ] && [ -f "$setupOptionsRoot/$package/installOk" ]; then
if $autoUpdatesEnabled ; then
echo "$package has already been installed and will be automatically updated - skipping"
continue
fi
# if automatic updates are enabled, skip packages that are installed
checkOnly=false
if [ -e $packageDir ] && [ -f "$installedFlagPrefix"$package ]; then
installText="reinstall"
# update will be skipped so set a flag so getFromGitHub only checks versions
if ! $updateFromUsb ; then
checkOnly=true
fi
else
installText="install"
fi
Expand All @@ -109,8 +107,12 @@ while read -u 9 package gitHubUser gitHubBranch; do

# check GitHub
else
getFromGitHub $package
getFromGitHub $package $checkOnly
if [ $? -eq 1 ]; then
if $autoUpdatesEnabled ; then
echo "$package needs update but will be updated automatically - skipping"
continue
fi
echo
yesNoPrompt "$installText $package from GitHub? (y/n): "
if $yesResponse ; then
Expand Down
45 changes: 19 additions & 26 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ source "/data/SetupHelper/CommonResources"

cleanupDbusSettings ()
{
dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/PackageVersions/GeneratorConnector\
dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/GitHubAutoUpdate\
com.victronenergy.BusItem.GetValue &> /dev/null
if (( $? == 0 )); then
removeDbusSetting "/Settings/GuiMods/PackageVersions/GeneratorConnector"
removeDbusSetting "/Settings/GuiMods/PackageVersions/GuiMods"
removeDbusSetting "/Settings/GuiMods/PackageVersions/GuiMods2"
removeDbusSetting "/Settings/GuiMods/PackageVersions/RpiDisplaySetup"
removeDbusSetting "/Settings/GuiMods/PackageVersions/RpiGpioSetup"
removeDbusSetting "/Settings/GuiMods/PackageVersions/RpiTemp"
removeDbusSetting "/Settings/GuiMods/PackageVersions/SetupHelper"
removeDbusSetting "/Settings/GuiMods/PackageVersions/TankRepeater"
removeDbusSetting "/Settings/GuiMods/PackageVersions/VeCanSetup"
removeDbusSetting "/Settings/GuiMods/PackageVersions/ShutdownMonitor"
removeDbusSettings "/Settings/GuiMods/PackageVersions/GeneratorConnector" "/Settings/GuiMods/PackageVersions/GuiMods"\
"/Settings/GuiMods/PackageVersions/GuiMods" "/Settings/GuiMods/PackageVersions/RpiDisplaySetup"\
"/Settings/GuiMods/PackageVersions/RpiGpioSetup" "/Settings/GuiMods/PackageVersions/RpiTemp"\
"/Settings/GuiMods/PackageVersions/SetupHelper" "/Settings/GuiMods/PackageVersions/TankRepeater",\
"/Settings/GuiMods/PackageVersions/VeCanSetup" "/Settings/GuiMods/PackageVersions/ShutdownMonitor"\
"/Settings/GuiMods/CheckingPackage" "/Settings/GuiMods/CheckingPackage"
fi
}

Expand All @@ -38,20 +34,17 @@ if [ $scriptAction == 'NONE' ] ; then
# NOTE: if new settings are added in the future, change test for that one
# to avoid creating that new parameter !!!!

dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/GuiMods/CheckingPackage\
dbus-send --system --print-reply=literal --dest=com.victronenergy.settings /Settings/PackageVersion/CheckingPackage\
com.victronenergy.BusItem.GetValue &> /dev/null
if (( $? != 0 )); then
logMessage "creating SetupHelper Settings"
dbus -y com.victronenergy.settings /Settings AddSettings\
'%[ {"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
'%[ {"path": "/PackageVersion/GitHubAutoUpdate", "default":0},\
{"path": "/PackageVersion/CheckingPackage", "default":""},]' > /dev/null
# relocate options and current values
moveSetting "$setupOptionsDir/autoGitHubUpdate" "/Settings/GuiMods/GitHubAutoUpdate" "/PackageVersion/GitHubAutoUpdate"
rm -f "$setupOptionsDir/autoGitHubUpdate"
moveSetting "" "/Settings/GuiMods/CheckingPackage" "/PackageVersion/CheckingPackage"
fi

# display initial message
Expand Down Expand Up @@ -115,7 +108,7 @@ if [ $scriptAction == 'NONE' ] ; then
;;
[gG]*)
autoUpdate=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings\
/Settings/GuiMods/GitHubAutoUpdate\
/Settings/PackageVersion/GitHubAutoUpdate\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $3}')
case $autoUpdate in
1)
Expand All @@ -141,16 +134,16 @@ if [ $scriptAction == 'NONE' ] ; then
if [ ! -z $response ]; then
case $response in
[nN]* | [eE]*)
setSetting 1 /Settings/GuiMods/GitHubAutoUpdate
setSetting 1 /Settings/PackageVersion/GitHubAutoUpdate
;;
[fF]*)
setSetting 2 /Settings/GuiMods/GitHubAutoUpdate
setSetting 2 /Settings/PackageVersion/GitHubAutoUpdate
;;
[oO]*)
setSetting 3 /Settings/GuiMods/GitHubAutoUpdate
setSetting 3 /Settings/PackageVersion/GitHubAutoUpdate
;;
[dD]*)
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
setSetting 0 /Settings/PackageVersion/GitHubAutoUpdate
;;
*)
esac
Expand Down
4 changes: 2 additions & 2 deletions updatePackageVersions
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ done

index=$newCount
while (( $index < $oldCount )); do
removeDbusSetting "/Settings/PackageVersion/$index/PackageName"
removeDbusSetting "/Settings/PackageVersion/$index/PackageVersion"
removeDbusSettings "/Settings/PackageVersion/$index/PackageName"\
"/Settings/PackageVersion/$index/PackageVersion"
((index++))
done

Expand Down
Binary file modified venus-data.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.4
v3.5

0 comments on commit 9e5dbab

Please sign in to comment.