diff --git a/.DS_Store b/.DS_Store index 0f88285..dd03258 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/ReadMe b/ReadMe index 6baa703..a02cba4 100644 --- a/ReadMe +++ b/ReadMe @@ -1,5 +1,3 @@ -Caution: bugs found in automatic updater. Do not use for now - 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 diff --git a/ServiceResources b/ServiceResources index f39be20..007cb96 100755 --- a/ServiceResources +++ b/ServiceResources @@ -10,55 +10,74 @@ # ONLY if there are changes. This leaves other files managed by supervise untouched. # # For all functions, $1 specifies the package name +# +# functions that begin with _ skip checks and do not log activity + + +# _killServiceProcesses makes sure there are no service processes running +# The intent is to force supervise to run the new version +# must be called from other functions that have already made the necessary checks +_killServiceProcesses () +{ + local pkg=$1 + ps -lw | grep $pkg | grep -v -e grep -e $$ | awk '{print $3}' | xargs kill > /dev/null 2>&1 +} # 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 () +_startService () { - # no service to remove - if [ ! -e "/service/$pkg" ]; then - return + local pkg=$1 + rm -f "/service/$pkg/down" + svc -u "/service/$pkg" + if [ -e "/service/$pkg/log" ]; then + rm -f "/service/$pkg/log/down" + svc -u "/service/$pkg/log" fi +} + +startService () +{ # no package specified if [ $# -lt 1 ]; then return fi - local pkg=$1 - rm -f "/service/$pkg/down" - svc -t "/service/$pkg" + if [ -e "/service/$pkg" ]; then + logMessage "starting $pkg service" + _startService $pkg + fi } -stopService () +_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" + if [ -e "/service/$pkg/log" ]; then + touch "/service/$pkg/log/down" + svc -d "/service/$pkg/log" + fi + _killServiceProcesses $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 () +stopService () { + # no package specified + if [ $# -lt 1 ]; then + return + fi local pkg=$1 - ps -l | grep $pkg | grep -v -e grep -e $$ | awk '{print $3}' | xargs kill > /dev/null 2>&1 + + if [ -e "/service/$pkg" ]; then + logMessage "stopping $pkg service" + _stopService $pkg + fi } # @@ -67,6 +86,7 @@ _killServiceProcesses () _removeService () { + local pkg=$1 # stop the service svc -d "/service/$pkg" @@ -79,19 +99,16 @@ _removeService () 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 + if [ -e "/service/$pkg" ]; then + logMessage "removing $pkg service" + _removeService $pkg + fi } @@ -107,14 +124,14 @@ removeService () installService () { - # no service to install - if [ ! -e "$scriptDir/service" ]; then - return - fi # no package specified if [ $# -lt 1 ]; then return fi + # no service to install + if [ ! -e "$scriptDir/service" ]; then + return + fi local pkg=$1 local serviceRestartNeeded=false @@ -127,33 +144,22 @@ installService () if [ ! -e "/service/$pkg" ]; then logMessage "$pkg installing service" cp -R "$scriptDir/service" "/service/$pkg" - # service already installed - only copy changed files + # service already installed - only copy changed files, then restart service else + logMessage "restarting $pkg service" 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 + _killServiceProcesses $pkg fi } diff --git a/UpdateResources b/UpdateResources index 319f1c9..794a0ea 100755 --- a/UpdateResources +++ b/UpdateResources @@ -28,18 +28,20 @@ getFromUsb () local archiveTimeStamp="" local lastUpdate="" - # archive found on USB stick - process it - if [ -f "$packageArchive" ]; then - tar -xzf "$packageArchive" -C /data - if [ ! -d "$packageDir-$gitHubBranch" ]; then - logMessage "ERROR: $packageArchive did not contain $package" - return 0 - fi + # no archive found on USB stick - process it + if [ ! -f "$packageArchive" ]; then + return 0 + fi + + tar -xzf "$packageArchive" -C /data + if [ ! -d "$packageDir-$gitHubBranch" ]; then + logMessage "ERROR: $packageArchive did not contain $package" + return 0 fi # get the timeStamp from local copy of package if [ -f "$packageDir/timeStamp" ]; then - lastUpdate=$(cat "$packageDir/gitHubTimeStamp") + lastUpdate=$(cat "$packageDir/timeStamp") else lastUpdate="" fi @@ -108,12 +110,13 @@ getFromGitHub () # install the archive and run setup script # -# $1 is the flag to allow running the script with user interaction +# $1 is the package name +# $2 is the flag to allow running the script with user interaction doUpdate () { - local pkgService="/service/$package" - local pkgServiceDir="$packageDir/service" + local package=$1 + local packageDir="/data/$package" if [ $# > 0 ] && [ $1 == 'prompting' ]; then installOk=true diff --git a/packageAutoUpdater b/packageAutoUpdater index f8adc71..a304cc0 100755 --- a/packageAutoUpdater +++ b/packageAutoUpdater @@ -13,7 +13,7 @@ # get the full, unambiguous path to this script scriptDir="$( cd "$(dirname $0)" >/dev/null 2>&1 ; /bin/pwd -P )" -packageName=$(basename "$scriptDir") +packageame=$(basename "$scriptDir") shortScriptName=$(basename "$scriptDir")/$(basename "$0") source "/data/SetupHelper/LogHandler" diff --git a/packageInstaller b/packageInstaller index a48f268..8bf6df1 100755 --- a/packageInstaller +++ b/packageInstaller @@ -114,7 +114,7 @@ for package in $allPackages; do updateSetupHelper=true # update the package with user interaction if it is needed to do a full install (not reinstall) else - doUpdate 'propmting' + doUpdate $package 'propmting' fi else rm -rf "$packageDir-$gitHubBranch" @@ -125,7 +125,7 @@ done # this prevents stepping on SetupHelper resources # (this script will complete even if it's replaced) if $updateSetupHelper ; then - doUpdate "SetupHelper" + doUpdate "SetupHelper" 'propmting' fi if $rebootNeeded ; then echo diff --git a/setup b/setup index edf508e..70fefb0 100755 --- a/setup +++ b/setup @@ -46,6 +46,7 @@ if [ $scriptAction == 'NONE' ] ; then 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 @@ -72,7 +73,23 @@ if [ $scriptAction == 'NONE' ] ; then [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 @@ -86,7 +103,7 @@ if [ $scriptAction == 'NONE' ] ; then fi if [ $scriptAction == 'INSTALL' ] ; then -# installService $packageName + installService $packageName fi if [ $scriptAction == 'UNINSTALL' ] ; then diff --git a/timeStamp b/timeStamp index 0ed4d3a..1b10da4 100644 --- a/timeStamp +++ b/timeStamp @@ -1 +1 @@ -1623570682 +1623607950