Skip to content

Commit 2766f21

Browse files
committed
fix[entry.sh]: Add telnet definition
1 parent 3fa5850 commit 2766f21

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/entry.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare -ri TIMEOUT_REAPPEAR=${TIMEOUT_REAPPEAR:-15}
3636

3737
declare -r RESTART="${RESTART:-1}"
3838
declare -r CONFIGTYPE="${CONFIGTYPE:-"fhem.cfg"}"
39+
declare -rix TELNETPORT="${TELNETPORT:-7072}"
3940

4041
declare -r UMASK="${UMASK:-0037}"
4142

@@ -284,6 +285,43 @@ function setGlobal_LOGFILE() {
284285
LOGFILE=$(prependFhemDirPath "$defaultLogfile")
285286
}
286287

288+
# Determine a telnet definition create one if none exists or patch existing
289+
#
290+
# Usage: setTelnet_DEFINITION
291+
# Global vars: CONFIGTYPE
292+
# FHEM_DIR
293+
#
294+
function setTelnet_DEFINITION()
295+
{
296+
297+
[ "${CONFIGTYPE}" == "configDB" ] && {
298+
echo ' HINT: Make sure to have your FHEM configuration properly prepared for compatibility with this Docker Image _before_ using configDB !';
299+
return;
300+
} # config is done inside DB => abort
301+
302+
local CUSTOMPORT=''
303+
local TELNETDEV=''
304+
local TELNETALLOWEDDEV=''
305+
306+
## Find Telnet access details
307+
if [ -z "$(grep -P "^define .* telnet ${TELNETPORT}" ${FHEM_DIR}/${CONFIGTYPE})" ]; then
308+
echo "define telnetDocker telnet ${TELNETPORT}" >> ${FHEM_DIR}/${CONFIGTYPE}
309+
fi
310+
311+
TELNETDEV="$(grep -P "^define .* telnet ${TELNETPORT}" ${FHEM_DIR}/${CONFIGTYPE} | head -1 | cut -d " " -f 2)"
312+
TELNETALLOWEDDEV="$(grep -P "^attr .* validFor .*${TELNETDEV}.*" ${FHEM_DIR}/${CONFIGTYPE} | head -1 | cut -d " " -f 2)"
313+
314+
## Enforce local telnet access w/o password
315+
if [ -n "$(grep -P "^attr ${TELNETALLOWEDDEV} password.*" ${FHEM_DIR}/${CONFIGTYPE})" ]; then
316+
if [ -n "$(grep -P "^attr ${TELNETALLOWEDDEV} globalpassword.*" ${FHEM_DIR}/${CONFIGTYPE})" ]; then
317+
echo " - Removed local password from Telnet allowed device '${TELNETALLOWEDDEV}'"
318+
sed -i "/attr ${TELNETALLOWEDDEV} password/d" ${FHEM_DIR}/${CONFIGTYPE}
319+
else
320+
echo " - Re-defined local password of Telnet allowed device '${TELNETALLOWEDDEV}' to global password"
321+
sed -i "s,attr ${TELNETALLOWEDDEV} password,attr ${TELNETALLOWEDDEV} globalpassword," ${FHEM_DIR}/${CONFIGTYPE}
322+
fi
323+
fi
324+
}
287325

288326
# Determine PID file
289327
#
@@ -763,6 +801,7 @@ function checkFhemProcessExists() {
763801
# Main steps in here:
764802
# - Run pre-start scripts
765803
# - Start printing the logfile to the console
804+
# - Create or patch Telnet Device for health check
766805
# - Launch FHEM process
767806
# - Run post-start scripts
768807
#
@@ -778,6 +817,8 @@ function startFhemProcess() {
778817
chown ${FHEM_UID}:${FHEM_GID} "$realLogFile"
779818
tailFileToConsoleStart "$realLogFile" # Start writing the logfile to the console
780819

820+
setTelnet_DEFINITION
821+
781822
umask ${UMASK}
782823
printfInfo "Starting FHEM\n"
783824
su fhem -c "cd ${FHEM_DIR} ; perl fhem.pl $CONFIGTYPE"
@@ -792,6 +833,8 @@ function startFhemProcess() {
792833
printfErr "Fatal: No message from FHEM that server has started.\n"
793834
exit 1
794835
fi
836+
837+
795838
printfInfo "FHEM successfully started\n"
796839

797840
runScript "/post-start.sh"

0 commit comments

Comments
 (0)