Skip to content

Commit

Permalink
blind install, other user packages
Browse files Browse the repository at this point in the history
Many changes in this version

Most notably is a SD/USB blind install option

Also support for packages developed by other users

Moved package version infomation and GitHub updates from GuiMods to this package
  • Loading branch information
kwindrem committed Nov 15, 2021
1 parent c577eba commit ac25a71
Show file tree
Hide file tree
Showing 39 changed files with 3,767 additions and 230 deletions.
Binary file modified .DS_Store
Binary file not shown.
103 changes: 29 additions & 74 deletions CommonResources
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CommonResources for SetupHelper
# contains a functions and variables necessare for a setup script to interface with reinstallMods
# contains a functions and variables necessary for a setup script to interface with reinstallMods
#
# Refer to the SetupHelper ReadMe file for details on how to use these resources.

Expand All @@ -10,7 +10,7 @@ source "$setupHelperDir/EssentialResources"
source "$setupHelperDir/LogHandler"
source "$setupHelperDir/ServiceResources"
source "$setupHelperDir/UpdateResources"
reinstallParam="reinstall"
source "$setupHelperDir/DbusSettingsResources"

# what action the script should take:
# NONE - do noting - signals script to prompt for user input on how to proceed
Expand All @@ -36,6 +36,8 @@ runAgain=false
filesUpdated=false
restartGui=false



# yesNoPrompt provides user prompting requesting a yes/no response
#
# $1 is the prompt displayed when pausing for user input
Expand Down Expand Up @@ -264,44 +266,6 @@ restoreActiveFile ()
fi
}

# 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
#
Expand Down Expand Up @@ -455,14 +419,17 @@ endScript ()
logMessage "adding $shortScriptName" to $(basename "$reinstallScriptsList")
echo "$fullScriptName" "$reinstallParam" >> "$reinstallScriptsList"
fi

if [ ! -f "$rcLocal" ]; then
logMessage "creating $rcLocal"
cat "$setupHelperDir/rcS.local" > "$rcLocal"
chmod +x "$rcLocal"
elif [ $(grep -c "SetupHelper" "$rcLocal") == 0 ]; then
logMessage "adding SetupHelper reinstall script to $rcLocal"
sed -e '1d' "$setupHelperDir/rcS.local" >> $rcLocal
# update reinstall call to nohup background
elif [ $(grep -c "nohup /data/SetupHelper" "$rcLocal") == 0 ]; then
logMessage "updating SetupHelper reinstall script in $rcLocal"
sed -i -e 's?/data/SetupHelper?nohup /data/SetupHelper?' -e 's?reinstallMods?reinstallMods > /dev/null \&?' "$rcLocal"
fi

# installed flag is removed if script needs to run again
Expand All @@ -474,6 +441,24 @@ endScript ()
touch "$installedFlag"
fi

# add package to packageList if not already there and the GitHub paths have been specified
if [ ! -z $packageGitHubUser ] && [ ! -z $packageGitHubBranch ]; then
# move from previous locaiton
oldPackageListFile="$setupOptionsRoot/SetupHelper/packageList"
if [ -f "$oldPackageListFile" ]; then
mv "$oldPackageListFile" "$packageListFile"
fi

if [ ! -f "$packageListFile" ] || [ $(grep -c "$packageName\s" "$packageListFile") == 0 ]; then
logMessage "adding $packageName to SetupHelper package list"
echo "$packageName $packageGitHubUser $packageGitHubBranch" >> "$packageListFile"
fi
fi

# update package version for the gui - takes time so do in background
nohup "/data/SetupHelper/updatePackageVersions" > /dev/null &


elif [ $scriptAction == 'UNINSTALL' ] ; then
# remove this script from reinstallScriptsList to prevent further calls during boot
if [ -f "$reinstallScriptsList" ] && [ ! $(grep -c "$fullScriptName" "$reinstallScriptsList") == 0 ]; then
Expand All @@ -484,41 +469,11 @@ endScript ()

# clean up only - flag not used since package is being removed
rm -f "$installedFlag"

