Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dubo-dubon-duponey committed Mar 18, 2024
1 parent 763b209 commit 2e3df60
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ EXPOSE 9003/udp
VOLUME /music

ENV _SERVICE_NICK="roon"
ENV _SERVICE_TYPE="http"
ENV _SERVICE_TYPE="_http._tcp"

COPY --from=assembly --chown=$BUILD_UID:root /dist /

Expand Down Expand Up @@ -306,7 +306,7 @@ ENV MOD_HTTP_TLS_MODE="internal"
# Advanced settings
#####
# Service type
ENV ADVANCED_MOD_MDNS_TYPE="_$_SERVICE_TYPE._tcp"
ENV ADVANCED_MOD_MDNS_TYPE="$_SERVICE_TYPE"
# Also announce the service as a workstation (for example for the benefit of coreDNS mDNS)
ENV ADVANCED_MOD_MDNS_STATION=true
# Root certificate to trust for client cert verification
Expand Down
47 changes: 34 additions & 13 deletions context/runtime/boot/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,47 @@ if [ ! -e /boot/bin/RoonServer/Server/RoonServer ]; then
exit
fi

helpers::dir::writable "/certs"
[ "${MOD_HTTP_ENABLED:-}" != true ] && [ "${MOD_TLS_ENABLED:-}" != true ] || {
helpers::dir::writable "/certs"
}

helpers::dir::writable "$XDG_RUNTIME_DIR" create
helpers::dir::writable "$XDG_STATE_HOME" create
helpers::dir::writable "$XDG_CACHE_HOME" create

# mDNS
[ "${MOD_MDNS_ENABLED:-}" != true ] || {
_mdns_type="${ADVANCED_MOD_MDNS_TYPE:-_http._tcp}"
_mdns_port="$([ "${MOD_HTTP_TLS_ENABLED:-}" == true ] && printf "%s" "${ADVANCED_MOD_HTTP_PORT:-443}" || printf "%s" "${ADVANCED_MOD_HTTP_PORT_INSECURE:-80}")"
[ "${ADVANCED_MOD_MDNS_STATION:-}" != true ] || mdns::records::add "_workstation._tcp" "${MOD_MDNS_HOST}" "${MOD_MDNS_NAME:-}" "$_mdns_port"
mdns::records::add "$_mdns_type" "${MOD_MDNS_HOST:-}" "${MOD_MDNS_NAME:-}" "$_mdns_port"
mdns::start::broadcaster
}
# HTTP helpers
if [ "$MOD_HTTP_ENABLED" == true ]; then
case "${1:-}" in
# Short hand helper to generate password hash
"hash")
shift
http::hash "$@"
exit
;;
# Helper to get the ca.crt out (once initialized)
"cert")
shift
http::certificate "${MOD_HTTP_TLS_MODE:-internal}" "$@"
exit
;;
esac
http::start &
fi

# TLS and HTTP
[ "${MOD_HTTP_ENABLED:-}" != true ] || http::start &
[ "${MOD_MDNS_ENABLED:-}" != true ] || \
mdns::start::default \
"${MOD_MDNS_HOST:-}" \
"${MOD_MDNS_NAME:-}" \
"${MOD_HTTP_ENABLED:-}" \
"${MOD_HTTP_TLS_ENABLED:-}" \
"${MOD_TLS_ENABLED:-}" \
"${ADVANCED_MOD_MDNS_STATION:-}" \
"${ADVANCED_MOD_MDNS_TYPE:-}" \
"${ADVANCED_MOD_HTTP_PORT:-}" \
"${ADVANCED_MOD_HTTP_PORT_INSECURE:-}" \
"${ADVANCED_MOD_TLS_PORT:-}"

# error”, “critical”, “warning”, “message”, “info”, and “debug”
# Looks like ROON ignore these
#MONO_LOG_LEVEL="$(printf "%s" "${LOG_LEVEL:-error}" | tr '[:upper:]' '[:lower:]' | sed -E 's/^(warn)$/warning/')"
#export MONO_LOG_LEVEL

exec /boot/bin/RoonServer/Server/RoonServer "$@"
30 changes: 28 additions & 2 deletions context/runtime/boot/mdns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ mdns::records::resolve(){
printf "%s %s" "$server" "$port"
}

mdns::start::default(){
local host="${1:-}"
local name="${2:-}"
local with_http_proxy="${3:-}"
local with_http_proxy_https="${4:-}"
local with_tls_proxy="${5:-}"
local with_station="${6:-}"
local type="${7:-}"

local http_proxy_https_port="${7:-443}"
local http_proxy_http_port="${8:-80}"
local tls_proxy_port="${9:-443}"

local port="$tls_proxy_port"

[ "$with_http_proxy" != true ] || {
port="$([ "$with_http_proxy_https" == true ] && printf "%s" "$http_proxy_https_port" || printf "%s" "$http_proxy_http_port")"
type="${type:-_http._tcp}"
}
[ "$with_tls_proxy" != true ] || type="${type:-_tls._tcp}"

mdns::records::add "$type" "$host" "$name" "$port"
[ "$with_station" != true ] || mdns::records::add "_workstation._tcp" "$host" "$name" "$port"
mdns::start::broadcaster
}

mdns::start::broadcaster(){
[ ! -e "$_default_mod_mdns_configuration_path" ] || mdns::records::load "$_default_mod_mdns_configuration_path"
local IFS=","
Expand Down Expand Up @@ -83,10 +109,10 @@ mdns::start::dbus(){
# https://man7.org/linux/man-pages/man3/sd_bus_default.3.html
# https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html

# $XDG_STATE_HOME=/tmp/state
# $XDG_RUNTIME_DIR=/tmp/runtime
# Configuration file also has that ^ hardcoded, so, cannot use the variable...

local dbussocket=/tmp/state/dbus/system_bus_socket
local dbussocket=/tmp/runtime/dbus/system_bus_socket

# Ensure directory exists
helpers::dir::writable "$(dirname "$dbussocket")" create
Expand Down

0 comments on commit 2e3df60

Please sign in to comment.