create_ap

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

bash_completion (4463B)


      1 # 
      2 # Bash Completion routine for create_ap
      3 #
      4 
      5 _use_filedir() {
      6     if [[ $(type -t _filedir) == "function" ]]; then
      7         _filedir
      8         return 0
      9     fi
     10     return 1
     11 }
     12 
     13 _create_ap() {
     14     local awk_cmd='
     15         ($1 ~ /^-/) {
     16             for (i = 1; i <= NF; i++) {
     17                 if ($i ~ /,$/) {
     18                     print substr ($i, 0, length ($i)-1)
     19                 }
     20                 else {
     21                     print $i
     22                     break
     23                 }
     24             }
     25         }
     26     '
     27 
     28     local cur prev opts
     29     COMPREPLY=()
     30     cur="$2"
     31     prev="$3"
     32     opts=$("$1" --help | awk "$awk_cmd")
     33 
     34     case "$prev" in
     35         -h|--help)
     36             # No Options
     37             ;;
     38         --version)
     39             # No Options
     40             ;;
     41         -c)
     42             # Refer http://en.wikipedia.org/wiki/List_of_WLAN_channels
     43             opts=$(
     44                 iw list | grep ' MHz \[[[:digit:]]\+\] ' |
     45                 grep -v 'no IR\|disabled' |
     46                 sed 's/.*\[\(.*\)\].*/\1/' | sort -n | uniq
     47             )
     48             ;;
     49         -w)
     50             opts="1 2 1+2"
     51             ;;
     52         -n)
     53             # No Options
     54             ;;
     55         -m)
     56             opts="nat bridge none"
     57             ;;
     58         --psk)
     59             # No Options
     60             ;;
     61         --hidden)
     62             # No Options
     63             ;;
     64         --ieee80211n)
     65             # No Options
     66             ;;
     67         --ht_capab)
     68             # Refer http://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
     69             opts='
     70                 [LDPC] [HT40-] [HT40+] [SMPS-STATIC] [SMPS-DYNAMIC]
     71                 [GF] [SHORT-GI-20] [SHORT-GI-40] [TX-STBC]
     72                 [RX-STBC1] [RX-STBC12] [RX-STBC123] [DELAYED-BA]
     73                 [MAX-AMSDU-7935] [DSSS_CCK-40] [40-INTOLERANT]
     74                 [LSIG-TXOP-PROT]
     75             '
     76             ;;
     77         --country)
     78             local reg_file=/usr/lib/crda/regulatory.bin
     79             if command -v regdbdump > /dev/null && [[ -f "$reg_file" ]]; then
     80                 local country_awk_cmd='
     81                     ($1 ~ /^country/) {
     82                         print substr ($2, 0, length ($2)-1)
     83                     }
     84                 '
     85                 opts=$(regdbdump "$reg_file" 2>/dev/null | awk "$country_awk_cmd")
     86             else
     87                 opts='
     88                     AD AE AF AI AL AM AN AR AS AT AU AW AZ BA BB BD BE
     89                     BF BG BH BL BM BN BO BR BS BT BY BZ CA CF CH CI CL
     90                     CN CO CR CX CY CZ DE DK DM DO DZ EC EE EG ES ET FI
     91                     FM FR GB GD GE GF GH GL GP GR GT GU GY HK HN HR HT
     92                     HU ID IE IL IN IR IS IT JM JO JP KE KH KN KP KR KW
     93                     KY KZ LB LC LI LK LS LT LU LV MA MC MD ME MF MH MK
     94                     MN MO MP MQ MR MT MU MW MX MY NG NI NL NO NP NZ OM
     95                     PA PE PF PG PH PK PL PM PR PT PW PY QA RE RO RS RU
     96                     RW SA SE SG SI SK SN SR SV SY TC TD TG TH TN TR TT
     97                     TW TZ UA UG US UY UZ VC VE VI VN VU WF WS YE YT ZA
     98                     ZW 00
     99                 '
    100             fi
    101             ;;
    102         --freq-band)
    103             opts="2.4 5"
    104             ;;
    105         --driver)
    106             # Refer http://w1.fi/cgit/hostap/tree/src/drivers
    107             # Not going to implement
    108             ;;
    109         --no-virt)
    110             # No Options
    111             ;;
    112         --no-haveged)
    113             # No Options
    114             ;;
    115         --fix-unmanaged)
    116             # No Options
    117             ;;
    118         --mac)
    119             # Not going to implement
    120             ;;
    121         --daemon)
    122             # No Options
    123             ;;
    124         --stop)
    125             local stop_awk_cmd='$1 ~ /^[0-9]+$/'
    126             opts=$("$1" --list-running | awk "$stop_awk_cmd")
    127             ;;
    128         --list-running)
    129             # No Options
    130             ;;
    131         --list-clients)
    132             local clients_awk_cmd='$1 ~ /^[0-9]+$/'
    133             opts=$("$1" --list-running | awk "$clients_awk_cmd")
    134             ;;
    135         --no-dns)
    136             # No Options
    137             ;;
    138         --dhcp-dns)
    139             # Not going to implement
    140             ;;
    141         --mkconfig)
    142             _use_filedir && return 0
    143             ;;
    144         --config)
    145             _use_filedir && return 0
    146             ;;
    147         -g)
    148             # Not going to implement
    149             ;;
    150         -d)
    151             # No Options
    152             ;;
    153         *)
    154             ;;
    155     esac
    156 
    157     COMPREPLY=( $(compgen -W "$opts" -- $cur) )
    158     return 0
    159 }
    160 complete -F _create_ap create_ap
    161 
    162 # vim: set ft=sh: