Path: blob/next/external/packages/extras-buildpkgs/hostapd/debian/ifupdown/hostapd.sh
13272 views
#!/bin/sh12# Copyright (C) 2006-2009 Debian hostapd maintainers3# Faidon Liambotis <[email protected]>4# Kel Modderman <[email protected]>5#6# This program is free software; you can redistribute it and/or7# modify it under the terms of the GNU General Public License8# as published by the Free Software Foundation; either version 29# of the License, or (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# On Debian GNU/Linux systems, the text of the GPL license,17# version 2, can be found in /usr/share/common-licenses/GPL-2.1819# quit if we're called for lo20if [ "$IFACE" = lo ]; then21exit 022fi2324if [ -n "$IF_HOSTAPD" ]; then25HOSTAPD_CONF="$IF_HOSTAPD"26else27exit 028fi2930HOSTAPD_BIN="/usr/sbin/hostapd"31HOSTAPD_PNAME="hostapd"32HOSTAPD_PIDFILE="/run/hostapd.$IFACE.pid"33HOSTAPD_OMIT_PIDFILE="/run/sendsigs.omit.d/hostapd.$IFACE.pid"3435if [ ! -x "$HOSTAPD_BIN" ]; then36exit 037fi3839if [ "$VERBOSITY" = "1" ]; then40TO_NULL="/dev/stdout"41else42TO_NULL="/dev/null"43fi4445hostapd_msg () {46case "$1" in47verbose)48shift49echo "$HOSTAPD_PNAME: $@" > "$TO_NULL"50;;51stderr)52shift53echo "$HOSTAPD_PNAME: $@" > /dev/stderr54;;55*)56;;57esac58}5960test_hostapd_pidfile () {61if [ -n "$1" ] && [ -f "$2" ]; then62if start-stop-daemon --stop --quiet --signal 0 \63--exec "$1" --pidfile "$2"; then64return 065else66rm -f "$2"67return 168fi69else70return 171fi72}7374init_hostapd () {75HOSTAPD_OPTIONS="-B -P $HOSTAPD_PIDFILE $HOSTAPD_CONF"76HOSTAPD_MESSAGE="$HOSTAPD_BIN $HOSTAPD_OPTIONS"7778test_hostapd_pidfile "$HOSTAPD_BIN" "$HOSTAPD_PIDFILE" && return 07980hostapd_msg verbose "$HOSTAPD_MESSAGE"81start-stop-daemon --start --oknodo --quiet --exec "$HOSTAPD_BIN" \82--pidfile "$HOSTAPD_PIDFILE" -- $HOSTAPD_OPTIONS > "$TO_NULL"8384if [ "$?" -ne 0 ]; then85return "$?"86fi8788HOSTAPD_PIDFILE_WAIT=089until [ -s "$HOSTAPD_PIDFILE" ]; do90if [ "$HOSTAPD_PIDFILE_WAIT" -ge 5 ]; then91hostapd_msg stderr \92"timeout waiting for pid file creation"93return 194fi9596HOSTAPD_PIDFILE_WAIT=$(($HOSTAPD_PIDFILE_WAIT + 1))97sleep 198done99cat "$HOSTAPD_PIDFILE" > "$HOSTAPD_OMIT_PIDFILE"100101return 0102}103104kill_hostapd () {105HOSTAPD_MESSAGE="stopping $HOSTAPD_PNAME via pidfile: $HOSTAPD_PIDFILE"106107test_hostapd_pidfile "$HOSTAPD_BIN" "$HOSTAPD_PIDFILE" || return 0108109hostapd_msg verbose "$HOSTAPD_MESSAGE"110start-stop-daemon --stop --oknodo --quiet --exec "$HOSTAPD_BIN" \111--pidfile "$HOSTAPD_PIDFILE" > "$TO_NULL"112113[ "$HOSTAPD_OMIT_PIDFILE" ] && rm -f "$HOSTAPD_OMIT_PIDFILE"114}115116case "$MODE" in117start)118case "$PHASE" in119pre-up)120init_hostapd || exit 1121;;122*)123hostapd_msg stderr "unknown phase: \"$PHASE\""124exit 1125;;126esac127;;128stop)129case "$PHASE" in130post-down)131kill_hostapd132;;133*)134hostapd_msg stderr "unknown phase: \"$PHASE\""135exit 1136;;137esac138;;139*)140hostapd_msg stderr "unknown mode: \"$MODE\""141exit 1142;;143esac144145exit 0146147148