Skip to content

Commit

Permalink
added package updates/installs
Browse files Browse the repository at this point in the history
added automatic and manual package updates

packages can be automatically updated from GitHub so that you always have the latest version and support for the latest Venus OS.

Packages can also be updated from USB stick.

Manual package installation can be performed from SetupHelper's setup script and can come from GitHub or a USB stick

fixed various bugs
  • Loading branch information
kwindrem committed Jun 13, 2021
1 parent 91e9a44 commit b06151f
Show file tree
Hide file tree
Showing 14 changed files with 1,046 additions and 159 deletions.
Binary file modified .DS_Store
Binary file not shown.
298 changes: 176 additions & 122 deletions CommonResources

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions LogHandler
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

setupLogFile="/var/log/SetupHelper"

# enable logging to console
# scripts can disable logging by setting
# logToConsole to false AFTER sourcing LogHandler
logToConsole=true

# output the last 100 lines of the log file to the console
# the full path to the log file should be passed in $1
# converts the tai64 time stamp to human readable form
Expand Down Expand Up @@ -38,7 +43,7 @@ displayLog ()
logMessage ()
{
# to console
if ! $runningAtBoot ; then
if $logToConsole ; then
echo "$*"
fi

Expand All @@ -57,17 +62,3 @@ logMessage ()
echo "$shortScriptName: $*" | tai64n >> $packageLogFile
fi
}


# truncates the log file if it's larger than 2000 lines
# it is called from the initialization code in CommonResources
# if NOT running at boot time

pruneSetupLogFile ()
{
if [ $(wc -l $setupLogFile | awk '{print $1}') -gt 2000 ]; then
tail -1000 $setupLogFile > $setupLogFile.tmp
mv $setupLogFile.tmp $setupLogFile
logMessage "log file truncated to last 1000 lines"
fi
}
138 changes: 119 additions & 19 deletions ReadMe
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
The SetupHelper package provides a set of utilities to simplfy
installing modifications to Victron Venus Os
and includes a mechanism to automatically reinstall them following a Venus OS update
The SetupHelper package provides:
a set of utilities to simplfy installing modifications to Victron Venus Os
a mechanism to automatically reinstall them following a Venus OS update
an automatic update mechanism to keep packages up to date
from GitHub archives or USB stick
a manual package installation mechanism from GitHub archives or USB stick

Supported pacages are:
SetupHelper GeneratorConnector GuiMods RpiDisplaySetup RpiGpioSetup TankRepeater

More information is provided below.

Setup:
The easiest way to install this code IF the Venus device has internet access is to run the following command:
There are two methods to fetch a package archive.

IF the Venus device has internet access is to run the following command:

wget -qO - https://github.com/kwindrem/SetupHelper/archive/current.tar.gz | tar -xzf - -C /data
mv /data/SetupHelper-current /data/SetupHelper

If not, do the following a computer that does have internet access
If the Venus device does not have internet access, you will need to fetch the archive using a computer that does have internet access:

click on this link in a web browser:
https://github.com/kwindrem/SetupHelper/archive/current.tar.gz
Expand All @@ -18,41 +27,132 @@ copy the venus-data.tar.gz to a USB stick,
put the stick in the Venus device and reboot.
When Venus boots, it will unarchive the file to /data/SetupHelper-current

Move the directory into it's active locaiton:
rm -rf /data/SetupHelper
mv /data/SetupHelper-current /data/SetupHelper

Then move rcS.local to /data, or edit that file if it already exists and add:
Finally, run the setup script to complete the installation
/data/SetupHelper/setup

Use the manual or automatic update mechnism for future updates

Description:

There are two parts to SetupHelper:
1) Install and update utilities help a user manage packages.

2) CommonResources helps in writing scripts to perform the installation.

The latter is of concern only to those writing new Venus modificaitons
or modifying an existing setup script.
These are described in detail later in the document.

SetupHelper package management:

