Révision cf747932
[router/upnpc] Fix autoconf
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
| plugins/network/upnpc_ | ||
|---|---|---|
| 61 | 61 |
set -x |
| 62 | 62 |
fi |
| 63 | 63 |
|
| 64 |
if ! command -v upnpc >/dev/null; then |
|
| 65 |
echo "upnpc not found (miniupnpc package)" >&2 |
|
| 66 |
exit 1 |
|
| 67 |
fi |
|
| 68 |
|
|
| 69 | 64 |
PLUGIN_NAME="$(basename "${0}")"
|
| 70 | 65 |
MODE="$(echo "${PLUGIN_NAME}" | sed 's/.*_//')"
|
| 71 |
DATA="$(upnpc -s)" |
|
| 72 |
SUPPORTED_MODES=$( |
|
| 66 |
# If called without a mode, default to multigraph |
|
| 67 |
[ "$MODE" = "upnpc" ] && MODE="multi" |
|
| 68 |
|
|
| 69 |
get_data() {
|
|
| 70 |
if ! command -v upnpc >/dev/null; then |
|
| 71 |
echo "upnpc not found (miniupnpc package)" >&2 |
|
| 72 |
exit 1 |
|
| 73 |
fi |
|
| 74 |
|
|
| 75 |
upnpc -s |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
get_supported_modes() {
|
|
| 79 |
DATA=$1 |
|
| 73 | 80 |
echo "${DATA}" | sed -n " \
|
| 74 | 81 |
s/.*Bytes.*/traffic/p; \ |
| 75 | 82 |
s/.*Packets.*/pkts/p; \ |
| 76 | 83 |
s/.*uptime=.*/uptime/p; \ |
| 77 |
") |
|
| 78 |
|
|
| 79 |
HOST=${host_name:-}
|
|
| 80 |
HOST_TITLE="" |
|
| 81 |
HOST_NAME="host_name ${HOST}"
|
|
| 82 |
if [ -z "${HOST}" ]; then
|
|
| 83 |
HOST=$(echo "${DATA}" | sed -n "s#.*desc: http://\([^/:]\+\).*#\1#p")
|
|
| 84 |
# Only add the host name to the title if autodetected |
|
| 85 |
HOST_TITLE=" ($HOST)" |
|
| 86 |
# ...but not as a separate host |
|
| 87 |
HOST_NAME="" |
|
| 88 |
fi |
|
| 84 |
" |
|
| 85 |
} |
|
| 89 | 86 |
|
| 90 | 87 |
autoconf() {
|
| 91 |
test -n "${DATA}" && echo yes || echo "no (No UPnP router detected)"
|
|
| 88 |
if ! command -v upnpc >/dev/null; then |
|
| 89 |
echo "no (upnpc not found [miniupnpc package])" |
|
| 90 |
return |
|
| 91 |
fi |
|
| 92 |
upnpc -s 2>/dev/null | grep -q 'List.*devices.*found' && echo yes \ |
|
| 93 |
|| echo "no (No UPnP router detected)" |
|
| 92 | 94 |
} |
| 93 | 95 |
|
| 94 | 96 |
|
| ... | ... | |
| 177 | 179 |
${HOST_NAME}
|
| 178 | 180 |
EOF |
| 179 | 181 |
;; |
| 180 |
"multi"|"upnpc")
|
|
| 182 |
"multi") |
|
| 181 | 183 |
echo "${HOST_NAME}"
|
| 182 | 184 |
# Don't repeat HOST_NAME in sub-configs |
| 183 | 185 |
HOST_NAME="" |
| ... | ... | |
| 229 | 231 |
esac |
| 230 | 232 |
} |
| 231 | 233 |
|
| 234 |
if [ "${1:-}" = "autoconf" ]; then
|
|
| 235 |
autoconf |
|
| 236 |
exit 0 |
|
| 237 |
fi |
|
| 238 |
|
|
| 239 |
# do data-based detection here, rather than in |
|
| 240 |
# config() as we don't want to do this multiple times |
|
| 241 |
# when the function calls itself for multigraphs |
|
| 242 |
DATA=$(get_data) |
|
| 243 |
SUPPORTED_MODES=$(get_supported_modes "${DATA}")
|
|
| 244 |
|
|
| 245 |
HOST=${host_name:-}
|
|
| 246 |
HOST_TITLE="" |
|
| 247 |
HOST_NAME="host_name ${HOST}"
|
|
| 248 |
if [ -z "${HOST}" ]; then
|
|
| 249 |
HOST=$(echo "${DATA}" | sed -n "s#.*desc: http://\([^/:]\+\).*#\1#p")
|
|
| 250 |
# Only add the host name to the title if autodetected |
|
| 251 |
HOST_TITLE=" ($HOST)" |
|
| 252 |
# ...but not as a separate host |
|
| 253 |
HOST_NAME="" |
|
| 254 |
fi |
|
| 255 |
|
|
| 232 | 256 |
case ${1:-} in
|
| 233 |
"autoconf") |
|
| 234 |
autoconf |
|
| 235 |
;; |
|
| 236 | 257 |
"suggest") |
| 237 | 258 |
suggest |
| 238 | 259 |
;; |
Formats disponibles : Unified diff