Skip to content

Commit 037f49d

Browse files
authored
By default, use RCON password from rcon-cli.env (#134)
1 parent 18b236f commit 037f49d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

backup-loop.sh

+22-22
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,28 @@ fi
2222
: "${SERVER_PORT:=25565}"
2323
: "${RCON_HOST:=localhost}"
2424
: "${RCON_PORT:=25575}"
25-
: "${RCON_PASSWORD_FILE:=}"
26-
: "${RCON_PASSWORD:=minecraft}"
25+
26+
if ! [[ -v RCON_PASSWORD ]] && ! [[ -v RCON_PASSWORD_FILE ]] && [[ -f "${SRC_DIR}/.rcon-cli.env" ]]; then
27+
. "${SRC_DIR}/.rcon-cli.env"
28+
# shellcheck disable=SC2154
29+
# since it comes from rcon-cli
30+
RCON_PASSWORD="$password"
31+
elif [[ -v RCON_PASSWORD_FILE ]]; then
32+
if [ ! -e "${RCON_PASSWORD_FILE}" ]; then
33+
log ERROR "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
34+
log ERROR "Please ensure your configuration."
35+
log ERROR "If you are using Docker Secrets feature, please check this for further information: "
36+
log ERROR " https://docs.docker.com/engine/swarm/secrets"
37+
exit 1
38+
else
39+
RCON_PASSWORD=$(cat "${RCON_PASSWORD_FILE}")
40+
fi
41+
elif ! [[ -v RCON_PASSWORD ]]; then
42+
# Legacy default
43+
RCON_PASSWORD=minecraft
44+
fi
45+
export RCON_PASSWORD
46+
2747
: "${RCON_RETRIES:=5}"
2848
: "${RCON_RETRY_INTERVAL:=10s}"
2949
: "${EXCLUDES:=*.jar,cache,logs}" # Comma separated list of glob(3) patterns
@@ -49,7 +69,6 @@ export TZ
4969

5070
export RCON_HOST
5171
export RCON_PORT
52-
export RCON_PASSWORD
5372
export XDG_CONFIG_HOME
5473
export SRC_DIR
5574
export DEST_DIR
@@ -383,25 +402,6 @@ rclone() {
383402
## main ##
384403
##########
385404

386-
if [[ $RCON_PASSWORD_FILE ]]; then
387-
if [ ! -e ${RCON_PASSWORD_FILE} ]; then
388-
log ERROR "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
389-
log ERROR "Please ensure your configuration."
390-
log ERROR "If you are using Docker Secrets feature, please check this for further information: "
391-
log ERROR " https://docs.docker.com/engine/swarm/secrets"
392-
exit 1
393-
else
394-
RCON_PASSWORD=$(cat ${RCON_PASSWORD_FILE})
395-
export RCON_PASSWORD
396-
fi
397-
fi
398-
399-
if [[ $PRE_SAVE_ALL_SCRIPT ]]; then
400-
PRE_SAVE_ALL_SCRIPT_FILE=/tmp/pre-save-all
401-
printf '#!/bin/bash\n\n%s' "$PRE_SAVE_ALL_SCRIPT" > "$PRE_SAVE_ALL_SCRIPT_FILE"
402-
chmod 700 "$PRE_SAVE_ALL_SCRIPT_FILE"
403-
fi
404-
405405
if [[ $PRE_BACKUP_SCRIPT ]]; then
406406
PRE_BACKUP_SCRIPT_FILE=/tmp/pre-backup
407407
printf '#!/bin/bash\n\n%s' "$PRE_BACKUP_SCRIPT" > "$PRE_BACKUP_SCRIPT_FILE"

0 commit comments

Comments
 (0)