The intent of this part of SetupHelper is to minimize the effort needed
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 enabled, automatic GitHub update checks will download and install the GitHub version
if it is newer than the current version.

One update check is made every 10 minutes, so it takes up to an hour check all packages.

If you are experimenting with modificaitons and wish to avoid GitHub updates overriding your work,
disable automatic updates.


USB updates are handy when the Venus device is not connected to the internet.

/data/SetupHelper/reinstallMods
To use the USB update process:
Navigate to the GitHub, repo, click on tags and select "current".
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.
Insert the stick in the Venus device.

You can alternatively use rc.local as explained below
Regardless the update source (USB or GitHub),
packageAutoUpdater replaces the current copy on the Venus device with the archive contents.
Then the package's setup script is run to reinstall the modificaitons.
No user interaction is needed in this process.

The following lines should be inclueded in the setup script to use the functions and variables provided here
A USB package update disables automatic GitHub updates to avoid conflicts.
(GitHub and files on a USB stick could have different timestamps.)

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 can be installed from eithera USB memory stick 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.

The method of putting an archive on a USB stick for manaul install is the same as the one for automatic updates.

As with package updates, GitHub is the desired source if your Venus device has an internet connection.

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



Setup script aids:

SetupHelper provides a number of functions and variables that simplfy scripts written to
install Venus OS mods. The remainder of this ReadMe describes the resources available and
how to incorporate them into a setup script.

Read on if you are intersting in writing a package setup script (or modifying an existing one)
or understanding how the mechanism works.

To use SetupHelper, the script must be written to include CommonResources,
then use the functions included in CommonResources to carry out the modiciations.

#### following lines incorporate SetupHelper utilities into this script
# Refer to the SetupHelper ReadMe file for details.

source "/data/SetupHelper/CommonResources"
source "/data/SetupHelper/CommonResources"

#### end of lines to include SetupHelper

A Venus software update overwrites any modifications to the root partition.
It is therefore necessary to reinstall the modifications following the Venus update.

For automatic reinstallation of any modificaitons using SetupHelper following a Venus update,
add the following line in /data/rcS.local or /data/rc.local to call the reinstaller:

/data/SetupHelper/reinstallMods
Running setup for any package using SetupHelper will install the necessary code to reinstall packages
during system boot

Typically, rcS.local is used because it runs prior to starting services
so conflicts with running services can be avoided
(services don't need to be restarted after they've been modified)
and if a reboot is required, it happens faster

If your setup script needs resources launched later in boot, use /data/rc.local
If your setup script needs resources launched later in boot, change the following line in CommonResources

rcLocal="/data/rcS.local"

to

rcLocal="/data/rc.local"

If you have already run any setup scripts and want to make this change, make sure to edit /data/rcS.local
to remove the call to reinstallMods or it will be called twice during boot!

reinstallScriptsList is a list of setup scripts, one per line that will be called from reinstallMods.
Scripts in this list are called EVERY time the system boots.
The script must avoid repeating work if it can be avoided.
SetupHelper tools (CommonResources) handles this for the script write.

reinstallScriptsList is hard-coded to reside in the /data directory.
The location must match in CommonResources, and in reinstallMods
Expand Down Expand Up @@ -219,8 +319,9 @@ fileList contains a list of Venus files to be managed by this package.
Packages may also contain files that do not exist in the stock Venus image.
These are NOT included in fileList!

The special file NOT_COMPATIBLE in a file set indicates the package is not compatible with this Venus version
CommonResources will prevent the package installation or force an uninstall if it already has been
obsoleteVersion is a file optionally contained in the package directory.
It indicates a Venus OS version at which the package is no longer compatible.
CommonResources prevents the package from being installed for the specified version and all those following it.

Use full paths/name for all files to avoid problems when running the script from other locations
such as the boot code, and quote them in case the names contain spaces.
Expand Down Expand Up @@ -302,4 +403,3 @@ LogHandler is a logging and log display mechanism. It is sourced by CommonResour
The latter must be initialized in setup script code
If no package log file exists, $packageLogFile shoudl remain null ""


