Skip to content

Commit

Permalink
Prefer ip over iface for the select network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 committed Mar 11, 2024
1 parent 026430a commit 05b56af
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion app/bin/install-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

apt-get update
apt-get install -y wget unzip libssl-dev
apt-get install -y iproute2
apt-get install -y iproute2
apt-get install -y net-tools
36 changes: 20 additions & 16 deletions app/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"]"
Expand Down

0 comments on commit 05b56af

Please sign in to comment.