diff --git a/FileSets/PatchSource/PageSettingsGeneral.qml b/FileSets/PatchSource/PageSettingsGeneral.qml index 4e1ddcf..1021cc7 100644 --- a/FileSets/PatchSource/PageSettingsGeneral.qml +++ b/FileSets/PatchSource/PageSettingsGeneral.qml @@ -89,14 +89,15 @@ MbPage vePlatform.reboot() } } + //////// add for Shutdown command - MbSubMenu - { - description: qsTr("Shutdown") - subpage: Component { PageSettingsShutdown {} } + MbSubMenu + { + description: qsTr("Shutdown") + subpage: Component { PageSettingsShutdown {} } property VBusItem shutdownItem: VBusItem { bind: Utils.path("com.victronenergy.shutdown", "/Shutdown") } - show: shutdownItem.valid - } + show: shutdownItem.valid + } MbSwitch { property VBusItem hasBuzzer: VBusItem {bind: "com.victronenergy.system/Buzzer/State"} @@ -105,6 +106,12 @@ MbPage show: hasBuzzer.valid } + MbSwitch { + name: qsTr("Enable status LEDs") + bind: Utils.path(bindPrefix, "/Settings/LEDs/Enable") + show: item.valid + } + MbItemOptions { id: demoOnOff description: qsTr("Demo mode") diff --git a/FileSets/PatchSource/PageSettingsGeneral.qml.orig b/FileSets/PatchSource/PageSettingsGeneral.qml.orig index a7f9a74..37ff69c 100644 --- a/FileSets/PatchSource/PageSettingsGeneral.qml.orig +++ b/FileSets/PatchSource/PageSettingsGeneral.qml.orig @@ -97,6 +97,12 @@ MbPage show: hasBuzzer.valid } + MbSwitch { + name: qsTr("Enable status LEDs") + bind: Utils.path(bindPrefix, "/Settings/LEDs/Enable") + show: item.valid + } + MbItemOptions { id: demoOnOff description: qsTr("Demo mode") diff --git a/FileSets/PatchSource/PageSettingsGeneral.qml.patch b/FileSets/PatchSource/PageSettingsGeneral.qml.patch index a2cbbb5..362a0ea 100644 --- a/FileSets/PatchSource/PageSettingsGeneral.qml.patch +++ b/FileSets/PatchSource/PageSettingsGeneral.qml.patch @@ -1,17 +1,18 @@ ---- /Users/Kevin/GitHub/ShutdownMonitor.copy/FileSets/PatchSource/PageSettingsGeneral.qml.orig 2024-03-22 19:53:04 -+++ /Users/Kevin/GitHub/ShutdownMonitor.copy/FileSets/PatchSource/PageSettingsGeneral.qml 2024-03-22 19:48:02 -@@ -89,6 +89,14 @@ - vePlatform.reboot() +--- /Users/Kevin/GitHub/ShutdownMonitor.copy/FileSets/PatchSource/PageSettingsGeneral.qml.orig 2024-04-22 04:01:13 ++++ /Users/Kevin/GitHub/ShutdownMonitor.copy/FileSets/PatchSource/PageSettingsGeneral.qml 2024-05-02 17:23:48 +@@ -90,6 +90,15 @@ } } + +//////// add for Shutdown command -+ MbSubMenu -+ { -+ description: qsTr("Shutdown") -+ subpage: Component { PageSettingsShutdown {} } ++ MbSubMenu ++ { ++ description: qsTr("Shutdown") ++ subpage: Component { PageSettingsShutdown {} } + property VBusItem shutdownItem: VBusItem { bind: Utils.path("com.victronenergy.shutdown", "/Shutdown") } -+ show: shutdownItem.valid -+ } - ++ show: shutdownItem.valid ++ } ++ MbSwitch { property VBusItem hasBuzzer: VBusItem {bind: "com.victronenergy.system/Buzzer/State"} + name: qsTr("Audible alarm") diff --git a/HelperResources/CommonResources b/HelperResources/CommonResources deleted file mode 100755 index 4815e64..0000000 --- a/HelperResources/CommonResources +++ /dev/null @@ -1,1606 +0,0 @@ -#!/bin/bash - - -# CommonResources for SetupHelper -# contains a functions and variables necessary for a setup script to interface with reinstallMods -#patch file missing for -# Refer to the SetupHelper ReadMe file for details on how to use these resources. - -# what action the script should take: -# NONE - do noting - signals script to prompt for user input on how to proceed -# INSTALL - install package components -# (decommissioned) PROMPT - prompt user for additional installation options -# UNINSTALL - remove package components -# EXIT - exit script without taking any action -# CHECK - runs file set checks only -# this will attempt to create a missing file set so PackageManager -# won't report it missing -# CommonResources may set the the action if initial checks -# indicate a clear direction -# otherwise, the action will be set based on user input (in the script) -# if failures occur during installation, -# scriptAction should be changed to UNINSTALL so the installation can be cleaned up -# and the setup script should test for UNINSTALL after it attempts installation -# A file set error indicates the file set for the current verion is not usable -# and installation should not occur -# checkFileSets EXITS locally - -scriptAction='NONE' - -# flags to control setup script behavior (in endScript) -rebootNeeded=false -runAgain=false -filesUpdated=false -restartGui=false -restartGenerator=false -restartSystemCalc=false -restartDigitalinputs=false - - -# file lists are populated by getFileLists called from_chckFileSets and autoinstall -# so these are global -fileList=() -fileListVersionIndependent=() -fileListAll=() - - -######## skip to bottom of file for remainder of code executed when script is sourced - - -# setInstallFailed sets flags to prevent further install steps -# and insure the package is uninstalled completely -# -# $1 indicates the reason for the failure and will evenutally be uused -# report the failure reason when exiting the script -# -# any remaining paremeters are passed to logMessage -# and also saved in installFailMessage for others to use -# the message is also sent to stderr if not running from the command line -# this allows PackageManager to report the full reason for failure -# -# a setup script can be run from the console, or from another script or program (unattended) -# when running from the console -# setInstallFailed will report errors and return to the caller -# -# if running unattended and if the script action is INSTALL -# during the precheck period (before any system modification) -# setInstallFailed WILL EXIT WITHOUT RETURNING TO THE CALLER !!!!! -# after the precheck period, system modifications may have been made so -# the scriptAction is changed to UNINSTALL -# so the modifictions can be reversed -# otherwise, setInstallFailed just logs the error -# -# note that PackageManager makes most of the pre-check tests -# before calling the setup script -# the only exception is file set checks made in checkFileSets - -installFailed=false -installExitReason=$EXIT_ERROR -installFailMessage="" -installPreChecks=true -installFailCount=0 - -# cleanup on any exit - -exitCleanup () -{ - # remove temp directory - rm -rf "$patchedFiles" -} - -trap exitCleanup EXIT - -setInstallFailed () -{ - (( installFailCount += 1 )) - installFailed=true - if [ ! -z "$1" ]; then - installExitReason=$1 - # no reson specified - use the generaic error exit code - else - installExitReason=EXIT_ERROR - fi - message="${@:2}" - if [ ! -z "$message" ]; then - installFailMessage="$message" - logMessage "ERROR: $message" - # if not running from console, output error to stderr - if ! $logToConsole ; then - echo "$message" >&2 - fi - else - installFailMessage="" - fi - - if ! $userInteraction && [ $scriptAction == 'INSTALL' ]; then - # during "pre-checks" failures occur before any system mofifications - - # EXIT NOW - DO NOT RETURN TO THE CALLER !!!!! - if $installPreChecks ; then - exit $installExitReason - # after "pre-checks" system mofifications may already have occured - # so an uninstall needs to follow the install - else - scriptAction='UNINSTALL' - fi - fi -} - - - -# checkPackageDependencies checks the packageDependencies file in the package directory -# -# all unmet dependencies are reported to the command line/log -# and to stderr if not running from the command line -# then the script exists - -function checkPackageDependencies () -{ - dependencyFile="$scriptDir/packageDependencies" - - #no dependencies specified for this package - if ! [ -f "$dependencyFile" ]; then return; fi - - errors="" - while IFS= read -r line; do - error="" - read package requirement <<< "$line" - if [ -f "$installedVersionPrefix"$package ]; then - packageInstalled=true - else - packageInstalled=false - fi - case $requirement in - installed) - if ! $packageInstalled ; then - error="$package must be installed" - fi - ;; - uninstalled) - if $packageInstalled ; then - error="$package must be uninstalled" - fi - ;; - esac - if ! [ -z "$error" ]; then - if ! [ -z "$errors" ]; then - errors+=", " - fi - errors+="$error" - fi - - done < "$dependencyFile" - if ! [ -z "$errors" ]; then - setInstallFailed $EXIT_PACKAGE_CONFLICT "$errors" - fi -} - -# getFileLists reads the file list from files in the FileSets directory -# -# 'fileList' file must only list version-dependent files -# 'fileListVersionIndependent' file must list only version-independent files -# prior to SetupHelper v6.0, this list is ignored -# 'fileListPatched' lists all files that should be patched before installation -# -# $1 specifies where the path to the fileList files -# -# three composite file lists are returned in global arrays: -# fileList contains only version-dependent files -# fileListVersionIndependent contains only version-independent files -# fileListPatched contains only files that need to be patched -# fileListAll contains both versioned and version-independent files - -function getFileLists () -{ - local verListFile="$1/fileList" - local indListFile="$1/fileListVersionIndependent" - local patchListFile="$1/fileListPatched" - local tempListVer=() - local tempListInd=() - local tempListPatched=() - - if [ -f "$verListFile" ]; then - while read -r line || [[ -n "$line" ]]; do - read -a params <<< $line - # parse line into space-separted parameters then discard any that don't begin with / - # this strips all comments beginning with # as well as any leading or trailing spaces - for param in ${params[@]} ; do - case $param in - /*) - tempListVer+=("$param") - ;; - esac - done - done < "$verListFile" - fi - if [ -f "$indListFile" ]; then - while read -r line || [[ -n "$line" ]]; do - read -a params <<< $line - for param in ${params[@]} ; do - case $param in - /*) - tempListInd+=("$param") - ;; - esac - done - done < "$indListFile" - fi - if [ -f "$patchListFile" ]; then - while read -r line || [[ -n "$line" ]]; do - read -a params <<< $line - for param in ${params[@]} ; do - case $param in - /*) - tempListPatched+=("$param") - ;; - esac - done - done < "$patchListFile" - fi - - # remove duplicate files from each list - fileList=($(printf "%s\n" "${tempListVer[@]}" | sort -u)) - fileListVersionIndependent=($(printf "%s\n" "${tempListInd[@]}" | sort -u)) - fileListPatched=($(printf "%s\n" "${tempListPatched[@]}" | sort -u)) - tempListAll=(${fileList[@]}) - tempListAll+=(${fileListVersionIndependent[@]}) - tempListAll+=(${fileListPatched[@]}) - fileListAll=($(printf "%s\n" "${tempListAll[@]}" | sort -u)) -} - - -# yesNoPrompt provides user prompting requesting a yes/no response -# -# $1 is the prompt displayed when pausing for user input -# -# $yesResponse is set to true if the response was yes -# -# returns 0 for yes, 1 for no - -yesNoPrompt () -{ - response='' - while true; do - /bin/echo -n "$*" - read response - case $response in - [yY]*) - yesResponse=true - return 0 - break - ;; - [nN]*) - yesResponse=false - return 1 - break - ;; - *) - esac - done -} - - -# standardActionPrompt provides the standard set of options for selecting script's action -# scriptAction is set by install/uninstall -# other actions are handled locally, including quitting from the script -# -# if nonstandard prompts are necessary, duplicate this code in the setup script -# and add the additional options and do not call standardActionPrompt -# -# the reinstall option is permitted only if setup options were previously set -# if the the reinstall action is choosen, the script action is set to INSTALL -# the setup script can then test this to skip further prompts -# -# $1 indicates if there are additional prompts needed during installaiton -# if this parameter is 'MORE_PROMPTS', installaiton does NOT change scriptAction -# if this parameter does not exist, installation WILL change scriptAction to INSTALL -# this provides backaward compatibility with scripts written prior to the reinstall logic -# -standardActionPrompt () -{ - if [ $# -gt 0 ] && [ $1 == 'MORE_PROMPTS' ]; then - updateScriptAction=false - else - updateScriptAction=true - fi - - echo - echo "Available actions:" - # don't allow install choice if incompatibilities have already been detected - if ! $installFailed ; then - echo " Install and activate (i)" - else - echo " can't install - errors reported above" - fi - if $optionsSet ; then - echo " Reinstall (r) based on options provided at last install" - fi - echo " Uninstall (u) and restores all files to stock" - echo " Quit (q) without further action" - echo " Display setup log (s) outputs the last 100 lines of the log" - if [ ! -z "$packageLogFile" ]; then - echo " Display Log (l) outputs the last 100 lines of the log" - fi - echo - response='' - while true; do - /bin/echo -n "Choose an action from the list above: " - read response - case $response in - [iI]*) - if ! $installFailed ; then - if $updateScriptAction ; then - scriptAction='INSTALL' - fi - break - fi - ;; - [rR]*) - if $optionsSet ; then - scriptAction='INSTALL' - break - fi - ;; - [uU]*) - scriptAction='UNINSTALL' - break - ;; - [qQ]*) - exit $EXIT_SUCCESS - ;; - [lL]*) - displayLog $packageLogFile - ;; - [sS]*) - displayLog $setupLogFile - ;; - *) - esac - done -} - - -# forcePackageUninstall insures a conflicting package is uninstalled before -# this package is installed -# the setup script must call this script BEFORE it begins installing anything -# $1 is the package name -# $2 contains an optional message - -forcePackageUninstall () -{ - if (( $# < 1 )); then - return - fi - if [ -f "$installedVersionPrefix""$1" ]; then - if (( $# >= 2 )); then - logMessage "${@:2}" - else - logMessage "uninstalling $1 - it conflicts with $packageName" - fi - if [ -e "/data/$1/setup" ]; then - "/data/$1/setup" "uninstall" "auto" "deferReboot" "deferGuiRestart" - else - logMessage "WARNING can't uninstall $1 - no package directory or no setup script" - fi - if [ -e "/data/settupOptions/$1" ]; then - touch "/data/settupOptions/$1/DO_NOT_AUTO_INSTALL" - fi - fi -} - - -# backupActiveFile makes a copy of the active file in file.orig -# if the original file does not exist the NO_ORIG flag is set -# to allow restoreAcive file to remove the active file -# -# if the backup (.orig file) exists the backup is not ukpdated -# -# $1 is the full path/file name to be backed up -# -# returns 0 if backup was made, 1 if not -# - -backupActiveFile () -{ - # don't do any work if install has already failed - if $installFailed ; then - return 1 - fi - - baseName=$(basename $1) - if [ -e "$1.orig" ] || [ -e "$1.NO_ORIG" ]; then - return 1 - elif [ ! -f "$1" ]; then - touch "$1.NO_ORIG" - return 0 - else - cp "$1" "$1.orig" - rm -f "$1.NO_ORIG" - return 0 - fi -} - - -# SetupHelper maintains a set of "restart flags" -# that control service restarts and system reboot -# after the package has been installed / uninstalled -# -# some restarts/reboots are based on the directory of the modified file -# others are based on the actual file itself -# -# not all services or specific files are flagged so some work in the setup script may be needed -# -# $1 is the full path and name to the modified file - -updateRestartFlags () -{ - # flag indicating any file update occurred - filesUpdated=true - - case $1 in - /opt/victronenergy/gui*) - restartGui=true - return;; - #### TODO: add gui-v2 - /opt/victronenergy/dbus-generator-starter/*) - restartGeneratorService=true - return;; - /opt/victronenergy/dbus-systemcalc-py/*) - restartSystemCalc=true - return;; - /opt/victronenergy/dbus-digitalinputs/*) - restartDigitalinputs=true - return;; - - /u-boot/overlay./*) # Raspberry PI DT overlay - rebootNeeded=true - return;; - /etc/udev/rules.d/*) # udev rules directory - rebootNeeded=true - return;; - esac - - # reboots based on specific file - case $( basename $1 ) in - gpio_list) - rebootNeeded=true - return;; - config.txt) - rebootNeeded=true - return;; - esac -} - - -# updateActiveFile first backs up the active file -# then copies the replacement (aka source) to the active file location (aka destination) -# -# two variations: -# -# updateActiveFile activeFile -# an attempt is made to locate the source (replacement) -# in the version directory or FileSets -# -# updateActiveFile sourceFile activeFile -# a separate source (replacement) file is specified -# -# both sourceFile and activeFile must be a full path to the file -# -# if the update fails, scriptAction is changed to UNINSTALL -# -# global thisFileUpdated is set to true if file was updated, false if not -# thisFileUpdated supports the old mechanism which may be used in some setup scripts -# returns 0 if file was updated, 1 if not - - -updateActiveFile () -{ - thisFileUpdated=false - - # don't do any work if install has already failed - if $installFailed ; then - return 1 - fi - - # separate source and replacement files specified - local sourceFile="" - local activeFile="" - local prevousPackage="" - if [ $# == 2 ]; then - if [ -f "$1" ]; then - sourceFile="$1" - else - setInstallFailed $EXIT_FILE_SET_ERROR "specified soure file "$1" does not exist" - return 1 - fi - activeFile="$2" - # use active file for both source and destination - else - activeFile="$1" - fi - - local baseName=$(basename "$activeFile") - - # replacement files are not needed for some versions - # if so marked, leave original untouched - if [ -f "$fileSet/$baseName.USE_ORIGINAL" ]; then - return 1 - # source file not specified separately - look for it in expected places - elif [ -z "$sourceFile" ]; then - # first in patched files - if [ -f "$patchedFiles/$baseName" ]; then - sourceFile="$patchedFiles/$baseName" - # then in version-specific FileSet - elif [ -f "$fileSet/$baseName" ]; then - sourceFile="$fileSet/$baseName" - # then in version-independent file set - elif [ -f "$versionIndependentFileSet/$baseName" ]; then - sourceFile="$versionIndependentFileSet/$baseName" - # then in FileSets - elif [ -f "$pkgFileSets/$baseName" ]; then - sourceFile="$pkgFileSets/$baseName" - # nothing found - can't continue - else - setInstallFailed $EXIT_FILE_SET_ERROR "no soure file for $baseName" - return 1 - fi - fi - - local pathToFile=$(dirname "$activeFile") - if [ ! -e "$pathToFile" ]; then - # fatal if GUI v1 not present and needed for install - if [[ "$pathToFile" == "/opt/victronenergy/gui/"* ]]; then - if $guiV1required ; then - setInstallFailed $EXIT_NO_GUI_V1 "$packageName requires GUI v1" - # GUI v1 not needed - proceed without updating active file - fi - # active file is not in GUI v1 part of file system - so this is fatal - else - setInstallFailed $EXIT_FILE_SET_ERROR "path to $activeFile does not exist" - fi - return 1 - fi - - # check for package conflicts - if [ -f "$activeFile.package" ]; then - prevousPackage=$( cat "$activeFile.package" ) - if [ $packageName != $prevousPackage ]; then - setInstallFailed $EXIT_PACKAGE_CONFLICT "$(basename $activeFile) was already modfied by $prevousPackage" - return 1 - fi - fi - - # add file to installed files list (used for uninstallAll) - # do this before actually modifying things just in case there's an error - # that way the uninstall is assured - echo "$activeFile" >> "$installedFilesList" - - # update package flag to prevent overwrites by other packages - echo $packageName > "$activeFile.package" - - # already updated - don't need to any more - if [ -f "$activeFile" ]; then - if cmp -s "$sourceFile" "$activeFile" > /dev/null ; then - return 1 - fi - fi - - backupActiveFile "$activeFile" - - # update the active file - cp "$sourceFile" "$activeFile" - - updateRestartFlags "$activeFile" - thisFileUpdated=true - return 0 -} - - -# restoreActiveFile moves the backup copy to the active location -# if the backup copy doesn't exist BUT the NO_ORIG flag is set -# the active copy is deleted to restore the system to stock -# $1 is the active name, the one to be backed up -# -# returns 0 if active file was restored, 1 if not -# also sets thisFileUpdated for backwards compatibility with existing setup scripts -# -# restore only if the package that updated this file is the current package -# failure is indicated in the return code but does not trigger as faliure - -restoreActiveFile () -{ - thisFileUpdated=false - - if [ -f "$1.package" ]; then - prevousPackage=$( cat "$1.package" ) - if [ $packageName != $prevousPackage ]; then - return 1 - fi - fi - if [ -e "$1.orig" ]; then - mv -f "$1.orig" "$1" - thisFileUpdated=true - elif [ -f "$1.NO_ORIG" ]; then - rm -f "$1" - thisFileUpdated=true - fi - - if $thisFileUpdated ; then - rm -f "$1.NO_ORIG" - rm -f "$1.package" - # remove file from installed file list - if [ -f "$installedFilesList" ]; then - grep -v "$1" "$installedFilesList" | tee "$installedFilesList" > /dev/null - fi - updateRestartFlags "$1" - return 0 - else - return 1 - fi -} - - -# checkFileSets validates the file sets used to install package modifications -# -# If a file set for the current Venus OS version exists, the replacement files in that file set -# are usable as is and no further checks are needed. -# The COMPLETE flag file indicates that the file set was validated on the computer creating -# the file sets and all replacement files (or symlinks to other file sets) exist. -# No checks are needed for a COMPLETE file set. -# If not, an attempt is made to create a file set for the current Venus OS version -# If the new active files for the new version all match another version -# the new file set is populated automatically with replacement files from the other version -# and may be used with no further action -# If not, new file set is marked INCOMPLETE and installation failure information is set -# The package can not be installed on this Venus OS version -# -# Replacement files that have no original specify an "alternate original" that is used -# for version comparisons that locate an appropriate replacement - -checkFileSets () -{ - # no file sets - nothing to check - if ! [ -e "$pkgFileSets" ]; then return; fi - - # no checks needed if all replacement files exist in the selected file set - if [ -f "$fileSet/COMPLETE" ]; then return; fi - - # sort versionList in reverse version order to make searches faster - # since newer versions will most likely contain the desired files to create a new file set - local rawVersionList=($(ls -d "$pkgFileSets"/v* 2> /dev/null)) - local tempList=() - local fs - local baseName - local version - local versionNumber - for fs in ${rawVersionList[@]} ; do - version=$(basename $fs) - versionStringToNumber $version - tempList+=("$version:$versionNumber") - done - local versionList=( $(echo ${tempList[@]} | tr ' ' '\n' | sort -t ':' -r -n -k 2 | uniq ) ) - - # versioned file sets exist but empty file list - if [ ! -z "$versionList" ] && [ -z "$fileList" ]; then - setInstallFailed $EXIT_FILE_SET_ERROR "empty file list" - touch "$fileSet/INCOMPLETE" - rm -f "$fileSet/COMPLETE" - return - # no versioned file sets - nothing to validate - allow install - elif [ -z "$versionList" ]; then return; fi - - # attempt to create a new file set or validate an existing one not marked as COMPLETE - - rm -f "$fileSet/INCOMPLETE" - - # attempt to create file set if it doesn't exist - if [ ! -d "$fileSet" ]; then - logMessage "creating a new file set for $venusVersion" - mkdir "$fileSet" - fi - - for file in ${fileList[@]} ; do - baseName=$(basename "$file") - - # version-independent file exists - if [ -e "$versionIndependentFileSet/$baseName" ] || [ -e "$pkgFileSets/$baseName" ]; then - # no versioned files (only version-independent found) - skip version checks - if [ -z $( find "$fileSet"/v* -name $baseName ) ]; then - continue - # continue with tests if any versioned files exist - else - logMessage "WARNING $baseName versioned file exists - version-independent file will be ignored" - fi - fi - - # skip checks if replacement file already exists - # or if there is no replacement file needed - if [ -f "$fileSet/$baseName" ] || [ -f "$fileSet/$baseName.USE_ORIGINAL" ]; then - rm -f "$fileSet/$baseName.NO_REPLACEMENT" - continue - fi - - local activeFile - if [ -f "$altOrigFileDir/$baseName.ALT_ORIG" ]; then - activeFile=$(cat "$altOrigFileDir/$baseName.ALT_ORIG") - elif [ -f "$pkgFileSets/$baseName.ALT_ORIG" ]; then - activeFile=$(cat "$pkgFileSets/$baseName.ALT_ORIG") - else - activeFile=$file - fi - # package already installed, use .orig file for comparisons - if [ -f "$activeFile.orig" ]; then - activeFile="$activeFile.orig" - fi - - # can't process if no original (aka active) file exists in the file set - if [ ! -f "$activeFile" ]; then - logMessage "ERROR $venusVersion $baseName no active file" - touch "$fileSet/$baseName.NO_ACTIVE_FILE" - touch "$fileSet/INCOMPLETE" - continue - fi - - # if an active file exists look for a match in another file set - if [ ! -z "$activeFile" ]; then - matchFound=false - for entry in ${versionList[@]}; do - otherVersion=$(echo $entry | awk -F ':' '{print $1}') - - # skip this version - if [ "$venusVersion" = "$otherVersion" ]; then - continue - fi - - otherFile="$pkgFileSets/$otherVersion/$baseName" - - # skip symbolic links and nonexistent originals - if [ ! -f "$otherFile.orig" ] || [ -L "$otherFile.orig" ] ; then - continue - fi - - # files match - if cmp -s "$activeFile" "$otherFile.orig" > /dev/null ; then - matchFound=true - break - fi - done - - if $matchFound ;then - rm -f "$fileSet/$baseName.orig" - rm -f "$fileSet/$baseName.NO_ORIG" - # if other file set contains a replacement file, link to it - if [ -f "$otherFile" ]; then - rm -f "$fileSet/$baseName" - ln -s "../$otherVersion/$baseName" "$fileSet/$baseName" - rm -f "$fileSet/$baseName.NO_REPLACEMENT" - rm -f "$fileSet/$baseName.USE_ORIGINAL" - # if other file set does not contain a replacement, this one will not either - # this IS permitted and handled in the updateActiveFile and restoreActiveFile functions - elif [ -f "$otherFile.USE_ORIGINAL" ]; then - touch "$fileSet/$baseName.USE_ORIGINAL" - rm -f "$fileSet/$baseName.NO_REPLACEMENT" - fi - # no match to a previous verison - can't create file set automatically - # but copy original file to aid manual editing - else - logMessage "ERROR $venusVersion $baseName no replacement file" - cp "$activeFile" "$fileSet/$baseName.orig" - touch "$fileSet/$baseName.NO_REPLACEMENT" - touch "$fileSet/INCOMPLETE" - fi - fi - done - - if [ -f "$fileSet/INCOMPLETE" ]; then - setInstallFailed $EXIT_FILE_SET_ERROR "incomplete file set for $venusVersion" - # if we get this far and fs is not marked INCOMPLETE, then the file set does not need to be checked again next pass - else - touch "$fileSet/COMPLETE" - fi -} - -# builds the installedFilesList and installedServices lists from the package's setup script -# this is needed for installs with a prior version of SetupHelper that did not -# create the installed... lists -# -# uninstall... functions then use these lists to uninstall - -buildUninstallListsfromSetupScript () -{ - # prevent this from running a second time - if [ "$uninstallListsAlreadyBuilt" == 'yes' ]; then - return - fi - uninstallListsAlreadyBuilt='yes' - local param - - scriptUninstallFilesList=() - scriptUninstallServicesList=() - while read -r line || [[ -n "$line" ]]; do - commandFound=false - read -a params <<< $line - numberOfParams=${#params} - for (( i=0; i < $numberOfParams; i++ ));do - case "${params[i]}" in - updateActiveFile) - # parameter of intrest is the second one if it exists - # otherwise, it should be the first one - param=${params[i+2]} - if [ -z "$param" ] || [[ $param == \#* ]]; then - param=$( echo ${params[i+1]} | sed s?'$qmlDir'?$qmlDir? ) - fi - if ! [ -z "$param" ] && ! [[ $param == \#* ]]; then - # remove any quotes around parameters - param=$( echo $param | sed -e 's?"?? g' -e "s?'?? g" ) - scriptUninstallFilesList+=("$param") - fi - ;; - installService) - # parameter of intrest is the first one if it exists - # otherwise, is the packageName - param=${params[i+1]} - if ! [ -z "$param" ] && ! [[ $param == \#* ]]; then - scriptUninstallServicesList+=("$param") - else - # remove any quotes around parameters - param=$( echo $param | sed -e 's?"?? g' -e "s?'?? g" ) - scriptUninstallServicesList+=($packageName) - fi - ;; - esac - done - done < "$scriptDir/setup" -} - -# install / uninstall all files / services functions -# -# the install... functions are called from endScript if the related flags are set -# but may also be called in the setup script -# if processing needs to be done after the files are installed -# -# NOTE: uninstall functions are called in endScrpit during an uninstall -# there are no flags to control this ! -# -# NOTE: only services in the package's serice directory are installed -# any services in the package's root diretory are not installed - - -installAllFiles () -{ - if [ -z "$fileListAll" ]; then - getFileLists "$pkgFileSets" - fi - - if [ ! -z "$fileListAll" ]; then - logMessage "installing files" - local file - for file in ${fileListAll[@]}; do - updateActiveFile "$file" - done - fi -} - -# uninstall files from -# installed files list if present -# and from file lists in the package -# and from updateActiveFile calls found in the setup script -# this insures complete uninstall even for packages installed -# with SetupHelper prior to v6.0 - -uninstallAllFiles () -{ - local restoreFilesList=() - # add installdeFilesList if present (might be empty but that's fine) - if [ -f "$installedFilesList" ]; then - restoreFilesList=( $( cat "$installedFilesList" ) ) - fi - # add file lists & calls to installActiveFile in setup script - restoreFilesList+=( ${fileListAll[@]} ) - buildUninstallListsfromSetupScript - restoreFilesList+=( ${scriptUninstallFilesList[@]} ) - - # remove duplicates - if (( ${#restoreFilesList[@]} > 1 )); then - restoreFilesList=( $(printf "%s\n" "${restoreFilesList[@]}" | sort -u ) ) - fi - - # uninstall the files - if [ ! -z "$restoreFilesList" ]; then - logMessage "uninstalling files" - local file - for file in ${restoreFilesList[@]}; do - restoreActiveFile $file - done - fi -} - - -installAllServices () -{ - local serviceList - local service - # get list of services in the package's service directory - if [ -d "$servicesDir" ]; then - servicesList=$( cd "$servicesDir"; ls -d * 2> /dev/null ) - if [ ! -z "$servicesList" ]; then - logMessage "installing services" - for service in $servicesList ; do - installService $service - done - fi - fi -} - - -# uninstal services found in the services directory -# and restoreServices call in the package's setup script - -uninstallAllServices () -{ - local tempList=() - local servicesList=() - local service - - if [ -f "$installedServicesList" ]; then - servicesList=( $( cat "$installedServicesList" ) ) - fi - # add list from the setup script itself - buildUninstallListsfromSetupScript - servicesList+=( ${scriptUninstallServicesList[@]} ) - - # remove duplicates - if (( ${#servicesList[@]} > 1 )); then - servicesList=( $(printf "%s\n" "${servicesList[@]}" | sort -u ) ) - fi - - # uninstall services - if [ ! -z "$servicesList" ]; then - logMessage "uninstalling services" - for service in $servicesList ; do - if [ -z "$service" ]; then - removeService $packageName - else - removeService $service - fi - done - fi -} - - -# restart the GUI V1 service -# begining at about v3.20~18, changes were made to accommodate the gui-v2 -# and these changes require different handling of a GUI service restart - - -restartGuiV1Service () -{ - # gui is the older service that runs GUI v1 only - if [ -e "/service/gui" ]; then - svc -t "/service/gui" - # restart GUI if NOT running v2 or can't determine if GUI v1 or v2 is selected - elif [ -e "/service/start-gui" ]; then - guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')" - if (( $guiVersion != 2 )); then - svc -t "/service/start-gui" - fi - fi -} - -# for backward compatibility (oler setup scripts) -restartGuiService () -{ - restartGuiV1Service -} - -restartGuiV2Service () -{ - # restart GUI if NOT running v1 or can't determine if GUI v1 or v2 is selected - if [ -e "/service/start-gui" ]; then - guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')" - if (( $guiVersion != 1 )); then - svc -t "/service/start-gui" - fi - fi -} - -# determine how the setup script should exit based on $scriptAction and other flags -# services may be restarted here also -# -# endScript accepts these optional parameters which determines if files and/or services are installed -# -# 'INSTALL_FILES' causes files from the file lists to be installed -# 'INSTALL_SERVICES' causes services in the services directory to be installed -# all services must be in the package's services directory -# 'ADD_DBUS_SETTINGS' will add/update dBus settings from the DbusSettingsList -# any or may be included -# do NOT include these if related processing is needed in the setup script ! -# instead, call installAllFiles and/or installAllServices in line with the other processing -# or call updateActiveFile or installService directly -# -# this function completes package installation -# and sets up conditions for reinstallation following a Venus Os firmware update -# -# may EXIT or REBOOT within the function - DOES NOT RETURN TO CALLER - - -endScript () -{ - if [ $scriptAction == 'INSTALL' ] && ! $installFailed ; then - # do installs as indicated from caller - while (( $# > 0 )); do - case "$1" in - 'INSTALL_FILES') - installAllFiles - ;; - 'INSTALL_SERVICES') - installAllServices - ;; - 'ADD_DBUS_SETTINGS') - addAllDbusSettings - ;; - esac - shift - done - - # assume that if we get this far, any command line opitons have already been set - touch "$setupOptionsDir/optionsSet" - - # clear flag preventing auto installs in PackageManager - rm -f "$setupOptionsDir/DO_NOT_AUTO_INSTALL" - - # if script needs to run again, installedVersionFile flag file is removed - # script should run again at boot time via reinstallMods - if $runAgain ; then - logMessage "script will run again at startup" - rm -f "$installedVersionFile" - # otherwise, installation is complete - update installedVersion - else - cp "$scriptDir/version" "$installedVersionFile" - fi - - # update rc.local to include call to reinstallMods - # do only for SetupHelper since other packages are now installed by PackageManager - if ! $installFailed && [ "$packageName" == "SetupHelper" ]; then - if [ ! -f "$rcLocal" ]; then - logMessage "creating $rcLocal" - cp "$scriptDir/rcS.local" "$rcLocal" - chmod +x "$rcLocal" - elif [ $(grep -c "blind install" "$rcLocal") -gt 0 ]; then - logMessage "REPLACING blind install $rcLocal with the standard one" - rm -f "$rcLocal" - cp "$scriptDir/rcS.local" "$rcLocal" - chmod +x "$rcLocal" - elif [ $(grep -c "SetupHelper" "$rcLocal") == 0 ]; then - logMessage "adding SetupHelper reinstall script to $rcLocal" - sed -e '2d' "$scriptDir/rcS.local" >> $rcLocal - fi - fi - fi - - - if [ $scriptAction == 'UNINSTALL' ] ; then - if $installFailed ; then - logMessage "INSTALL failed - attempting UNINSTALL in endScript" - # package was actually uninstalled (not an install failure) - set flag preventing auto installs - else - touch "$setupOptionsDir/DO_NOT_AUTO_INSTALL" - fi - - # ALWAYS attempt to uninstall files and services - uninstallAllFiles - uninstallAllServices - - # flag package not installed since package is being removed - rm -f "$installedVersionFile" - - # when uninstalling SetupHelper, remove EMPTY installed...Lists in all packages - # to prevent a future install with an older SetupHelper - # confusing a future future uninstall with a new SetupHelper - if [ "$packageName" == "SetupHelper" ] && [ -e "$installedFilesDir" ]; then - for file in $(ls "$installedFilesDir") ; do - if ! [ -s "$installedFilesDir/$file" ]; then - rm "$installedFilesDir/$file" - fi - done - # remove lines from rcS.local - sed -i -e "/# SetupHelper reinstall/,/fi/d" "$rcLocal" - fi - fi - - # setup script signals nothing to do - exit without further action without errors - if ! $installFailed; then - if [ $scriptAction == 'EXIT' ]; then - exit $EXIT_SUCCESS - elif ! [ $scriptAction == 'INSTALL' ] && ! [ $scriptAction == 'UNINSTALL' ]; then - setInstallFailed $EXIT_ERROR "unexpected script action $scriptAction - did not install or uninstall" - fi - fi - - # check for reboot or restarts - if $rebootNeeded ; then - if $userInteraction ; then - if yesNoPrompt "Reboot system now (y) or do it manually later (n): " ; then - logMessage "rebooting ..." - reboot - else - logMessage "system must be rebooted to finish installation and activate components" - exit $EXIT_REBOOT - fi - else - logMessage "completed - reboot needed" - exit $EXIT_REBOOT - fi - fi - if $restartGeneratorService ; then - logMessage "restarting generator service" - svc -t /service/dbus-generator-starter - fi - if $restartSystemCalc ; then - logMessage "restarting systemcalc service" - svc -t /service/dbus-systemcalc-py - fi - if $restartDigitalinputs ; then - logMessage "restarting digital inputs service" - svc -t /service/dbus-digitalinputs - fi - #### TODO: add gui v2 - if $restartGui ; then - if $userInteraction ; then - if yesNoPrompt "Restart the GUI now (y) or issue a do it manually later (n): " ; then - logMessage "completed - restarting GUI" - restartGuiV1Service - if $installFailed ; then - exit $installExitReason - else - exit $EXIT_SUCCESS - fi - else - echo "GUI must be restarted to activate changes" - exit $EXIT_RESTART_GUI - fi - else - if $deferGuiRestart ; then - logMessage "completed - GUI restart needed" - exit $EXIT_RESTART_GUI - # GUI restart NOT deferred - do it now - else - logMessage "completed - restarting GUI" - restartGuiV1Service - if $installFailed ; then - exit $installExitReason - else - exit $EXIT_SUCCESS - fi - fi - fi - fi - - # if installation was attempted but failed, exit without checking anything else - if $installFailed ; then - if [ $scriptAction == 'UNINSTALL' ]; then - logMessage "complete - package has been uninstalled" - else - logMessage "complete - no changes were made" - fi - exit $installExitReason - # install/uninstall succeeded - else - logMessage "complete - no errors" - exit $EXIT_SUCCESS - fi -} - -######## this code is executed in-line when CommonResources is sourced - -# check for reinstall parameter -# set $scriptAction to control work following the source command -# if "force" is also provided on the command line, then the installedVersionFile is not checked -# installedVersionFile contains the installed version (if any) -# it is compared to the version file in the package directory -# if installedVersionFile is missing or contents are different, the installation will proceed -# if the two versions match, there is no need to reinstall the package -# we assume a reinstall is always run without benefit of a console (runningAtBoot will be true) -# so there will be no prompts and all actions will be automatic -# -# "deferReboot" signals that endScript should not reboot the system, but return EXIT_REBOOT -# assuming the caller will evenutally reboot the system -# -# "deferGuiRestart" is similar for restarting the GUI -# -# "install" causes the package to be installed silently -# "uninstall" causes the package to be uninstalled silently -# -# command line parameters may appear in any order -# -# -# logToConsole is set to true in the LogHandler script -# It is set to false here the 'auto' parameter is passed on the command line -# which indicates this script is NOT being run from the command line - -# cleanup from previous versions - reinstallScriptsList no loner used -rm -f "/data/reinstallScriptsList" - -# set global machine type -if [ -f /etc/venus/machine ]; then - machine=$(cat /etc/venus/machine) -else - machine="" - setInstallFailed $EXIT_INCOMPATIBLE_PLATFORM "can't determine Venus device type" -fi - -# initialize version strings and numbers for future checks -if [ -f "$installedVersionFile" ]; then - installedVersion=$(cat "$installedVersionFile") - versionStringToNumber $installedVersion - installedVersionNumber=$versionNumber -else - installedVersion="" - installedVersionNumber=0 -fi - -packageVersionFile="$scriptDir/version" -if [ -f "$packageVersionFile" ]; then - packageVersion=$(cat "$packageVersionFile") - - versionStringToNumber $packageVersion - packageVersionNumber=$versionNumber -else - packageVersion="" - packageVersionNumber=0 -fi - -# collect command line options -reinstall=false -force=false -deferReboot=false -deferGuiRestart=false -userInteraction=true -runFromPm=false -while [ $# -gt 0 ]; do - case $1 in - "reinstall") - reinstall=true - ;; - "force") - force=true - ;; - "deferReboot") - deferReboot=true - ;; - "deferGuiRestart") - deferGuiRestart=true - ;; - "install") - scriptAction='INSTALL' - ;; - "uninstall") - scriptAction='UNINSTALL' - ;; - "auto") - logToConsole=false - userInteraction=false - ;; - "runFromPm") - runFromPm=true - logToConsole=false - userInteraction=false - deferReboot=true - deferGuiRestart=true - ;; - "check") - # if no other actions were set, set it here - # but allow other actions to override this one - if [ $scriptAction == 'NONE' ]; then - scriptAction='CHECK' - fi - ;; - *) - esac - shift -done - -# do after logToConsole is enabled/disabled abvove -logMessage "--- starting setup script $packageVersion action $scriptAction" - -# packages that require options to proceed unattended -# must include the optionsRequried flag file in their package directory -# if the flag is present and options haven't been previously set, -# SD/USB media will be checked for the package options directory -# and copy them into position - -opitonsRequiredFile="$scriptDir/optionsRequired" -optionsSet=false -if [ -f $opitonsRequiredFile ]; then - if [ -f "$setupOptionsDir/optionsSet" ]; then - optionsSet=true - # options not set - check media for options if doing a blind install - elif [ $scriptAction == 'INSTALL' ]; then - mediaList=($(ls /media)) - for dir in ${mediaList[@]} ; do - altSetupDir="/media/$dir/"$(basename $setupOptionsRoot)"/$packageName" - if [ -f "$altSetupDir/optionsSet" ]; then - cp -r "$altSetupDir" "$setupOptionsRoot" - if [ -f "$setupOptionsDir/optionsSet" ]; then - logMessage "options retrieved from SD/USB media" - optionsSet=true - fi - break - fi - done - fi - -# no command line options are needed - ok to reinstall even if -# setup was not run from the command line -else - optionsSet=true -fi - -# called from reinstallMods at boot time -if $reinstall ; then - runningAtBoot=true - if $force ; then - scriptAction='INSTALL' - # not installed, do it now - elif (( installedVersionNumber == 0 )); then - scriptAction='INSTALL' - # check versions and install only if package version is newer than installed version - else - # trigger install if version numbers differ - if (( installedVersionNumber != packageVersionNumber )); then - scriptAction='INSTALL' - else - exit $EXIT_SUCCESS - fi - fi - -# not running from reinstallMods -else - runningAtBoot=false - pruneSetupLogFile -fi - -if [ ! -d "$setupOptionsDir" ]; then - logMessage "creating package options directory $setupOptionsDir" - mkdir -p $setupOptionsDir -fi - -# initialze integer version number for venus version -# used below and in checkFileSets -versionStringToNumber $venusVersion -venusVersionNumber=$versionNumber - -# do pre-checks - skip if uninstalling -if [ $scriptAction != 'UNINSTALL' ]; then - # flag the version that is performing these checks - # this is used by PackageManager to know when to run checks - echo "$venusVersion" > "$scriptDir/packageCheckVersion" - - # prevent installing Raspberry Pi packages on other platforms - if [ -f "$scriptDir/raspberryPiOnly" ]; then - if [[ $machine != *"raspberrypi"* ]]; then - setInstallFailed $EXIT_INCOMPATIBLE_PLATFORM "$packageName not compatible with $machine" - fi - fi - # check to see if package is compatible with this Venus version - if [ -f "$scriptDir/firstCompatibleVersion" ]; then - firstCompatibleVersion=$(cat "$scriptDir/firstCompatibleVersion") - # no first compatible version specified - use the default - else - firstCompatibleVersion='v2.71' - fi - versionStringToNumber $firstCompatibleVersion - firstCompatibleVersionNumber=$versionNumber - if (( $venusVersionNumber < $firstCompatibleVersionNumber )); then - setInstallFailed $EXIT_INCOMPATIBLE_VERSION "$venusVersion before first compatible $firstCompatibleVersion" - elif [ -f "$scriptDir/obsoleteVersion" ]; then - obsoleteVersion=$(cat "$scriptDir/obsoleteVersion") - versionStringToNumber $obsoleteVersion - obsoleteVersionNumber=$versionNumber - if (( $venusVersionNumber >= $obsoleteVersionNumber )); then - setInstallFailed $EXIT_INCOMPATIBLE_VERSION "$venusVersion after last compatible $obsoleteVersion" - fi - fi - - # determine if GUI v1 is installed - # Note, it may NOT be running or selected to run!!!! - if [ ! -d "/opt/victronenergy/gui" ]; then - guiV1present=false - else - guiV1present=true - fi - # block installs if any GUI files would be modified and GUI v1 is not present - # packages can bypass GUI v1 checks and allow installs even if package contains them - if [ -f "$scriptDir/GUI_V1_NOT_REQUIRED" ]; then - guiV1required=false - # files in the GUI v1 directory are considered mandatory - elif (( $( cat "$pkgFileSets/fileList"* 2>/dev/null | grep -c '/gui/' ) > 0 )); then - guiV1required=true - # look also in setup script - elif (( $( grep 'updateActiveFile' "$scriptDir/setup" | grep -c '$qmlDir\|/gui/') > 0 )); then - guiV1required=true - else - guiV1required=false - fi - if ! $guiV1present && $guiV1required ; then - setInstallFailed $EXIT_NO_GUI_V1 "$packageName requires GUI v1" - fi - - # attempting an install without the comand line prompting - # and needed options have not been set yet - can't continue - if ! $installFailed && [ $scriptAction == 'INSTALL' ]; then - if ! $optionsSet ; then - setInstallFailed $EXIT_OPTIONS_NOT_SET "required options have not been set" - fi - fi - - getFileLists "$pkgFileSets" - - checkFileSets - - # checkFileSets created a missing file set and set the INCOMPLETE flag if needed - # that is all CHECK needed to do so EXIT HERE !!!! - if [ $scriptAction == 'CHECK' ]; then - if [ -f "$fileSet/INCOMPLETE" ]; then - exit $EXIT_FILE_SET_ERROR - fi - fi - - checkPackageDependencies - - # create installed files (and services) directory - if [ ! -d "$installedFilesDir" ]; then - mkdir "$installedFilesDir" - fi - - # create place for patch output (unique temp directory in volatile storage) - # this is removed in the exit trap above - patchedFiles=$( mktemp -d ) - - # create patched files in fileListPatched - patchErrors=() - for file in ${fileListPatched[@]}; do - message="" - baseName=$( basename $file ) - patchFile="$patchSourceDir/$baseName.patch" - if ! [ -f "$patchFile" ]; then - message="patch file missing for $baseName" - patchErrors+="$message\n" - setInstallFailed $EXIT_PATCH_ERROR "$message" - continue - fi - # BusyBox patch doesn't support the -o option so copy source to output first - # then patch the output - # if package already installed, patch .orig - if [ -e "$file.orig" ]; then - cp "$file.orig" "$patchedFiles/$baseName" - # if package probably not installed, patch the active file - elif [ -e "$file" ] ; then - cp "$file" "$patchedFiles/$baseName" - else - message="no source for $baseName patch" - patchErrors+=( "$message" ) - setInstallFailed $EXIT_PATCH_ERROR "$message" - continue - fi - if ! patch "$patchedFiles/$baseName" "$patchFile" &> /dev/null ; then - message="patch unsuccesful for $baseName" - patchErrors+=( "$message" ) - setInstallFailed $EXIT_PATCH_ERROR "$message" - fi - done - - # save any errors in PatchErrors file - if [ -z "$patchErrors" ] ; then - rm -f "$scriptDir/patchErrors" - else - printf "%s\n" "${patchErrors[@]}" > "$scriptDir/patchErrors" - if [ $scriptAction == 'CHECK' ]; then - exit $EXIT_PATCH_ERROR - else - endScript - fi - fi - - # go no further if just checking - if [ $scriptAction == 'CHECK' ]; then - exit $EXIT_SUCCESS - fi - - # create patched files for files with VisibleItemModel for older Venus OS versions - versionStringToNumber "v3.00~14" - if (( $venusVersionNumber < $versionNumber )); then - logMessage "patching VisibleItemModel to VisualItemModel in all .qml replacements" - for file in ${fileListVersionIndependent[@]}; do - baseName=$( basename "$file" ) - if ! [[ "$baseName" == *.qml ]]; then continue; fi - sourceFile="$versionIndependentFileSet/$baseName" - if ! [ -f "$sourceFile" ]; then continue; fi - if (( $(grep -c "VisibleItemModel" "$sourceFile") == 0 )); then continue; fi - sed -e 's/VisibleItemModel/VisualItemModel/' "$sourceFile" > "$patchedFiles/$baseName" - done - fi -fi # if [ $scriptAction != 'UNINSTALL' ] - -# make sure rootfs is mounted R/W & and resized to allow space for replacement files -# arbitrary minimum size of 3 MB -if ! $installFailed; then - rootMinimumSize=3 - availableSpace=$(df -m / | tail -1 | awk '{print $4}') - - # remount read-write - if (( $(mount | grep ' / ' | grep -c 'rw') == 0 )); then - # only remount read-write for CCGX - if [ "$machine" == "ccgx" ]; then - if [ -f /opt/victronenergy/swupdate-scripts/remount-rw.sh ]; then - logMessage "remounting root read-write" - /opt/victronenergy/swupdate-scripts/remount-rw.sh - fi - # remount and resize for other platforms - elif [ -f /opt/victronenergy/swupdate-scripts/resize2fs.sh ]; then - /opt/victronenergy/swupdate-scripts/resize2fs.sh - availableSpace=$(df -m / | tail -1 | awk '{print $4}') - logMessage "remounting read-write root and resizing - $availableSpace MB now available" - fi - # check to see if remount was successful - if (( $(mount | grep ' / ' | grep -c 'rw') == 0 )); then - setInstallFailed $EXIT_ROOT_FULL "ERROR: unable to remount root read-write - can't continue" - fi - # root already read-write, attempt to resize if space is limited (CCGX can't resize) - elif (( $availableSpace < $rootMinimumSize )); then - if [ "$machine" == "ccgx" ]; then - logMessage "can't resize root on CCGX" - else - if [ -f /opt/victronenergy/swupdate-scripts/resize2fs.sh ]; then - /opt/victronenergy/swupdate-scripts/resize2fs.sh - availableSpace=$(df -m / | tail -1 | awk '{print $4}') - logMessage "resized root - $availableSpace MB now available" - fi - fi - fi -fi -if ! $installFailed; then - # make sure the root partition has space for the package - if (( $availableSpace < $rootMinimumSize )); then - setInstallFailed $EXIT_ROOT_FULL "no room for modified files on root ($availableSpace MB remaining) - can't continue" - fi -fi - -# done with pre checks -# prior to this no system mofications have been made -# after this system modifications may occur - -if $installFailed ; then - if ! $userInteraction ; then - logMessage "ERROR: errors occured during pre-checks - can't continue" - # EXIT HERE if errors occured during pre-checks while running unattended !!!! - # the LAST install failure reported to setInstallFailed is used as the exit code - exit $installExitReason # EXIT HERE !!!! - # command line install request failed - reset scriptAction to NONE - # so prompts will be shown - eg - # to show the log or - # to trigger a manual uninstall - elif [ $scriptAction == 'INSTALL' ]; then - logMessage "ERROR: install failed during pre-checks - select another action" - scriptAction='NONE' - fi -fi - -installPreChecks=false - - -#### do standard prompting, automatic install/uninstall then exit -if [ "$standardPromptAndActions" == 'yes' ]; then - # prompt only if action hasn't been set yet (from command line) - if [ "$scriptAction" == 'NONE' ]; then - standardActionPrompt - fi - endScript 'INSTALL_FILES' 'INSTALL_SERVICES' 'ADD_DBUS_SETTINGS' -fi - -# otherwise continue with the setup script - -#### continue executing the setup script which sourced this file - - - diff --git a/HelperResources/DbusSettingsResources b/HelperResources/DbusSettingsResources deleted file mode 100755 index d1cd1c4..0000000 --- a/HelperResources/DbusSettingsResources +++ /dev/null @@ -1,211 +0,0 @@ -#!/bin/bash - -# 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 - -# 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 -# updateDbusIntSetting -# updateDbusRealSetting -# updates a dbus setting parameter with a new value -# -# if the setting does not exist, it is created -# but max and min values are not set and the default is "", 0 or 0.0 depending on data type -# if these are needed use the dbus command directly -# this can also be faster if lots of settings must be created at the same time -# -# other data types may exist and would need their own function -# -# $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 () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - dbus-send --system --print-reply=literal --dest=com.victronenergy.settings "$1"\ - com.victronenergy.BusItem.GetValue &> /dev/null - if (( $? != 0 )); 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 () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - dbus-send --system --print-reply=literal --dest=com.victronenergy.settings "$1"\ - com.victronenergy.BusItem.GetValue &> /dev/null - if (( $? != 0 )); 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 -} - - -updateDbusRealSetting () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - dbus-send --system --print-reply=literal --dest=com.victronenergy.settings "$1"\ - com.victronenergy.BusItem.GetValue &> /dev/null - if (( $? != 0 )); then - logMessage "creating dbus Setting $1" - dbus -y com.victronenergy.settings / AddSettings "%[ {\"path\":\"$1\", \"default\":0.0} ]" &> /dev/null - fi - - dbus -y com.victronenergy.settings "$1" SetValue "$2" &> /dev/null -} - - - -# addAllDbusSettings adds settings from DbusSettingsList in the package directory -# the format of each line is: -# {"path":"/Settings/GuiMods/ShortenTankNames", "default":1, "min":0, "max":1} -# min and max are optional - -addAllDbusSettings () -{ - local settings - - if [ -f "$scriptDir/DbusSettingsList" ]; then - logMessage "updating dbus Settings" - while read -r line || [[ -n "$line" ]]; do - settings+="$line, " - done < "$scriptDir/DbusSettingsList" - - dbus -y com.victronenergy.settings / AddSettings "%[ $settings ]" &> /dev/null - fi -} - -# same as above but removes them -# typically settings are retained when removing a package so -# the developer must make this call specifically in the setup script's UNINSTALL section -# if they wish to remove the settings - -removeAllDbusSettings () -{ - local settings - - if [ -f "$scriptDir/DbusSettingsList" ]; then - logMessage "removing dbus Settings" - while read -r line || [[ -n "$line" ]]; do - settings+=$( echo $line | awk -F[:,] '{print $2, ","}' ) - done < "$scriptDir/DbusSettingsList" - - dbus -y com.victronenergy.settings / RemoveSettings "%[ $settings ]" - fi -} - - - -# removeDbusSettings removes the setting from dbus 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) - -removeDbusSettings () -{ - 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 - -setSetting () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - 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 (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 () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - local setupOption="$1" - local oldDbusPath=$2 - local newDbusPath=$3 - - 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 - if [ ! -z $oldSetting ] && [ ! -z "$newDbusPath" ]; then - dbus -y com.victronenergy.settings $newDbusPath SetValue $oldSetting &> /dev/null - fi -} diff --git a/HelperResources/EssentialResources b/HelperResources/EssentialResources deleted file mode 100755 index 585790a..0000000 --- a/HelperResources/EssentialResources +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash - -# EssentialResources for SetupHelper -# contains a variables necessary for all setup helper scripts -# -# sourced from CommonResources, UpdateResources and reinstallMods -# and also updateFileSets - -# get the full, unambiguous path to this script (and therefore to script that sourced it) -scriptDir="$( cd "$(dirname $0)" >/dev/null 2>&1 ; /bin/pwd -P )" -packageRoot="$( dirname $scriptDir )" -packageName=$( basename "$scriptDir" ) - -shortScriptName=$(basename "$scriptDir")/$(basename "$0") -fullScriptName="$scriptDir/$(basename "$0")" - -if [ -f "/opt/victronenergy/version" ]; then - venusVersion="$(cat /opt/victronenergy/version | head -n 1)" -else - venusVersion="" -fi - -installedVersionPrefix="/etc/venus/installedVersion-" -installedVersionFile="$installedVersionPrefix"$packageName - -installedFilesDir="/etc/venus/installedModifications" -installedFilesList="$installedFilesDir/installedFiles"-$packageName -installedServicesList="$installedFilesDir/installedServices"-$packageName - - -# obsolete - use installedVersion -installedFlagPrefix="/etc/venus/inInstalled-" -installedFlag="$installedFlagPrefix"$packageName - -# set up pointers to package files -# based on the actual package for compatibility with older packages -pkgFileSets="$scriptDir/FileSets" -fileSet="$pkgFileSets/$venusVersion" -versionIndependentFileSet="$pkgFileSets/VersionIndependent" -# location of patch files -patchSourceDir="$pkgFileSets/PatchSource" -altOrigFileDir="$pkgFileSets/AlternateOriginals" - -servicesDir="$scriptDir/services" - - -# rc local file that calls reinstallMods -# rcS.local avoids conflicts with mods that blindly replace /data/rc.local -rcLocal="/data/rcS.local" - -# defined exit codes - must be consistent between all setup scripts and reinstallMods -# and PackageManager.py -EXIT_SUCCESS=0 -EXIT_REBOOT=123 -EXIT_RESTART_GUI=124 -EXIT_ERROR=255 # unknown error -EXIT_INCOMPATIBLE_VERSION=254 -EXIT_INCOMPATIBLE_PLATFORM=253 -EXIT_FILE_SET_ERROR=252 -EXIT_OPTIONS_NOT_SET=251 -EXIT_RUN_AGAIN=250 -EXIT_ROOT_FULL=249 -EXIT_DATA_FULL=248 -EXIT_NO_GUI_V1=247 -EXIT_PACKAGE_CONFLICT=246 -EXIT_PATCH_ERROR=245 - - -# old variables - keep for compatibility -exitReboot=$EXIT_REBOOT -exitSuccess=$EXIT_SUCCESS - -# 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 - - diff --git a/HelperResources/IncludeHelpers b/HelperResources/IncludeHelpers deleted file mode 100755 index 9d1c44a..0000000 --- a/HelperResources/IncludeHelpers +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh - -# this script selects the correct location for helper Resources -# and sources them into the setup script -# -# for backward compatibility, CommonResources in the SetupHelper directory -# links to this file, not CommonResources -# CommonResources previously sourced the other files -# now sourcing all resource files is done from here -# -# the helper files location is either the package directory or in the SetupHelper directory -# if both are present, the one with the newer version number is incorporated -# into the setup script -# -# this script should be sourced in the setup script before any other activities - -# NOTE: this script uses VersionResources ONLY -# it does source any other helper files since final location has not yet been chosen - -pkgDir="$( cd "$(dirname $0)" >/dev/null 2>&1 ; /bin/pwd -P )" -pkgRoot="$( dirname "$pkgDir")" -pkgName=$( basename $pkgDir ) -shHelperDir="$pkgRoot/SetupHelper/HelperResources" -# assume helper files are in package directory - change below if not -helperResourcesDir="$pkgDir/HelperResources" - -if [ -e "$helperResourcesDir/version" ]; then - # both helper file sets are present - compare them and choose the newest - if [ -e "$shHelperDir" ]; then - # temporarily source the local VersionResources - source "$pkgDir/HelperResources/VersionResources" - # setup helper files are newer - switch to those helper files - compareVersions $( cat "$shHelperDir/version" ) $( cat "$pkgDir/HelperResources/version" ) - if (( $? == 1 )); then - helperResourcesDir="$shHelperDir" - fi - fi -elif [ -e "$shHelperDir" ]; then - helperResourcesDir="$shHelperDir" -else - echo "$pkgName: helper files not found - can't continue" | tee -a "/data/log/SetupHelper" - exit 1 -fi - -# if we get here, helper files were located - source the files -helperFileList=( EssentialResources LogHandler VersionResources \ - DbusSettingsResources ServiceResources ) -for file in ${helperFileList[@]}; do - if [ -f "$helperResourcesDir/$file" ]; then - source "$helperResourcesDir/$file" - else - echo "$pkgName: helper file $file not found - can't continue" | tee -a "/data/log/SetupHelper" - exit 1 - fi -done - -# now transfer control to CommonResoures - it may not return ! -if [ -f "$helperResourcesDir/CommonResources" ]; then - source "$helperResourcesDir/CommonResources" -else - echo "$pkgName: helper file CommonResources not found - can't continue" | tee -a "/data/log/SetupHelper" - exit 1 -fi - - diff --git a/HelperResources/LogHandler b/HelperResources/LogHandler deleted file mode 100755 index 6cfa585..0000000 --- a/HelperResources/LogHandler +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -# LogHandler for SetupHelper -# contains a functions and variables necessare=y to write to and output logs -# -# Refer to the SetupHelper ReadMe file for details on how to use these resources -# -# it is sourced by CommonResources and reinstall Mods -# -# there may be two logs associated with a setup script: -# the script helper log and optionally the package log -# logs are written to both places and additionally the command line if not running from reinstallMods - -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 -# -# $1 specifies the path to the log file -# $setupLogFile -# $packageLogFile is defined to point to the log file of the package if it exists - -displayLog () -{ - if [ ! -z "$1" ]; then - if [ -f "$1" ]; then - tail -100 "$1" | tai64nlocal - else - echo "no log File $1 found" - fi - else - echo "no log File specified" - fi -} - - -# write a message to one or more log files - -logMessage () -{ - # to console - if $logToConsole ; then - echo "$*" - fi - - # to setup helper log - if [ ! -z $setupLogFile ]; then - echo "$shortScriptName: $*" | tai64n >> $setupLogFile - fi - - # to setup helper log - if [ ! -z $packageLogFile ]; then - # no log file yet - make enclosing directory - # if directory already exists mkdir will do nothing (silently) - if [ ! -f "$packageLogFile" ]; then - mkdir -p $(dirname "$packageLogFile") - fi - 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 -} diff --git a/HelperResources/ServiceResources b/HelperResources/ServiceResources deleted file mode 100755 index 56db015..0000000 --- a/HelperResources/ServiceResources +++ /dev/null @@ -1,294 +0,0 @@ -#!/bin/bash - -#!/bin/bash -# ServiceManager for SetupHelper -# contains a functions to install and remove a package's service -# -# If an active copy of the service already exists, the run and log/run files are updated -# ONLY if there are changes, then the service and/or the logger will be restarted. -# This leaves other files managed by supervise untouched. -# -# in Venus OS between v2.80~10 and v2.90~2, services are stored in /opt/victronenergy/service -# which is overlayed onto /service -# the FS overlay also maintains a "working directory": $overlayWorkDir in this script -# all services need to be added there rather than /service -# Note: service calls (eg svc) are still made on /service/... -# there is an unknown interaction between /service and the overlay source -# so code here operates on both directories -# -# in Venus OS starting with v2.90~3, /service is mounted as a tmpfs (RAM disk) -# /opt/victronenergy/service is copied to /service ONLY at boot time -# so new services need to be copied to /opt/victronenergy/service for boot processing -# AND to /service so they run immediately -# -# svc -u /service/ starts a service that is not already running -# svc -d /service/ stops a service and will not restart -# these are "temporary" and don't survive a system boot -# svc -t /service/ sends the service a TERM command -# if the service was up at the time, it restarts -# if the service was down at the time, it is NOT started -# -# the /service//down flag file controls the state of a service at boot time: -# if the file exists, the service won't start automatically at boot or when created -# if the file does not exist, the service will start at boot or immediately when it is created -# -# if the services manager (svscan) is not up, or the real service directory does not yet exist -# some steps will be skipped to avoid errors in calling daemontools functions -# -# more info here: -# https://cr.yp.to/daemontools/svc.html -# https://cr.yp.to/daemontools/supervise.html -# https://cr.yp.to/daemontools/svstat.html -# https://cr.yp.to/daemontools/svok.html - -victronServicesDir="/opt/victronenergy/service" -overlayWorkDir="/run/overlays/service" -serviceDir="$victronServicesDir" -serviceUsesFsOverlay=false -serviceMountedTmpfs=false - -versionStringToNumber "v2.90~3" -tmpfsStartVersion=$versionNumber -versionStringToNumber "v2.80~10" -overlayStartVersion=$versionNumber -versionStringToNumber $venusVersion - -# service is mounted tmpfs -if (( $versionNumber >= $tmpfsStartVersion )) ; then - serviceMountedTmpfs=true -# service uses a file system overlay -elif (( $versionNumber >= $overlayStartVersion )) ; then - serviceUsesFsOverlay=true -# service is writable in place -else - serviceDir="/service" -fi - -# check to see if services manager is running -svscanIsUp () -{ - pgrep -lx svscan &> /dev/null - if (( $? == 0 )) ; then - return 0 - else - return 1 - fi -} - -# check to see if named service is up -serviceIsUp () -{ - if ! svscanIsUp ; then - return 1 - elif [ ! -e "/service/$1" ]; then - return 1 - elif [ $(svstat "/service/$1" | awk '{print $2}') == "up" ]; then - return 0 - else - return 1 - fi -} - - -# -# removeService cleanly removes the service -# - -removeService () -{ - # no service specified - if (( $# < 1 )); then - return - fi - local serviceName="$1" - - if [ -e "$serviceDir/$serviceName" ]; then - logMessage "removing $serviceName service" - # stop the service if it is currently running - if serviceIsUp $serviceName ; then - svc -d "/service/$1" - fi - if serviceIsUp "$serviceName/log" ; then - svc -d "/service/$1/log" - fi - - # supervise processes may hang around after removing the service so save info and kill them after removal - pids="" - while read -u 9 line; do - read s uid pid ppid vsz rss tty stime time cmd blah <<< "$line" - if [ $cmd == 'supervise' ]; then - pids+="$pid " - elif [ $cmd == 'multilog' ]; then - pids+="$ppid " - fi - done 9<<< $(ps -lw | grep $serviceName) - - # remove the service directory - rm -rf "$serviceDir/$serviceName" - # when /service is mounted as tmpfs, the service needs to be removed from /service also - if $serviceMountedTmpfs && [ -d "/service/$serviceName" ]; then - rm -rf "/service/$serviceName" - # removing the service in the overlayed service directory doesn't remove it from /service - # it needs to be removed from the overlay work directory also - elif $serviceUsesFsOverlay && [ -d "$overlayWorkDir/$serviceName" ] ; then - rm -rf "$overlayWorkDir/$serviceName" - fi - - # now kill the supervise processes - if ! [ -z $pids ]; then - kill $pids - fi - fi - - # remove service from installed services list - if [ -f "$installedServicesList" ]; then - grep -v "$serviceName" "$installedServicesList" | tee "$installedServicesList" > /dev/null - fi -} - - -# installService adds the service to the /service directory or updates an existing one -# -# If the service does not yet exist, it is created -# If the service already exists, installService will -# update the service files then restart the service and the logger - - -# The service usually starts automatically within a few seconds of creation. -# installService waits 10 seconds to see if the service starts on its own -# if not, it will be started -# -# The service may contain a "down" flag file. If present, the service won't be started. -# This allows the service to be started manually later. -# If the down flag is present the service will not start at boot. -# -# -# $1 is the service name -- that is the name of the service in /service -# the package name will be used as the service name if not specified on the command line -# -# $2 is the directory in the script directory to be copied to the service in /service -# (this includes the run and control (down) files) -# the default is 'service' in the package directory -# -# for most packages with one service, the defaults are fine -# however if a package needs to install more than one service -# then the service name and directory must be specified -# installService "PackageManager" "servicePM" -# installService "SetupHelper" "serviceSH" -# servicePM/run would include a call to /data/SetupHelper/PackageManager.py -# serviceSH/run would include a call to /data/SetupHelper/SetupHelper.sh - -installService () -{ - # don't do any work if install has already failed - if $installFailed; then - return - fi - - local serviceName="" - if (( $# >= 1 )); then - serviceName=$1 - else - serviceName=$packageName - fi - - local servicePath="" - if (( $# >= 2 )); then - servicePath="$scriptDir/$2" - elif [ -e "$servicesDir/$serviceName" ]; then - servicePath="$servicesDir/$serviceName" - elif [ -e "$scriptDir/service" ]; then - servicePath="$scriptDir/service" - fi - - # no service to install - if [ ! -e "$servicePath" ]; then - setInstallFailed $EXIT_ERROR "service $service not found - can't continue" - return - fi - - if [ -L "$serviceDir/$serviceName" ]; then - logMessage "removing old $serviceName service (was symbolic link)" - removeService $serviceName - fi - - # add service to the installed services list (used for uninstallAll) - # do this before actually modifying things just in case there's an error - # that way the uninstall is assured - echo "$serviceName" >> "$installedServicesList" - - # service not yet installed, COPY service directory to the service directory(s) - if [ ! -e "/service/$serviceName" ]; then - logMessage "installing $serviceName service" - - cp -R "$servicePath" "$serviceDir/$serviceName" - if $serviceMountedTmpfs && [ -d "/service" ] ; then - cp -R "$servicePath" "/service/$serviceName" - fi - # if down flag is NOT set, check every second for service to start automatically - # then start it here if it is not running after 10 seconds - if [ -f "$serviceDir/$serviceName/down" ]; then - logMessage "$serviceName not (re)started - must be started manually (down flag set)" - elif ! svscanIsUp ; then - logMessage "services manager (svscan) not yet up - $serviceName should start automatically later" - else - local delayCount=10 - local serviceRunning=false - while (( $delayCount > 0 )); do - if serviceIsUp $serviceName ; then - serviceRunning=true - break - fi - echo "waiting for $serviceName service to start" - sleep 1 - (( delayCount-- )) - done - if $serviceRunning; then - logMessage "service $serviceName running" - else - logMessage "starting $serviceName service" - svc -u "/service/$serviceName" - if [ -e "/service/$serviceName/log" ] && ! serviceIsUp "$serviceName/log" ; then - svc -u "/service/$serviceName/log" - fi - fi - fi - - # service already installed - only copy changed files, then restart service if it is running - else - if [ -f "$servicePath/run" ]; then - cmp -s "$servicePath/run" "$serviceDir/$serviceName/run" > /dev/null - if (( $? != 0 )); then - logMessage "updating $serviceName run file" - cp "$servicePath/run" "$serviceDir/$serviceName/run" - if $serviceMountedTmpfs ; then - cp "$servicePath/run" "/service/$serviceName/run" - fi - fi - if serviceIsUp $serviceName ; then - if $runFromPm && [ $serviceName == 'PackageManager' ]; then - logMessage "$serviceName restart deferred until GUI restart" - restartGui=true - else - logMessage "restarting $serviceName service" - svc -t "/service/$serviceName" - fi - fi - fi - # log needs to be handled separtely including a restart - if [ -f "$servicePath/log/run" ]; then - cmp -s "$servicePath/log/run" "$serviceDir/$serviceName/log/run" > /dev/null - if (( $? != 0 )); then - logMessage "updating $serviceName log/run file" - cp "$servicePath/log/run" "$serviceDir/$serviceName/log/run" - if $serviceMountedTmpfs ; then - cp "$servicePath/log/run" "/service/$serviceName/log/run" - fi - fi - if serviceIsUp "$serviceName/log" ; then - logMessage "restarting $serviceName logger" - svc -t "/service/$serviceName/log" - fi - fi - fi -} diff --git a/HelperResources/VersionResources b/HelperResources/VersionResources deleted file mode 100755 index c4a1439..0000000 --- a/HelperResources/VersionResources +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/sh - -# this file contains functions for comparing version numbers -# -# NOTE: this script does NOT rely on other helper files - - -# convert a version string to an integer to make comparisions easier -# the Victron format for version numbers is: vX.Y~Z-large-W -# the ~Z portion indicates a pre-release version so a version without it is "newer" than a version with it -# the -W portion has been abandoned but was like the ~Z for large builds and is IGNORED !!!! -# large builds now have the same version number as the "normal" build -# -# the version string passed to this function allows for quite a bit of flexibility -# any alpha characters are permitted prior to the first digit -# up to 3 version parts PLUS a prerelease part are permitted -# each with up to 4 digits each -- MORE THAN 4 digits is indeterminate -# that is: v0.0.0d0 up to v9999.9999.9999b9999 and then v9999.9999.9999 as the highest priority -# any non-numeric character can be used to separate main versions -# special significance is assigned to single caracter separators between the numeric strings -# b or ~ indicates a beta release -# a indicates an alpha release -# d indicates an development release -# these offset the pre-release number so that b/~ has higher numeric value than any a -# and a has higher value than d separator -# -# a blank version or one without at least one number part is considered invalid -# alpha and beta seperators require at least two number parts -# -# returns 0 if conversion succeeeded, 1 if not -# the value integer is returned in $versionNumber -# a status text string is returned in $versionStringToNumberStatus -# and will include the string passed to the function -# as well as the converted number if successful and the type of release detected -# or an error reason if not -# - - -function versionStringToNumber () -{ - local version="$*" - local numberParts - local versionParts - local numberParts - local otherParts - local other - local number=0 - local type='release' - - # split incoming string into - # an array of numbers: major, minor, prerelease, etc - # and an array of other substrings - # the other array is searched for releasy type strings and the related offest added to the version number - - read -a numberParts <<< $(echo $version | tr -cs '0-9' ' ') - numberPartsLength=${#numberParts[@]} - if (( $numberPartsLength == 0 )); then - versionNumber=0 - versionStringToNumberStatus="$version: invalid, missing major version" - return 1 - fi - if (( $numberPartsLength >= 2 )); then - read -a otherParts <<< $(echo $version | tr -s '0-9' ' ') - - for other in ${otherParts[@]}; do - case $other in - 'b' | '~') - type='beta' - (( number += 60000 )) - break ;; - 'a') - type='alpha' - (( number += 30000 )) - break ;; - 'd') - type='develop' - break ;; - esac - done - fi - - # if release all parts contribute to the main version number - # and offset is greater than all prerelease versions - if [ "$type" == "release" ] ; then - (( number += 90000 )) - # if pre-release, last part will be the pre release part - # and others part will be part the main version number - else - (( numberPartsLength-- )) - (( number += 10#${numberParts[$numberPartsLength]} )) - fi - # include core version number - (( number += 10#${numberParts[0]} * 10000000000000 )) - if (( numberPartsLength >= 2)); then - (( number += 10#${numberParts[1]} * 1000000000 )) - fi - if (( numberPartsLength >= 3)); then - (( number += 10#${numberParts[2]} * 100000 )) - fi - - versionNumber=$number - versionStringToNumberStatus="$version:$number $type" - return 0 -} - - - -# compares two version strings -# -# missing verions are treated as 0 -# -# returns 0 if they are equal -# returns 1 if the first is newer than the second -# returns -1 if the second is newer than the first - -function compareVersions () -{ - local versionNumber2 - - if [ -z $2 ]; then - versionNumber2=0 - else - versionStringToNumber $2 - versionNumber2=$versionNumber - fi - if [ -z $1 ]; then - versionNumber=0 - else - versionStringToNumber $1 - fi - - if (( versionNumber == versionNumber2 ));then - return 0 - elif (( versionNumber > versionNumber2 ));then - return 1 - else - return -1 - fi -} diff --git a/HelperResources/forSetupScript b/HelperResources/forSetupScript deleted file mode 100644 index ba2ef04..0000000 --- a/HelperResources/forSetupScript +++ /dev/null @@ -1,14 +0,0 @@ -#### add the following lines to the package's setup script -#### following lines incorporate helper resources into this script -pkgDir=$( dirname $0 ) -pkgName=$( basename $pkgDir ) -pkgRoot=$( dirname $pkgDir ) -if [ -e "$pkgDir/HelperResources/IncludeHelpers" ]; then - source "$pkgDir/HelperResources/IncludeHelpers" -elif [ -e "$pkgRoot/SetupHelper/HelperResources/IncludeHelpers" ]; then - source "$pkgRoot/SetupHelper/HelperResources/IncludeHelpers" -else - echo "$pkgName: helper resources not found - can't continue" | tee -a "/data/log/SetupHelper" - exit 1 -fi -#### end of lines to include helper resources diff --git a/HelperResources/version b/HelperResources/version deleted file mode 100644 index 7c280a8..0000000 --- a/HelperResources/version +++ /dev/null @@ -1 +0,0 @@ -v7.17 diff --git a/changes b/changes index 738c67e..6486c35 100644 --- a/changes +++ b/changes @@ -1,3 +1,6 @@ +v3.3: + remove local copy of HelperResources + v3.2: switch to patch for some files diff --git a/setup b/setup index f83515e..7f66a2e 100755 --- a/setup +++ b/setup @@ -14,18 +14,8 @@ standardPromptAndActions='yes' -#### following lines incorporate helper resources into this script -pkgDir=$( dirname $0 ) -pkgName=$( basename $pkgDir ) -pkgRoot=$( dirname $pkgDir ) -if [ -e "$pkgDir/HelperResources/IncludeHelpers" ]; then - source "$pkgDir/HelperResources/IncludeHelpers" -elif [ -e "$pkgRoot/SetupHelper/HelperResources/IncludeHelpers" ]; then - source "$pkgRoot/SetupHelper/HelperResources/IncludeHelpers" -else - echo "$pkgName: helper files not found - can't continue" | tee -a "/data/log/SetupHelper" - exit 1 -fi +#### following line incorporates helper resources into this script +source "/data/SetupHelper/HelperResources/IncludeHelpers" #### end of lines to include helper resources diff --git a/version b/version index 4d5034c..a6c6260 100644 --- a/version +++ b/version @@ -1 +1 @@ -v3.2 +v3.3