create_ap

create a nat-ed wifi ap
git clone git://git.2f30.org/create_ap
Log | Files | Refs | README | LICENSE

commit d8c85b460a01a9cf3f3deb5f6007818a95cd2d5b
parent a1c6c411d3c6984d3d75c69aeb423b9c3c585449
Author: oblique <psyberbits@gmail.com>
Date:   Sun, 14 Dec 2014 15:57:22 +0200

Add --daemon

Diffstat:
Mcreate_ap | 28+++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/create_ap b/create_ap @@ -45,6 +45,7 @@ usage() { echo " close create_ap, then use this option to switch your interface" echo " back to managed" echo " --mac <MAC> Set MAC address" + echo " --daemon Run create_ap in the background" echo " --stop <id> Send stop command to an already running create_ap. For an <id>" echo " you can put the PID of create_ap or the WiFi interface. You can" echo " get them with --list" @@ -71,6 +72,7 @@ usage() { echo " $(basename $0) -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase" echo " $(basename $0) -m bridge wlan0 br0 MyAccessPoint MyPassPhrase" echo " $(basename $0) --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase" + echo " $(basename $0) --daemon wlan0 eth0 MyAccessPoint MyPassPhrase" echo " $(basename $0) --stop wlan0" } @@ -412,6 +414,7 @@ FIX_UNMANAGED=0 COUNTRY= FREQ_BAND=2.4 NEW_MACADDR= +DAEMONIZE=0 LIST_RUNNING=0 STOP_ID= @@ -431,7 +434,7 @@ cleanup() { trap "" SIGUSR1 echo - echo "Doing cleanup..." + echo -n "Doing cleanup.. " # exiting for x in $CONFDIR/*.pid; do @@ -509,6 +512,8 @@ cleanup() { fi networkmanager_rm_unmanaged_if_needed ${WIFI_IFACE} ${OLD_MACADDR} fi + + echo "done" } die() { @@ -556,9 +561,10 @@ send_stop() { trap "die" SIGINT trap "die" SIGUSR1 -ARGS=$(getopt -o hc:w:g:dnm: -l "help","hidden","ieee80211n","ht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","stop:","list" -n $(basename $0) -- "$@") +ARGS=( "$@" ) +GETOPT_ARGS=$(getopt -o hc:w:g:dnm: -l "help","hidden","ieee80211n","ht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","daemon","stop:","list" -n $(basename $0) -- "$@") [[ $? -ne 0 ]] && exit 1 -eval set -- "$ARGS" +eval set -- "$GETOPT_ARGS" while :; do case "$1" in @@ -635,6 +641,10 @@ while :; do NEW_MACADDR="$1" shift ;; + --daemon) + shift + DAEMONIZE=1 + ;; --stop) shift STOP_ID="$1" @@ -676,6 +686,18 @@ if [[ $FIX_UNMANAGED -eq 1 ]]; then exit 0 fi +if [[ $DAEMONIZE -eq 1 ]]; then + # remove --daemon + NEW_ARGS=( ) + for x in "${ARGS[@]}"; do + [[ "$x" != "--daemon" ]] && NEW_ARGS+=( "$x" ) + done + + # fork()/setsid()/fork() + setsid "$0" "${NEW_ARGS[@]}" & + exit 0 +fi + if [[ $FREQ_BAND != 2.4 && $FREQ_BAND != 5 ]]; then echo "ERROR: Invalid frequency band" >&2 exit 1