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"
2022-05-10 23:28:05 +00:00
readonly CONFIG_REGEX = "^(\;|\#)?\ *([a-zA-Z_0-9]+)=.*"
2022-05-16 22:37:28 +00:00
CONFIG_FILE = " ${ DATA_DIR } /mumble_server_config.ini "
2022-05-10 23:28:05 +00:00
2022-08-22 10:57:43 +00:00
readonly SENSITIVE_CONFIGS = (
"dbPassword"
"icesecretread"
"icesecretwrite"
"serverpassword"
"registerpassword"
"sslPassPhrase"
)
2022-05-10 23:28:05 +00:00
# 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-15 17:13:44 +00:00
# Grab the original command line that is supposed to start the Mumble server
declare -a server_invocation = ( " ${ @ } " )
declare -a used_configs
normalize_name( ) {
local uppercase = " ${ 1 ^^ } "
echo " ${ uppercase //_/ } "
}
2022-05-11 00:48:48 +00:00
# Create an associative array for faster config option lookup
2022-05-15 13:43:12 +00:00
declare -A option_for
2022-05-11 00:48:48 +00:00
for config in " ${ existing_config_options [@] } " ; do
2022-05-15 17:13:44 +00:00
option_for[ " $( normalize_name " $config " ) " ] = " $config "
2022-05-11 00:48:48 +00:00
done
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-08-22 10:57:43 +00:00
if array_contains "SENSITIVE_CONFIGS" " $config_name " ; then
echo " Setting config \" $config_name \" to: ********* "
else
echo " Setting config \" $config_name \" to: ' $config_value ' "
fi
2022-05-09 01:10:42 +00:00
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-12-04 20:40:37 +00:00
echo -e "# Config file automatically generated from the MUMBLE_CONFIG_* environment variables or secrets in /run/secrets/MUMBLE_CONFIG_* files\n" > " ${ CONFIG_FILE } "
2022-04-03 09:27:10 +00:00
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-15 17:13:44 +00:00
config_option = " ${ option_for [ $( normalize_name " $var " ) ] } "
2022-05-11 00:48:48 +00:00
if [ [ -z " $config_option " ] ] ; then
2022-06-30 15:56:15 +00:00
if [ [ " $MUMBLE_ACCEPT_UNKNOWN_SETTINGS " = true ] ] ; then
2022-06-30 16:01:29 +00:00
echo " [WARNING]: Unable to find config corresponding to variable \" $var \". Make sure that it is correctly spelled, using it as-is "
2022-06-30 15:56:15 +00:00
set_config " $var " " $value "
2022-06-30 16:01:29 +00:00
else
2022-06-30 15:56:15 +00:00
>& 2 echo " [ERROR]: Unable to find config corresponding to variable \" $var \" "
exit 1
fi
else
2022-06-30 16:01:29 +00:00
set_config " $config_option " " $value "
2022-04-03 09:27:10 +00:00
fi
2022-05-11 00:48:48 +00:00
2022-05-15 17:13:44 +00:00
done < <( printenv --null | sed -zn 's/^MUMBLE_CONFIG_//p' )
# ^ Feeding it in like this, prevents the creation of a subshell for the while-loop
2022-04-03 09:27:10 +00:00
2022-12-04 20:40:37 +00:00
# Check any docker/podman secrets matching the pattern and set config from there
while read -r var; do
config_option = " ${ option_for [ $( normalize_name " $var " ) ] } "
secret_file = " /run/secrets/MUMBLE_CONFIG_ $var "
if [ [ -z " $config_option " ] ] ; then
if [ [ " $MUMBLE_ACCEPT_UNKNOWN_SETTINGS " = true ] ] ; then
echo " [WARNING]: Unable to find config corresponding to container secret \" $secret_file \". Make sure that it is correctly spelled, using it as-is "
set_config " $var " " $value "
else
>& 2 echo " [ERROR]: Unable to find config corresponding to container secret \" $secret_file \" "
exit 1
fi
else
set_config " $config_option " " $( cat $secret_file ) "
fi
done < <( ls /run/secrets | sed -n 's/^MUMBLE_CONFIG_//p' )
2022-05-09 01:21:43 +00:00
# Apply default settings if they're missing
2022-09-14 20:13:59 +00:00
# Compatibilty with old DB filename
OLD_DB_FILE = " ${ DATA_DIR } /murmur.sqlite "
if [ [ -f " $OLD_DB_FILE " ] ] ; then
set_config "database" " $OLD_DB_FILE " true
else
set_config "database" " ${ DATA_DIR } /mumble-server.sqlite " true
fi
2022-04-03 09:27:10 +00:00
set_config "ice" "\"tcp -h 127.0.0.1 -p 6502\"" true
2022-09-15 21:06:35 +00:00
if ! array_contains "used_configs" "welcometextfile" ; then
set_config "welcometext" "\"<br />Welcome to this server, running the official Mumble Docker image.<br />Enjoy your stay!<br />\"" true
fi
2022-04-03 09:27:10 +00:00
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-12-04 20:40:37 +00:00
if [ [ -f /run/secrets/MUMBLE_SUPERUSER_PASSWORD ] ] ; then
#Variable to change the superuser password
" ${ server_invocation [@] } " -supw " $( cat /run/secrets/MUMBLE_SUPERUSER_PASSWORD) "
echo "Successfully configured superuser password from container secret"
elif [ [ -n " ${ MUMBLE_SUPERUSER_PASSWORD } " ] ] ; then
#Variable to change the superuser password
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 [@] } "