Support --mkconfig option

When invoked with --mkconfig <conf_file>, the options are stored in
conf_file and create_ap exits.
This commit is contained in:
Karthik K 2015-05-06 22:38:40 +05:30
parent 3ca3663894
commit 13569a5a42
2 changed files with 81 additions and 32 deletions

View File

@ -2,6 +2,14 @@
# Bash Completion routine for create_ap # Bash Completion routine for create_ap
# #
_use_filedir() {
if [[ $(type -t _filedir) == "function" ]]; then
_filedir
return 0
fi
return 1
}
_create_ap() { _create_ap() {
local awk_cmd=' local awk_cmd='
($1 ~ /^-/) { ($1 ~ /^-/) {
@ -117,6 +125,9 @@ _create_ap() {
--list) --list)
# No Options # No Options
;; ;;
--mkconfig)
_use_filedir && return 0
;;
-g) -g)
# Not going to implement # Not going to implement
;; ;;

View File

@ -57,6 +57,7 @@ usage() {
echo " you can put the PID of create_ap or the WiFi interface. You can" echo " you can put the PID of create_ap or the WiFi interface. You can"
echo " get them with --list" echo " get them with --list"
echo " --list Show the create_ap processes that are already running" echo " --list Show the create_ap processes that are already running"
echo " --mkconfig <conf_file> Store configs in conf_file"
echo echo
echo "Non-Bridging Options:" echo "Non-Bridging Options:"
echo " -g <gateway> IPv4 Gateway for the Access Point (default: 192.168.12.1)" echo " -g <gateway> IPv4 Gateway for the Access Point (default: 192.168.12.1)"
@ -574,14 +575,21 @@ IEEE80211N=0
HT_CAPAB='[HT40+]' HT_CAPAB='[HT40+]'
DRIVER=nl80211 DRIVER=nl80211
NO_VIRT=0 NO_VIRT=0
FIX_UNMANAGED=0
COUNTRY= COUNTRY=
FREQ_BAND=2.4 FREQ_BAND=2.4
NEW_MACADDR= NEW_MACADDR=
DAEMONIZE=0 DAEMONIZE=0
NO_HAVEGED=0
CONFIG_OPTS=(CHANNEL GATEWAY WPA_VERSION ETC_HOST HIDDEN SHARE_METHOD
IEEE80211N HT_CAPAB DRIVER NO_VIRT COUNTRY FREQ_BAND
NEW_MACADDR DAEMONIZE NO_HAVEGED)
FIX_UNMANAGED=0
LIST_RUNNING=0 LIST_RUNNING=0
STOP_ID= STOP_ID=
NO_HAVEGED=0
STORE_CONFIG=
CONFDIR= CONFDIR=
WIFI_IFACE= WIFI_IFACE=
@ -806,8 +814,31 @@ send_stop() {
mutex_unlock mutex_unlock
} }
# Storing configs
write_config() {
local i=1
if ! eval 'echo -n > "$STORE_CONFIG"' > /dev/null 2>&1; then
echo "ERROR: Unable to create config file $STORE_CONFIG" >&2
exit 1
fi
for config_opt in "${CONFIG_OPTS[@]}"; do
eval echo $config_opt=\$$config_opt
done >> "$STORE_CONFIG"
while [[ $# -ne 0 ]]; do
echo "ARG$i=$1"
shift
((i++))
done >> "$STORE_CONFIG"
echo -e "\nConfigs written to $STORE_CONFIG"
exit 0
}
ARGS=( "$@" ) 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","version","no-haveged" -n "$PROGNAME" -- "$@") 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","version","no-haveged","mkconfig:" -n "$PROGNAME" -- "$@")
[[ $? -ne 0 ]] && exit 1 [[ $? -ne 0 ]] && exit 1
eval set -- "$GETOPT_ARGS" eval set -- "$GETOPT_ARGS"
@ -908,6 +939,11 @@ while :; do
shift shift
NO_HAVEGED=1 NO_HAVEGED=1
;; ;;
--mkconfig)
shift
STORE_CONFIG="$1"
shift
;;
--) --)
shift shift
break break
@ -934,6 +970,8 @@ trap "clean_exit" SIGINT SIGUSR1
# if we get USR2 signal then run die(). # if we get USR2 signal then run die().
trap "die" SIGUSR2 trap "die" SIGUSR2
[[ -n "$STORE_CONFIG" ]] && write_config "$@"
if [[ $LIST_RUNNING -eq 1 ]]; then if [[ $LIST_RUNNING -eq 1 ]]; then
echo -e "List of running $PROGNAME instances:\n" echo -e "List of running $PROGNAME instances:\n"
list_running list_running