From 05b56af97223eb5f1abd63086ed6e57d9eaccabe Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 11 Mar 2024 10:25:20 +0100 Subject: [PATCH] Prefer ip over iface for the select network interface --- Dockerfile | 15 +++++++++------ README.md | 8 +++++--- app/bin/install-pkg.sh | 3 ++- app/bin/run.sh | 36 ++++++++++++++++++++---------------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87a2564..4a3fa93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,15 +24,17 @@ RUN chmod u+x /app/bin/cleanup.sh RUN /app/bin/cleanup.sh RUN rm /app/bin/cleanup.sh -COPY app/bin/run.sh /app/bin -RUN chmod 755 /app/bin/run.sh - FROM scratch COPY --from=BASE / / LABEL maintainer="GioF71" LABEL source="https://github.com/GioF71/spotconnect-docker" +RUN mkdir -p /app/bin + +COPY app/bin/run.sh /app/bin +RUN chmod 755 /app/bin/run.sh + ENV PUID "" ENV PGID "" ENV PREFER_STATIC "" @@ -46,9 +48,10 @@ ENV LOG_LEVEL_UTIL "" ENV LOG_LEVEL_UPNP "" ENV LOG_LEVEL_RAOP "" -ENV AUTO_NETWORK_IFACE_URL "" -ENV ENABLE_AUTO_NETWORK_IFACE "" -ENV NETWORK_IFACE "" +ENV AUTO_NETWORK_URL "" +ENV ENABLE_AUTO_NETWORK "" +ENV NETWORK_SELECT "" +ENV NETWORK_USE_IP "" VOLUME /config diff --git a/README.md b/README.md index e11c9f5..376523f 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,10 @@ LOG_LEVEL_MAIN|Enables log of type `main` using the provided value LOG_LEVEL_UTIL|Enables log of type `util` using the provided value LOG_LEVEL_UPNP|Enables log of type `upnp` using the provided value LOG_LEVEL_RAOP|Enables log of type `raop` using the provided value -ENABLE_AUTO_NETWORK_IFACE|Allows to automatically set NETWORK_IFACE, defaults to `yes`, but this does not override an explicitly set `NETWORK_IFACE` variable anyway -NETWORK_IFACE|Sets the network interface -AUTO_NETWORK_IFACE_URL|Used for selecting iface, defaults to `1.1.1.1` +ENABLE_AUTO_NETWORK|Allows to automatically set NETWORK_SELECT, defaults to `yes`, but this does not override an explicitly set `NETWORK_SELECT` variable anyway +NETWORK_SELECT|Sets the network interface or ip and optionally port +AUTO_NETWORK_URL|Used for selecting the network to use, defaults to `1.1.1.1` +NETWORK_USE_IP|Use ip instead of network card for `-b`, defaults to `yes` ## Run @@ -105,6 +106,7 @@ The changelog of the upstream project is available [here](https://github.com/phi DATE|DESCRIPTION :---|:--- +2024-03-11|Prefer ip over iface for the select network interface 2024-03-09|Auto select network interface (see [#3](https://github.com/GioF71/spotconnect-docker/issues/3)) 2024-03-06|Bump to version [0.9.2](https://github.com/philippe44/SpotConnect/releases/tag/0.9.2) 2024-01-26|Add support for log level of type `raop` diff --git a/app/bin/install-pkg.sh b/app/bin/install-pkg.sh index 876b14d..4922058 100644 --- a/app/bin/install-pkg.sh +++ b/app/bin/install-pkg.sh @@ -2,4 +2,5 @@ apt-get update apt-get install -y wget unzip libssl-dev -apt-get install -y iproute2 \ No newline at end of file +apt-get install -y iproute2 +apt-get install -y net-tools diff --git a/app/bin/run.sh b/app/bin/run.sh index 8e1b4a6..6cace27 100644 --- a/app/bin/run.sh +++ b/app/bin/run.sh @@ -132,27 +132,31 @@ else CMD_LINE="$CMD_LINE -x /config/$CONFIG_FILE_NAME -I -j -k -Z" fi -echo "NETWORK_IFACE=${NETWORK_IFACE}" -upnp_iface="${NETWORK_IFACE}" -if [[ -z "${upnp_iface}" ]]; then - echo "ENABLE_AUTO_NETWORK_IFACE=[${ENABLE_AUTO_NETWORK_IFACE}]" - if [[ -z "${ENABLE_AUTO_NETWORK_IFACE}" ]] || [[ "${ENABLE_AUTO_NETWORK_IFACE^^}" == "YES" ]] || [[ "${ENABLE_AUTO_NETWORK_IFACE^^}" == "Y" ]]; then - echo "Automatically setting upnp_iface ..." - auto_upnpiface_url="${AUTO_NETWORK_IFACE_URL}" - if [[ -z "${auto_upnpiface_url}" ]]; then - auto_upnpiface_url=1.1.1.1 +echo "NETWORK_SELECT=${NETWORK_SELECT}" +select_network="${NETWORK_SELECT}" +if [[ -z "${select_network}" ]]; then + echo "ENABLE_AUTO_NETWORK=[${ENABLE_AUTO_NETWORK}]" + if [[ -z "${ENABLE_AUTO_NETWORK}" ]] || [[ "${ENABLE_AUTO_NETWORK^^}" == "YES" ]] || [[ "${ENABLE_AUTO_NETWORK^^}" == "Y" ]]; then + echo "Automatically setting network ..." + auto_network_url="${AUTO_NETWORK_URL}" + if [[ -z "${auto_network_url}" ]]; then + auto_network_url=1.1.1.1 fi - upnp_iface=$(ip route get $auto_upnpiface_url | grep -oP 'dev\s+\K[^ ]+') - #select_ip=$(ifconfig $iface | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') - echo "Automatically setting upnp_iface [Done]" - CMD_LINE="$CMD_LINE -b ${upnp_iface}" - elif [[ "${ENABLE_AUTO_NETWORK_IFACE^^}" != "NO" ]] && [[ "${ENABLE_AUTO_NETWORK_IFACE^^}" != "N" ]]; then - echo "Invalid ENABLE_AUTO_NETWORK_IFACE=[${ENABLE_AUTO_NETWORK_IFACE}]" + select_network=$(ip route get $auto_network_url | grep -oP 'dev\s+\K[^ ]+') + select_ip=$(ifconfig $select_network | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') + chosen_network_argument="${select_network}" + if [[ -z "${NETWORK_USE_IP}" ]] || [[ "${NETWORK_USE_IP^^}" == "YES" ]] || [[ "${NETWORK_USE_IP^^}" == "Y" ]]; then + chosen_network_argument="${select_ip}" + fi + echo "Automatically setting network [Done]" + CMD_LINE="$CMD_LINE -b ${chosen_network_argument}" + elif [[ "${ENABLE_AUTO_NETWORK^^}" != "NO" ]] && [[ "${ENABLE_AUTO_NETWORK^^}" != "N" ]]; then + echo "Invalid ENABLE_AUTO_NETWORK=[${ENABLE_AUTO_NETWORK}]" exit 1 fi else # use provided iface - CMD_LINE="$CMD_LINE -b ${upnp_iface}" + CMD_LINE="$CMD_LINE -b ${select_network}" fi echo "Command Line: ["$CMD_LINE"]"