Skip to content

Commit

Permalink
Merge pull request #158 from fhem/fix-Logfile
Browse files Browse the repository at this point in the history
Logfile definition patched with real Logfile
  • Loading branch information
sidey79 authored Mar 10, 2024
2 parents 874129d + 62c0602 commit cc169c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ function getGlobalAttr() {
}



# Collect information about the docker environment
#
# Usage: collectDockerInfo
Expand Down Expand Up @@ -325,6 +326,29 @@ function setTelnet_DEFINITION()
fi
}

# Determine a Logfile definition create one if none exists or patch existing
#
# Usage: setLogfile_DEFINITION
# Global vars: CONFIGTYPE
# FHEM_DIR
# LOGFILE
#
function setLogfile_DEFINITION()
{

[ "${CONFIGTYPE}" == "configDB" ] && {
echo ' HINT: Make sure to have your FHEM configuration properly prepared for compatibility with this Docker Image _before_ using configDB !';
return;
} # config is done inside DB => abort

## Find Logfile definition
if [ -z "$(grep -P "^define Logfile FileLog" ${FHEM_DIR}/${CONFIGTYPE})" ]; then
echo "define Logfile FileLog ${LOGFILE} Logfile" >> ${FHEM_DIR}/${CONFIGTYPE}
fi
sed -i "s,define Logfile FileLog ./log/fhem-\S*\ Logfile$,define Logfile FileLog ${LOGFILE#${FHEM_DIR}/} Logfile," ${FHEM_DIR}/${CONFIGTYPE}
}


# Determine PID file
#
# Usage: setGlobal_PIDFILE
Expand Down Expand Up @@ -465,6 +489,9 @@ function fhemCleanInstall() {
getGlobalAttr "${FHEM_DIR}/fhem.cfg" "commandref" >/dev/null || echo "attr global commandref modular" >> ${FHEM_DIR}/fhem.cfg
getGlobalAttr "${FHEM_DIR}/fhem.cfg" "mseclog" >/dev/null || echo "attr global mseclog 1" >> ${FHEM_DIR}/fhem.cfg

printfInfo " Patching fhem.cfg Logfile configuration\n"
setTelnet_DEFINITION

printfInfo " Adding pre-defined devices to fhem.cfg\n"

cat >> $fhemCfgFile <<- END_OF_INLINE
Expand Down Expand Up @@ -659,7 +686,6 @@ fhem ALL=(ALL) NOPASSWD: /usr/bin/nmap
fhem ALL=(ALL) NOPASSWD: /usr/bin/apt-get -q update
fhem ALL=(ALL) NOPASSWD: /usr/bin/apt-get -s -q -V upgrade
fhem ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y -q -V upgrade
fhem ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y -q -V dist-upgrade
fhem ALL=(ALL) NOPASSWD:SETENV: /usr/bin/npm update *
# Allow installation of new packages
fhem ALL=(ALL) NOPASSWD:SETENV: /usr/local/bin/cpanm *
Expand Down
22 changes: 19 additions & 3 deletions src/tests/bats/entry.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ setup() {

teardown() {
rm -rf /opt/fhem/*

}

@test "printf info tests" {
Expand Down Expand Up @@ -64,6 +63,7 @@ teardown() {

}


@test "check setGlobal_LOGFILE from default" {

export -f setGlobal_LOGFILE
Expand Down Expand Up @@ -91,6 +91,24 @@ teardown() {
assert_output "${FHEM_DIR}/log/fhem-%Y-%m.log"
}

@test "check Logfile definition from fhem.cfg" {
export FHEM_DIR="/opt/fhem"
export CONFIGTYPE="fhem.cfg"
export -f setGlobal_LOGFILE
export -f prependFhemDirPath
export -f getGlobalAttr
export -f setLogfile_DEFINITION
export -f fhemCleanInstall

run setGlobal_LOGFILE
run fhemCleanInstall
run setLogfile_DEFINITION

assert_file_exists /opt/fhem/fhem.cfg
assert_file_contains /opt/fhem/fhem.cfg "define Logfile FileLog ./log/fhem-%Y-%m-%d.log Logfile"
}



@test "check fhemUpdateInstall()" {
export FHEM_DIR="/tmp/fhem"
Expand Down Expand Up @@ -151,10 +169,8 @@ teardown() {


@test "verify before clean install FHEM" {

assert_file_exists /fhem/FHEM/99_DockerImageInfo.pm
assert_not_exists /opt/fhem/fhem.pl

}

@test "Setup clean install FHEM" {
Expand Down

0 comments on commit cc169c2

Please sign in to comment.