# update package version for the gui - takes time so do in background
nohup "/data/SetupHelper/updatePackageVersions" > /dev/null &
fi

# create/update dbus version setting
# do only if not running as a boot-time reinstall
# dbus services won't be up if running from rcS.local
if $force || ! $reinstall ; then
if [ $scriptAction == 'INSTALL' ] ; then
# create the version setting if it doesn't exist yet
packageVersion=$(dbus-send --system --print-reply=literal\
--dest=com.victronenergy.settings /Settings/GuiMods/PackageVersions/$packageName\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $2}')
if [ -z $packageVersion ]; then
logMessage "creating $packageName version Setting"
dbus -y com.victronenergy.settings /Settings AddSettings\
"%[ {\"path\":\"/GuiMods/PackageVersions/$packageName\", \"default\":\"unknown\"} ]" &> /dev/null
fi
fi
if [ -f "$scriptDir/version" ]; then
packageVersion=$(cat "$scriptDir/version")
# if no version, use package timestamp instead
elif [ -f "$scriptDir/timeStamp" ]; then
timeStamp=$(cat "$scriptDir/timeStamp")
packageVersion=$(date --date=@$timeStamp)
else
packageVersion="unknown"
fi
# flag verison not installed
if [ $scriptAction == 'UNINSTALL' ] ; then
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
fi


# this script was called from reinstallMods
# set exit code based on actual code
if $runningAtBoot ; then
Expand Down
111 changes: 111 additions & 0 deletions DbusSettingsResources
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# DbusSettingsResources for SetupHelper
#
# contains a functions and variables necessary to access dbus Settings parameters
# it should be sourced by scripts setting, creating and removing dbus settings
#
# dbus Settings is not operational during system boot when some setup scripts may
# need to make settings changes
# These functions check to see if the settings system is operational and defer
# the set/create/remove activity so the calling script may continue

source "/data/SetupHelper/EssentialResources"
source "/data/SetupHelper/LogHandler"

# dbus Settings funcitons
# These functions encapsulate an interface to dbus Settings
# NOTE: dbus Settings resources are not always active when it is necessary for
# scripts to make changes or create/remove settings
# it is up to the caller to insure dbus Settings resources are active before callling
# these functions
# a dbus exeption error will be logged if settings are not active yet


# updateDbusStringSetting updates a dbus setting STRING parameter with a new value
# if the setting does not exist, it is created
#
# functions for other data types have not been included but could be added
# the determining factor is the values supplied for default, max and min values
# as they determine the underlying data type for the setting
#
# $1 is the path to the setting starting with /Settings
# $2 is the new value
#
# if the setting does not yet exist, it is created, then updated to the new value

updateDbusStringSetting ()
{
local oldValue

oldValue=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings "$1"\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $2}')
if [ -z $oldValue ]; then
logMessage "creating dbus Setting $1"
dbus -y com.victronenergy.settings / AddSettings "%[ {\"path\":\"$1\", \"default\":\"\"} ]" &> /dev/null
fi

dbus -y com.victronenergy.settings "$1" SetValue "$2" &> /dev/null
}


updateDbusIntSetting ()
{
local oldValue

oldValue=$(dbus-send --system --print-reply=literal --dest=com.victronenergy.settings "$1"\
com.victronenergy.BusItem.GetValue 2> /dev/null | awk '{print $2}')
if [ -z $oldValue ]; then
logMessage "creating dbus Setting $1"
dbus -y com.victronenergy.settings / AddSettings "%[ {\"path\":\"$1\", \"default\":0} ]" &> /dev/null
fi

dbus -y com.victronenergy.settings "$1" SetValue "$2" &> /dev/null
}


# removeDbusSetting removes the setting from dbus Settings
#
# $1 is the path to the setting to be removed starting with /Settings

removeDbusSetting ()
{
logMessage "removing dbus Setting $1"
dbus -y com.victronenergy.settings / RemoveSettings "%[\"$1\" ]" &> /dev/null
}


