Skip to content

Commit

Permalink
Add logmessage if fhem revision is to old for DockerImageInfo Module (#…
Browse files Browse the repository at this point in the history
…253)

Added logmessage
added tests
added note to README
  • Loading branch information
sidey79 authored Jun 29, 2024
2 parents 20d2bdc + 0dc3f6e commit 0fdce6d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Updated versions based on

If you are using 3rd Party modules which are not available on the FHEM svn repository, you may need this image, because it has more perl modules preinstalled.

To let this image work correctly, you need as least a FHEM revision 25680 or newer.

##### Not updated anymore since Jan 2024

- debian buster
Expand Down
20 changes: 20 additions & 0 deletions src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ function initialContainerSetup() {
fhemCleanInstall
fi

local -i revision
revision=$(getFHEMRevision)
[[ revision -lt 25680 ]] && printfErr "Your fhem revision ${revision} is to old, please update to at least revision 25680\n" && printfInfo " Your container will soon be terminated, please update your FHEM installation\n"

printfInfo " Patching fhem.cfg Logfile configuration\n"
setGlobal_LOGFILE
setLogfile_DEFINITION
Expand Down Expand Up @@ -847,6 +851,22 @@ function checkFhemProcessExists() {
}


# Extract the svn revision number from fhem.pl file
#
# Usage: getFHEMRevision
# Returns: 0 if the id is not found
# else: The revision number which is found in the file
#

function getFHEMRevision()
{
local revision
revision=$(grep '# $Id: fhem.pl ' "${FHEM_DIR}/fhem.pl" | cut -d " " -f 4)
[[ $revision =~ ^-?[0-9]+$ ]] && echo "$revision" || echo "0" ; return 0

}


# Starts FHEM.
# Main steps in here:
# - Run pre-start scripts
Expand Down
41 changes: 41 additions & 0 deletions src/tests/bats/entry.bats
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,44 @@ teardown() {
run -1 bash -c 'is_absolutePath .'
run -1 bash -c 'is_absolutePath '
}


# bats test_tags=unitTest
@test "verify getFHEMRevision" {
bats_require_minimum_version 1.5.0

#export -f getFHEMRevision

run fhemCleanInstall
assert_file_exists ${FHEM_DIR}/fhem.pl

assert [ "$(getFHEMRevision)" -gt 0 ]

# Patch fixed revision id
sed -i 's/[0-9]\+/20000/1' ${FHEM_DIR}/fhem.pl
assert [ "$(getFHEMRevision)" -eq 20000 ]

# Patch wrong revision id
sed -i 's/[0-9]\+/ddd/1' ${FHEM_DIR}/fhem.pl
assert [ "$(getFHEMRevision)" -eq 0 ]
}


# bats test_tags=unitTest
@test "verify initialContainerSetup without error" {
run initialContainerSetup
assert_output --partial "Preparing initial container setup"
assert_output --partial "Initial container setup done"
refute_output --partial 'ERROR'
}

# bats test_tags=unitTest
@test "verify initialContainerSetup with to old fhem installation" {
fhemCleanInstall
sed -i 's/[0-9]\+/20000/1' ${FHEM_DIR}/fhem.pl
run initialContainerSetup

assert_output --partial "is to old"
assert_output --partial "Your container will soon be terminated"
assert_output --partial 'ERROR'
}

0 comments on commit 0fdce6d

Please sign in to comment.