2020-05-25 15:20:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-14 00:42:00 +00:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
|
|
|
|
|
|
|
: "${SERVER_PORT:=25565}"
|
2022-04-10 15:58:18 +00:00
|
|
|
: "${ENABLE_AUTOPAUSE:=false}"
|
|
|
|
: "${AUTOPAUSE_TIMEOUT_EST:=3600}"
|
|
|
|
: "${AUTOPAUSE_TIMEOUT_KN:=120}"
|
|
|
|
: "${AUTOPAUSE_TIMEOUT_INIT:=600}"
|
|
|
|
: "${AUTOPAUSE_PERIOD:=10}"
|
|
|
|
: "${AUTOPAUSE_KNOCK_INTERFACE:=eth0}"
|
2022-07-30 17:06:22 +00:00
|
|
|
: "${DEBUG_AUTOPAUSE:=false}"
|
2021-11-14 00:42:00 +00:00
|
|
|
export SERVER_PORT
|
2022-04-10 15:58:18 +00:00
|
|
|
export ENABLE_AUTOPAUSE
|
|
|
|
export AUTOPAUSE_TIMEOUT_EST
|
|
|
|
export AUTOPAUSE_TIMEOUT_KN
|
|
|
|
export AUTOPAUSE_TIMEOUT_INIT
|
|
|
|
export AUTOPAUSE_PERIOD
|
|
|
|
export AUTOPAUSE_KNOCK_INTERFACE
|
2022-07-30 17:06:22 +00:00
|
|
|
export DEBUG_AUTOPAUSE
|
2020-05-25 15:20:14 +00:00
|
|
|
|
|
|
|
log "Autopause functionality enabled"
|
|
|
|
|
2021-11-14 00:42:00 +00:00
|
|
|
isDebugging && set -x
|
|
|
|
|
2022-09-03 21:48:14 +00:00
|
|
|
cp /auto/knockd-config.cfg /tmp/knockd-config.cfg
|
2020-07-26 18:22:07 +00:00
|
|
|
|
2020-05-25 15:20:14 +00:00
|
|
|
# update server port to listen to
|
|
|
|
regseq="^\s*sequence\s*=\s*$SERVER_PORT\s*$"
|
2020-07-26 18:22:07 +00:00
|
|
|
linenum=$(grep -nm1 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
|
|
|
|
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
|
|
|
|
sed -i "${linenum}s/sequence.*/sequence = $SERVER_PORT/" /tmp/knockd-config.cfg
|
2020-05-25 15:20:14 +00:00
|
|
|
log "Updated server port in knockd config"
|
|
|
|
fi
|
|
|
|
# update rcon port to listen to
|
|
|
|
regseq="^\s*sequence\s*=\s*$RCON_PORT\s*$"
|
2020-07-26 18:22:07 +00:00
|
|
|
linenum=$(grep -nm2 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
|
|
|
|
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
|
|
|
|
sed -i "${linenum}s/sequence.*/sequence = $RCON_PORT/" /tmp/knockd-config.cfg
|
2020-05-25 15:20:14 +00:00
|
|
|
log "Updated rcon port in knockd config"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [[ $AUTOPAUSE_PERIOD =~ ^[0-9]+$ ]]; then
|
|
|
|
AUTOPAUSE_PERIOD=10
|
|
|
|
export AUTOPAUSE_PERIOD
|
|
|
|
log "Warning: AUTOPAUSE_PERIOD is not numeric, set to 10 (seconds)"
|
|
|
|
fi
|
|
|
|
if [ "$AUTOPAUSE_PERIOD" -eq "0" ] ; then
|
|
|
|
AUTOPAUSE_PERIOD=10
|
|
|
|
export AUTOPAUSE_PERIOD
|
|
|
|
log "Warning: AUTOPAUSE_PERIOD must not be 0, set to 10 (seconds)"
|
|
|
|
fi
|
|
|
|
if ! [[ $AUTOPAUSE_TIMEOUT_KN =~ ^[0-9]+$ ]] ; then
|
|
|
|
AUTOPAUSE_TIMEOUT_KN=120
|
|
|
|
export AUTOPAUSE_TIMEOUT_KN
|
|
|
|
log "Warning: AUTOPAUSE_TIMEOUT_KN is not numeric, set to 120 (seconds)"
|
|
|
|
fi
|
|
|
|
if ! [[ $AUTOPAUSE_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
|
|
|
|
AUTOPAUSE_TIMEOUT_EST=3600
|
|
|
|
export AUTOPAUSE_TIMEOUT_EST
|
|
|
|
log "Warning: AUTOPAUSE_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
|
|
|
|
fi
|
|
|
|
if ! [[ $AUTOPAUSE_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
|
|
|
|
AUTOPAUSE_TIMEOUT_INIT=600
|
|
|
|
export AUTOPAUSE_TIMEOUT_INIT
|
|
|
|
log "Warning: AUTOPAUSE_TIMEOUT_INIT is not numeric, set to 600 (seconds)"
|
|
|
|
fi
|
2021-01-02 17:27:03 +00:00
|
|
|
if [[ "$AUTOPAUSE_KNOCK_INTERFACE" == "lo" ]] ; then
|
|
|
|
log "Warning: AUTOPAUSE_KNOCK_INTERFACE is set to the local loopback interface."
|
|
|
|
log " This is not advisable, as incoming connections are likely not picked up there."
|
|
|
|
log " Continuing with this setting."
|
|
|
|
fi
|
2020-05-25 15:20:14 +00:00
|
|
|
|
2021-01-02 17:27:03 +00:00
|
|
|
if [[ -n "$MAX_TICK_TIME" && "$MAX_TICK_TIME" != "-1" ]] ; then
|
2020-05-25 15:20:14 +00:00
|
|
|
log "Warning: MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
|
2021-01-02 17:27:03 +00:00
|
|
|
elif [[ -z "$MAX_TICK_TIME" ]] ; then
|
2020-05-25 15:20:14 +00:00
|
|
|
if versionLessThan 1.8.1; then
|
|
|
|
# 10 years
|
|
|
|
MAX_TICK_TIME=315360000000
|
|
|
|
else
|
|
|
|
MAX_TICK_TIME=-1
|
|
|
|
fi
|
|
|
|
export MAX_TICK_TIME
|
|
|
|
fi
|
|
|
|
|
2023-03-12 18:40:35 +00:00
|
|
|
# seq_cooldown cannot be larger than AUTOPAUSE_TIMEOUT_KN, otherwise the server may
|
|
|
|
# become paused while knockd is still ignoring packets, preventing players from joining.
|
|
|
|
let COOLDOWN=$AUTOPAUSE_TIMEOUT_KN/2
|
|
|
|
sed -i "s/\(seq_cooldown *= *\).*/\1$COOLDOWN/" /tmp/knockd-config.cfg
|
|
|
|
|
2022-09-03 21:48:14 +00:00
|
|
|
/auto/autopause-daemon.sh &
|