2022-04-03 09:27:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2022-05-09 01:30:17 +00:00
|
|
|
readonly DATA_DIR="/data"
|
|
|
|
readonly BARE_BONES_CONFIG_FILE="/etc/mumble/bare_config.ini"
|
|
|
|
readonly CONFIG_FILE="${DATA_DIR}/mumble_server_config.ini"
|
2022-05-10 23:28:05 +00:00
|
|
|
readonly CONFIG_REGEX="^(\;|\#)?\ *([a-zA-Z_0-9]+)=.*"
|
|
|
|
|
|
|
|
# Compile list of configuration options from the bare-bones config
|
|
|
|
readarray -t existing_config_options < <(sed -En "s/$CONFIG_REGEX/\2/p" "$BARE_BONES_CONFIG_FILE")
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-11 00:31:06 +00:00
|
|
|
# Grab the original command line that is supposed to start the Mumble server
|
2022-05-09 01:30:17 +00:00
|
|
|
declare -a server_invocation=("${@}")
|
|
|
|
declare -a used_configs
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-09 01:10:42 +00:00
|
|
|
array_contains() {
|
|
|
|
local array_expansion="$1[@]" seeking="$2"
|
|
|
|
for element in "${!array_expansion}"; do
|
|
|
|
[[ "$element" = "$seeking" ]] && return 0
|
2022-04-03 09:27:10 +00:00
|
|
|
done
|
2022-05-09 01:10:42 +00:00
|
|
|
return 1
|
2022-04-03 09:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_config() {
|
2022-05-09 01:10:42 +00:00
|
|
|
local config_name="$1" config_value="$2" is_default="$3"
|
2022-04-03 09:27:10 +00:00
|
|
|
local apply_value=true
|
|
|
|
|
2022-05-09 01:10:42 +00:00
|
|
|
[[ "$is_default" = true ]] && array_contains "used_configs" "$config_name" && \
|
|
|
|
apply_value=false # Don't use default value if the user already set one!
|
|
|
|
|
|
|
|
[[ "$apply_value" != true ]] && return 0
|
2022-05-09 00:13:03 +00:00
|
|
|
|
2022-05-09 01:10:42 +00:00
|
|
|
echo "Setting config \"$config_name\" to: '$config_value'"
|
|
|
|
used_configs+=("$config_name")
|
2022-05-09 00:13:03 +00:00
|
|
|
|
2022-05-09 01:10:42 +00:00
|
|
|
# Append config to our on-the-fly-built config file
|
|
|
|
echo "${config_name}=${config_value}" >> "$CONFIG_FILE"
|
2022-04-03 09:27:10 +00:00
|
|
|
}
|
2022-05-09 00:13:03 +00:00
|
|
|
|
2022-04-03 09:27:10 +00:00
|
|
|
# Drop the user into a shell, if they so wish
|
2022-05-09 00:07:09 +00:00
|
|
|
if [[ "$1" = "bash" || "$1" = "sh" ]]; then
|
2022-04-03 09:27:10 +00:00
|
|
|
echo "Dropping into interactive BASH session"
|
|
|
|
exec "${@}"
|
|
|
|
fi
|
|
|
|
|
2022-05-09 00:07:09 +00:00
|
|
|
if [[ -f "$MUMBLE_CUSTOM_CONFIG_FILE" ]]; then
|
2022-04-03 09:27:10 +00:00
|
|
|
echo "Using manually specified config file at $MUMBLE_CUSTOM_CONFIG_FILE"
|
|
|
|
echo "All MUMBLE_CONFIG variables will be ignored"
|
|
|
|
CONFIG_FILE="$MUMBLE_CUSTOM_CONFIG_FILE"
|
|
|
|
else
|
2022-05-11 00:31:06 +00:00
|
|
|
# Ensures the config file is empty, starting from a clean slate
|
2022-04-03 09:27:10 +00:00
|
|
|
echo -e "# Config file automatically generated from the MUMBLE_CONFIG_* environment variables\n" > "${CONFIG_FILE}"
|
|
|
|
|
2022-05-09 01:21:43 +00:00
|
|
|
# Process settings through variables of format MUMBLE_CONFIG_*
|
|
|
|
|
2022-04-03 09:27:10 +00:00
|
|
|
while IFS='=' read -d '' -r var value; do
|
2022-05-11 00:31:06 +00:00
|
|
|
# MUMBLE_CONFIG_DB_BLA and MUMBLE_CONFIG_DBBLA mean the same
|
2022-05-08 23:53:47 +00:00
|
|
|
uppercase_variable=${var/MUMBLE_CONFIG_/}
|
|
|
|
uppercase_variable_no_underscores="${uppercase_variable//_/}"
|
|
|
|
found=false
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-08 23:53:47 +00:00
|
|
|
for current_config in "${existing_config_options[@]}"; do
|
2022-05-11 00:31:06 +00:00
|
|
|
uppercase_current_config=${current_config^^}
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-11 00:31:06 +00:00
|
|
|
if [[ "$uppercase_current_config" = "$uppercase_variable" || "$uppercase_current_config" = "$uppercase_variable_no_underscores" ]]; then
|
2022-05-08 23:53:47 +00:00
|
|
|
set_config "$current_config" "$value"
|
|
|
|
found=true
|
|
|
|
break
|
2022-04-03 09:27:10 +00:00
|
|
|
fi
|
2022-05-08 23:53:47 +00:00
|
|
|
done
|
|
|
|
|
2022-05-09 00:07:09 +00:00
|
|
|
if [[ "$found" = "false" ]]; then
|
2022-05-08 23:53:47 +00:00
|
|
|
>&2 echo "[ERROR]: Unable to find config corresponding to variable \"$var\""
|
|
|
|
exit 1
|
2022-04-03 09:27:10 +00:00
|
|
|
fi
|
2022-05-08 23:53:47 +00:00
|
|
|
done < <( printenv --null | grep -az MUMBLE_CONFIG_ ) # Feeding it in like this, prevents the creation of a subshell for the while-loop
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-09 01:21:43 +00:00
|
|
|
# Apply default settings if they're missing
|
|
|
|
|
2022-04-03 09:27:10 +00:00
|
|
|
set_config "database" "${DATA_DIR}/murmur.sqlite" true
|
|
|
|
set_config "ice" "\"tcp -h 127.0.0.1 -p 6502\"" true
|
|
|
|
set_config "welcometext" "\"<br />Welcome to this server, running the official Mumble Docker image.<br />Enjoy your stay!<br />\"" true
|
|
|
|
set_config "port" 64738 true
|
|
|
|
set_config "users" 100 true
|
|
|
|
|
2022-05-09 01:38:25 +00:00
|
|
|
{ # Add ICE section
|
|
|
|
echo -e "\n[Ice]"
|
|
|
|
echo "Ice.Warn.UnknownProperties=1"
|
|
|
|
echo "Ice.MessageSizeMax=65536"
|
|
|
|
} >> "$CONFIG_FILE"
|
2022-04-03 09:27:10 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-09 01:21:43 +00:00
|
|
|
# Additional environment variables
|
|
|
|
|
2022-05-09 00:22:01 +00:00
|
|
|
[[ "$MUMBLE_VERBOSE" = true ]] && server_invocation+=( "-v" )
|
2022-04-03 09:27:10 +00:00
|
|
|
|
2022-05-11 00:31:06 +00:00
|
|
|
# Make sure the correct configuration file is used
|
2022-04-03 09:27:10 +00:00
|
|
|
server_invocation+=( "-ini" "${CONFIG_FILE}")
|
|
|
|
|
2022-05-11 00:31:06 +00:00
|
|
|
# Variable to change the superuser password
|
2022-05-09 00:07:09 +00:00
|
|
|
if [[ -n "${MUMBLE_SUPERUSER_PASSWORD}" ]]; then
|
2022-04-03 09:27:10 +00:00
|
|
|
"${server_invocation[@]}" -supw "$MUMBLE_SUPERUSER_PASSWORD"
|
|
|
|
echo "Successfully configured superuser password"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Show /data permissions, in case the user needs to match the mount point access
|
|
|
|
echo "Running Mumble server as uid=$(id -u) gid=$(id -g)"
|
|
|
|
echo "\"${DATA_DIR}\" has the following permissions set:"
|
|
|
|
echo " $( stat ${DATA_DIR} --printf='%A, owner: \"%U\" (UID: %u), group: \"%G\" (GID: %g)' )"
|
|
|
|
|
2022-05-09 01:38:25 +00:00
|
|
|
echo "Command run to start the service : ${server_invocation[*]}"
|
2022-04-03 09:27:10 +00:00
|
|
|
echo "Starting..."
|
|
|
|
|
|
|
|
exec "${server_invocation[@]}"
|