Skip to content

Commit

Permalink
Automatically set upnpip instead of upnpiface #379 (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 committed Mar 5, 2024
1 parent cae1eb0 commit e17ef48
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ RUN if [ "$BUILD_MODE" = "full" ]; then \
apt-get install -y git; \
fi

RUN apt-get install -y net-tools

RUN apt-get remove -y software-properties-common

RUN apt-get -y autoremove
Expand Down Expand Up @@ -103,6 +105,7 @@ ENV PORT_OFFSET ""
ENV AUTO_UPNPIFACE_URL ""
ENV ENABLE_AUTO_UPNPIFACE ""
ENV UPNPIFACE ""
ENV UPNPIP ""
ENV UPNPPORT ""

ENV OWN_QUEUE ""
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ MPD_PORT|The port used by mpd, defaults to `6600`
UPRCL_HOSTPORT|Set if we own the MPD queue, defaults to `1`, possible values `1` and `0`
PORT_OFFSET|If set, the offset is applied to the default for `UPNP_PORT` (summed) and to the default `PLG_MICRO_HTTP_PORT` (subtracted). Setting this variable overrides these individual variables.
UPNPIFACE|UPnP network interface
ENABLE_AUTO_UPNPIFACE|Allows to automatically set UPNPIFACE, defaults to `yes`, but this does not override an explicitly set `UPNPIFACE` variable
AUTO_UPNPIFACE_URL|Used by `ENABLE_AUTO_UPNPIFACE`, defaults to `1.1.1.1`
CHECK_CONTENT_FORMAT|Set to `yes` to enable, see [here](https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-manual.html#checkcontentformat)
UPNPIP|IP V4 address to use for UPnP, alternative to using an interface name.
UPNPPORT|UPnP port
AUTO_UPNPIFACE_URL|Used by `ENABLE_AUTO_UPNPIFACE` and `ENABLE_AUTO_UPNPIP`, defaults to `1.1.1.1`
ENABLE_AUTO_UPNPIFACE|Allows to automatically set UPNPIFACE, defaults to `no`, but this does not override an explicitly set `UPNPIFACE` variable anyway
ENABLE_AUTO_UPNPIP|Allows to automatically set UPNPIP, defaults to `yes`, but this does not override an explicitly set `UPNPIP` variable anyway
CHECK_CONTENT_FORMAT|Set to `yes` to enable, see [here](https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-manual.html#checkcontentformat)
UPMPD_FRIENDLY_NAME|Name of the upnp renderer (OpenHome), defaults to `upmpd`
AV_FRIENDLY_NAME|Name of the upnp renderer (UPnP AV mode), defaults to `upmpd-av`
FRIENDLY_NAME|Name of the renderer, overrides `UPMPD_FRIENDLY_NAME`, `AV_FRIENDLY_NAME` and `MEDIA_SERVER_FRIENDLY_NAME`. The variable `AV_FRIENDLY_NAME` is appended with the postfix `UPNPAV_POSTFIX`, unless UPNPAV is the only enabled renderer. See `UPNPAV_POSTFIX` and `UPNPAV_SKIP_NAME_POSTFIX` for more details.
Expand Down
53 changes: 47 additions & 6 deletions app/bin/run-upmpdcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,48 @@ if [ "${LOG_ENABLE^^}" == "YES" ]; then
fi
fi

if [[ -z "$ENABLE_AUTO_UPNPIFACE" || "$ENABLE_AUTO_UPNPIFACE" == "1" || "${ENABLE_AUTO_UPNPIFACE^^}" == "YES" || "${ENABLE_AUTO_UPNPIFACE^^}" == "Y" ]]; then
if [ -z "${UPNPIFACE}" ]; then
if [[ -z "${AUTO_UPNPIFACE_URL}" ]]; then
AUTO_UPNPIFACE_URL=1.1.1.1
fi
iface=$(ip route get $AUTO_UPNPIFACE_URL | grep -oP 'dev\s+\K[^ ]+')
set_upnp_iface=0
if [[ "$ENABLE_AUTO_UPNPIFACE" == "1" || "${ENABLE_AUTO_UPNPIFACE^^}" == "YES" || "${ENABLE_AUTO_UPNPIFACE^^}" == "Y" ]]; then
if [[ -z "${UPNPIFACE}" ]]; then
set_upnp_iface=1
else
echo "Cannot set UPNPIFACE with ENABLE_AUTO_UPNPIFACE enabled"
exit 1
fi
fi

set_upnp_ip=0
if [[ -z "${ENABLE_AUTO_UPNP}" || "$ENABLE_AUTO_UPNPIP" == "1" || "${ENABLE_AUTO_UPNPIP^^}" == "YES" || "${ENABLE_AUTO_UPNPIP^^}" == "Y" ]]; then
if [[ -z "${UPNPIP}" ]]; then
set_upnp_ip=1
else
echo "Cannot set UPNPIP with ENABLE_AUTO_UPNPIP enabled"
exit 1
fi
fi

#if [[ -z "$ENABLE_AUTO_UPNPIFACE" || "$ENABLE_AUTO_UPNPIFACE" == "1" || "${ENABLE_AUTO_UPNPIFACE^^}" == "YES" || "${ENABLE_AUTO_UPNPIFACE^^}" == "Y" ]]; then
if [[ set_upnp_iface -eq 1 && set_upnp_ip -eq 1 ]]; then
echo "Cannot enable both ENABLE_AUTO_UPNPIFACE and ENABLE_AUTO_UPNPIP"
exit 1
fi

if [[ set_upnp_iface -eq 1 || set_upnp_ip -eq 1 ]]; then
if [[ -z "${AUTO_UPNPIFACE_URL}" ]]; then
AUTO_UPNPIFACE_URL=1.1.1.1
fi
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')
if [[ set_upnp_iface -eq 1 ]]; then
echo "Automatically setting UPNPIFACE to ["$iface"]"
sed -i 's/\#upnpiface/upnpiface/g' $CONFIG_FILE
sed -i 's/UPNPIFACE/'"$iface"'/g' $CONFIG_FILE
fi
if [[ set_upnp_ip -eq 1 ]]; then
echo "Automatically setting UPNPIP to ["$select_ip"]"
sed -i 's/\#upnpip/upnpip/g' $CONFIG_FILE
sed -i 's/UPNPIP/'"$select_ip"'/g' $CONFIG_FILE
fi
fi

echo "UPNPIFACE=["$UPNPIFACE"]"
Expand All @@ -196,6 +228,15 @@ else
sed -i 's/UPNPIFACE/'"$UPNPIFACE"'/g' $CONFIG_FILE
fi

echo "UPNPIP=["$UPNPIP"]"
if [ -z "${UPNPIP}" ]; then
echo "UPNPIP not set"
else
echo "Setting UPNPIP to ["$UPNPIP"]"
sed -i 's/\#upnpip/upnpip/g' $CONFIG_FILE
sed -i 's/UPNPIP/'"$UPNPIP"'/g' $CONFIG_FILE
fi

# Renderer mode
if [ -n "${RENDERER_MODE}" ]; then
echo "RENDERER_MODE = [${RENDERER_MODE}]"
Expand Down
2 changes: 1 addition & 1 deletion app/conf/upmpdcli.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ logfilename = LOG_DIRECTORY/upmpdcli.log
#pkgdatadir=/usr/share/upmpdcli
#pidfile = /var/run/upmpdcli.pid
#upnpiface = UPNPIFACE
#upnpip =
#upnpip = UPNPIP
#upnpport = UPNPPORT
#useipv6 = false
#friendlyname = UPMPD_FRIENDLY_NAME
Expand Down
1 change: 1 addition & 0 deletions doc/change-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Change Date|Major Changes
---|---
2024-03-05|Automatically set upnpip instead of upnpiface (see issue [#379](https://github.com/GioF71/upmpdcli-docker/issues/379)))
2024-02-29|Update workflow actions (see issue [#377](https://github.com/GioF71/upmpdcli-docker/issues/377)))
2024-02-12|Update to Upmpdcli version 1.8.7 (see issue [#371](https://github.com/GioF71/upmpdcli-docker/issues/371))
2024-01-10|Update to Upmpdcli version 1.8.7 (see issue [#366](https://github.com/GioF71/upmpdcli-docker/issues/366))
Expand Down

0 comments on commit e17ef48

Please sign in to comment.