1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/bin/sh
set -e
CONFFILE="/etc/miniupnpd/miniupnpd.conf"
DEFAULT_FILE="/etc/default/miniupnpd"
. /usr/share/debconf/confmodule
read_config () {
sed -rn '
s|^\s*'"${2}"'='\''([^'\'']+)'\''\s*$|\1|g
t hold
s|^\s*'"${2}"'='\"'([^'\"']+)'\"'\s*$|\1|g
t hold
s|^\s*'"${2}"'=(\S+)\s*$|\1|
t hold
b
: hold
p
' "${1}"
}
if [ -r "${DEFAULT_FILE}" ] ; then
. "${DEFAULT_FILE}"
fi
if [ -r "${CONFFILE}" ] ; then
MiniUPnPd_EXTERNAL_INTERFACE=$(read_config "${CONFFILE}" ext_ifname)
MiniUPnPd_LISTENING_IP=$(read_config "${CONFFILE}" listening_ip | sed -z 's/\n/ /g')
fi
if [ -z "${MiniUPnPd_EXTERNAL_INTERFACE}" ] ; then
# If no interface is defined, try to find one automatically
if command -v ip > /dev/null 2>&1 ; then
MiniUPnPd_EXTERNAL_INTERFACE=$(LC_ALL=C ip -o route show | sed -nre '/^default /s/^default .*dev ([^ ]+).*/\1/p')
elif command -v route > /dev/null 2>&1 ; then
MiniUPnPd_EXTERNAL_INTERFACE=$(LC_ALL=C route | grep -m 1 default | awk -- '{ print $8 }')
fi
fi
# fetch anything in debconf
db_get miniupnpd/start_daemon
if [ -n "$RET" ] ; then
if [ "$RET" = 'true' ] ; then
START_DAEMON=1
else
START_DAEMON=0
fi
fi
db_get miniupnpd/iface
if [ -n "$RET" ] ; then
MiniUPnPd_EXTERNAL_INTERFACE="$RET"
else
db_set miniupnpd/iface "${MiniUPnPd_EXTERNAL_INTERFACE}"
fi
db_get miniupnpd/listen
if [ -n "$RET" ] ; then
MiniUPnPd_LISTENING_IP="$RET"
else
db_set miniupnpd/listen "${MiniUPnPd_LISTENING_IP}"
fi
if [ -z "${MiniUPnPd_EXTERNAL_INTERFACE}" ] || [ -z "${MiniUPnPd_LISTENING_IP}" ] ; then
# If none found, then we shouldn't start the daemon.
START_DAEMON=0
fi
if [ "${START_DAEMON}" = 1 ] ; then
db_set miniupnpd/start_daemon true
else
db_set miniupnpd/start_daemon false
fi
db_input high miniupnpd/start_daemon || true
db_input high miniupnpd/iface || true
db_input high miniupnpd/listen || true
# detect iptables, since `iptables` may not be present if only nftables installed
if update-alternatives --query iptables | grep -F Value | grep -qF legacy ; then
db_input low miniupnpd/ip6script || true
fi
db_input medium miniupnpd/force_igd_desc_v1 || true
db_go
exit 0
|