Docker container behind radio.jerryaldrichiii.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
2.4 KiB

#!/bin/sh
set -e
set_val() {
# Combine args in case there are spaces
# https://linux.die.net/man/1/ash
val="${@#$1 }" # Remove smallest prefix pattern (space after $1 intentional)
sed -i "s/<$1>[^<]*<\/$1>/<$1>$val<\/$1>/g" /etc/icecast/icecast.xml
}
# The below will replace values in the config with the ENV variable specified.
# If one is not specified, what follows ':-' will be used.
# NOTE: The order below matches the order seen in the config.
set_val location ${ICECAST_LOCATION:-San Francisco}
set_val admin ${ICECAST_ADMIN:-Someone Failed to Change Me}
set_val clients ${ICECAST_LIMITS_CLIENTS:-100}
set_val sources ${ICECAST_LIMITS_SOURCES:-2}
set_val queue-size ${ICECAST_LIMITS_QUEUE_SIZE:-524288}
set_val client-timeout ${ICECAST_LIMITS_CLIENT_TIMEOUT:-30}
set_val header-timeout ${ICECAST_LIMITS_HEADER_TIMEOUT:-14}
set_val source-timeout ${ICECAST_LIMITS_SOURCE_TIMEOUT:-10}
set_val burst-on-connect ${ICECAST_LIMITS_BURST_ON_CONNECT:-1}
set_val burst-size ${ICECAST_LIMITS_BURST_SIZE:-65535}
set_val fileserve ${ICECAST_FILESERVE:-1}
set_val source-password ${AUTHENTICATION_SOURCE_PASSWORD:-changeorbehacked}
set_val relay-password ${AUTHENTICATION_RELAY_PASSWORD:-changeorbehacked}
set_val admin-user ${AUTHENTICATION_ADMIN_USERNAME:-changeorbehacked}
set_val admin-password ${AUTHENTICATION_ADMIN_PASSWORD:-changeorbehacked}
set_val relays-on-demand ${RELAYS_ON_DEMAND:-1}
set_val loglevel ${LOG_LEVEL:-3}
set_val logsize ${LOG_SIZE:-10000}
set_val logarchive ${LOG_ARCHIVE:-0}
# Build relay XML sections
CONFIG="$(cat /bootstrap/config.json)"
for stream in $(echo "$CONFIG" | jq -r '.streams[] | @base64'); do
_parse() {
echo ${stream} | base64 -d | jq -r ${1}
}
RELAY_XML=$(cat <<-EOX
$RELAY_XML
<relay>
<server>$(_parse .server)</server>
<port>$(_parse .port)</port>
<mount>$(_parse .mount)</mount>
<local-mount>$(_parse .local_mount)</local-mount>
<relay-shoutcast-metadata>1</relay-shoutcast-metadata>
</relay>
EOX
)
done
# Set hostname (needs to match for listen urls and such)
host=$(echo "$CONFIG" | jq -r '.hostname')
set_val hostname ${ICECAST_HOSTNAME:-$host}
# Using | as the delimiter because of URLs containing /
sed -i "s|ICECAST_RELAYS|$(echo "$RELAY_XML" | tr "\n" "#")|g;s/#/\n/g" /etc/icecast/icecast.xml
# Publish config.json for consumers (e.g. web player)
cp /bootstrap/config.json /usr/share/icecast/web/
icecast -c "/etc/icecast/icecast.xml"