161 changes: 161 additions & 0 deletions ServiceResources
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# ServiceManager for SetupHelper
# contains a functions to install, remove, start and stop a package's service

# managing a normal package's service is straight forward
#
# normally, services are connected via a symbolic link, but to avoid issues with
# updating package files, the service directory is COPIED to the /service directory instead.
#
# If the active copy of the service already exists, the run and log/run files are updated
# ONLY if there are changes. This leaves other files managed by supervise untouched.
#
# For all functions, $1 specifies the package name


# startService and stopService start and stop the service, respectively
# the 'down' flag is also cleared/set to control service runs in the future
# startService will cause the service to stop then start again !!!

startService ()
{
# no service to remove
if [ ! -e "/service/$pkg" ]; then
return
fi
# no package specified
if [ $# -lt 1 ]; then
return
fi

local pkg=$1

rm -f "/service/$pkg/down"
svc -t "/service/$pkg"
}


stopService ()
{
# no service to remove
if [ ! -e "/service/$pkg" ]; then
return
fi
# no package specified
if [ $# -lt 1 ]; then
return
fi

local pkg=$1

touch "/service/$pkg/down"
svc -d "/service/$pkg"
}

# killServiceProcesses makes sure there are no services
# internal function only !!!!
# must be called from other functions that have already made the necessary checks

_killServiceProcesses ()
{
local pkg=$1
ps -l | grep $pkg | grep -v -e grep -e $$ | awk '{print $3}' | xargs kill > /dev/null 2>&1
}

#
# removeService cleanly removes the service
#

_removeService ()
{
# stop the service
svc -d "/service/$pkg"

# remove the active service directory
rm -rf "/service/$pkg"

# kill related processes
_killServiceProcesses $pkg
}

removeService ()
{
# no service to remove
if [ ! -e "/service/$pkg" ]; then
return
fi
# no package specified
if [ $# -lt 1 ]; then
return
fi

local pkg=$1

logMessage "removing $pkg service"
_removeService $pkg
}


# installService adds the service to the /service directory or updates an existing one
#
# If the service does not yet exist, it will start immediately unless
# it includes the 'down' flag file. This behavior is up to the service writer.
#
# If the service already exists, installService will stop it,
# update the service files and stop all child processes
# Then restart the service unless the down flag is set
#

installService ()
{
# no service to install
if [ ! -e "$scriptDir/service" ]; then
return
fi
# no package specified
if [ $# -lt 1 ]; then
return
fi

local pkg=$1
local serviceRestartNeeded=false

if [ -L "/service/$pkg" ]; then
logMessage "$pkg removing old service (was symbolic link)"
_removeService $pkg
fi
# service not yet installed, COPY service directory to the active locaiton
if [ ! -e "/service/$pkg" ]; then
logMessage "$pkg installing service"
cp -R "$scriptDir/service" "/service/$pkg"
# service already installed - only copy changed files
else
if [ -f "$scriptDir/service/run" ]; then
cmp -s "$scriptDir/service/run" "/service/$pkg/run" > /dev/null
if [ $? != 0 ]; then
cp "$scriptDir/service/run" "/service/$pkg/run"
serviceRestartNeeded=true
fi
fi
if [ -f "$scriptDir/service/log/run" ]; then
cmp -s "$scriptDir/service/log/run" "/service/$pkg/log/run" > /dev/null
if [ $? != 0 ]; then
cp "$scriptDir/service/log/run" "/service/$pkg/log/run"
serviceRestartNeeded=true
fi
fi
if $serviceRestartNeeded ; then
logMessage "$pkg updated service - restarting"
# stop the service
svc -d "/service/$pkg"
# kill related processes
_killServiceProcesses $pkg
# bring service back up
if [ ! -f "/service/down" ]; then
svc -u "/service/$pkg"
fi
fi
fi
}



Loading

0 comments on commit b06151f

Please sign in to comment.