# setSetting updates the dbus setting parameter
# the setting must already exist or the update will fail
#
# $1 is the new value
# $2 is the setting path

setSetting ()
{
dbus -y com.victronenergy.settings $2 SetValue $1 &> /dev/null
}

# 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
}
12 changes: 8 additions & 4 deletions EssentialResources
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ reinstallScriptsList="/data/reinstallScriptsList"
pkgFileSets="$scriptDir/FileSets"
fileSet="$pkgFileSets/$venusVersion"

# GitHub account
gitHubUser="kwindrem"
gitHubBranch="current"

# rc local file that calls reinstallMods
# use /data/rc.local if some scripts need resources not available at time rcS.local runs
rcLocal="/data/rcS.local"
Expand All @@ -32,7 +28,15 @@ rcLocal="/data/rcS.local"
exitReboot=123
exitSuccess=0

reinstallParam="reinstall"

# directory that holds script's options
# options were removed from the script directory so they are preserved when the package is reinstalled
setupOptionsRoot="/data/setupOptions"
setupOptionsDir="$setupOptionsRoot"/$packageName

# packages managed by SetupHelper
packageListFile="/data/packageList"

qmlDir=/opt/victronenergy/gui/qml

26 changes: 26 additions & 0 deletions FileSets/MbDisplayPackageVersion.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import QtQuick 1.1
import com.victron.velib 1.0
import "utils.js" as Utils

MbItem {
id: root
///////////// height: 30

property int versionIndex
property string bindPrefix

function getBind(param)
{
return Utils.path(bindPrefix, "/", versionIndex, "/", param)
}

VBusItem { id: packageName; bind: getBind ("PackageName") }
VBusItem { id: packageVersion; bind: getBind ("PackageVersion") }

MbItemValue
{
description: packageName.valid ? packageName.value : ""
item.bind: getBind ("PackageVersion")
show: item.valid && packageName.valid
}
}
43 changes: 43 additions & 0 deletions FileSets/PageSettingsPackageControl.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/////// new menu for package version display

import QtQuick 1.1
import "utils.js" as Utils
import com.victron.velib 1.0

MbPage {
id: root
title: qsTr("Package Versions")
property string bindPrefix: "com.victronenergy.settings/Settings/GuiMods"
VBusItem { id: checkingPackageItem; bind: Utils.path(bindPrefix, "/CheckingPackage") }
property string checkingPackage: checkingPackageItem.valid ? checkingPackageItem.value : ""

model: VisualItemModel
{
MbSubMenu
{
description: qsTr("Package Version List")
subpage: Component { PageSettingsPackageVersions {} }
}
MbItemOptions
{
id: autoUpdate
description: qsTr ("Automatic Git Hub updates")
bind: Utils.path (bindPrefix, "/GitHubAutoUpdate")
possibleValues:
[
MbOption { description: "Normal"; value: 1 },
MbOption { description: "Fast one pass then Normal"; value: 2 },
MbOption { description: "Check packages once (Fast)"; value: 3 },
MbOption { description: "Disabled"; value: 0 }
]
writeAccessLevel: User.AccessUser
}
MbItemText
{
text: checkingPackage
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
show: checkingPackage != ""
}
}
}
22 changes: 22 additions & 0 deletions FileSets/PageSettingsPackageVersions.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/////// new menu for package version display

import QtQuick 1.1
import "utils.js" as Utils
import com.victron.velib 1.0

MbPage {
id: root
title: qsTr("Package Version List")
property string bindPrefix: "com.victronenergy.settings/Settings/PackageVersion"
property VBusItem count: VBusItem { bind: Utils.path(bindPrefix, "/Count") }

model: count.valid ? count.value : 0
delegate: Component
{
MbDisplayPackageVersion
{
bindPrefix: root.bindPrefix
versionIndex: index
}
}
}
1 change: 1 addition & 0 deletions FileSets/fileList
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/opt/victronenergy/gui/qml/PageSettings.qml
Loading

0 comments on commit ac25a71

Please sign in to comment.