Skip to content

Commit

Permalink
fixed bugs in auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed Jun 13, 2021
1 parent 83bd5b3 commit 5b55961
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 68 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions ReadMe
Original file line number Diff line number Diff line change
@@ -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
Expand Down
104 changes: 55 additions & 49 deletions ServiceResources
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

#
Expand All @@ -67,6 +86,7 @@ _killServiceProcesses ()

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

Expand All @@ -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
}


Expand All @@ -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
Expand All @@ -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
}

Expand Down
25 changes: 14 additions & 11 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packageInstaller
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -86,7 +103,7 @@ if [ $scriptAction == 'NONE' ] ; then
fi

if [ $scriptAction == 'INSTALL' ] ; then
# installService $packageName
installService $packageName
fi

if [ $scriptAction == 'UNINSTALL' ] ; then
Expand Down
2 changes: 1 addition & 1 deletion timeStamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1623570682
1623607950

0 comments on commit 5b55961

Please sign in to comment.