On June 4, 2016 11:11:13 AM GMT+02:00, Benjamin Baier <program...@netzbasis.de> 
wrote:
>On Fri, 3 Jun 2016 00:26:12 +0800
>Ray Lai <r...@raylai.com> wrote:
>
>> Hi all,
>> 
>> I got tired of configuring my wifi every time I had to move my
>laptop.
>> Here's a script a whipped up. It scans the wifi for known networks
>and
>> writes the strongest one to /etc/hostname.if. Then it runs netstart.
>> Easy to use, simple config file, no arguments needed, perfect
>> for /etc/apm/resume.
>> 
>> Oh, and it uses pledge for good measure.
>> 
>> I hope this is helpful!
>
>Hi and thanks, 
>please let me share my modifications for wifi handling, too.
>
>This patch to /etc/netstart [0] cycles through different configurations
>in hostname.if [1] until the link status becomes "active".

I don't like the syntax, and in general I'd like hostname.if over time become a 
list of arguments to pass on to ifconfig with no magic whatsoever attached, but 
I like the relative KISS approach of this.

Alternatively, one could pass sth like "linkless" or "nolink" (or probably 
something better), as a parameter to ifconfig, causing it to not process any 
further arguments if the interface already has link status active.

/Alexander 

>
>It's not bulletproof nor as fast as it could be...
>
>Greetings Ben
>
>
>[0] diff -u /etc/netstart.orig /etc/netstart
>--- /etc/netstart.orig  Fri Jun  3 23:09:40 2016
>+++ /etc/netstart       Sat Jun  4 11:05:03 2016
>@@ -40,6 +40,8 @@
>        fi
>        # Check for ifconfig'able interface.
>        (ifconfig $if || ifconfig $if create) >/dev/null 2>&1 || return
>+       # Check for wifi, so we can treat it special
>+       [ "$(ifconfig $if | grep groups:.*wlan)" ] && wifi=yes
> 
>        # Now parse the hostname.* file.
>        while :; do
>@@ -66,6 +68,11 @@
>                "!"*) # Parse commands.
>               cmd="${af#*!} ${name} ${mask} ${bcaddr} ${ext1} ${ext2}"
>                        ;;
>+               "TRYNEXT")
>+                       [ "$wifi" ] && wifi=checkactive || continue
>+                       [ "$name" = "NONE" ] && checkdelay="" ||
>checkdelay="$name"
>+                       cmd=
>+                       ;;
>                "dhcp")
>                        [ "$name" = "NONE" ] && name=
>                        [ "$mask" = "NONE" ] && mask=
>@@ -127,6 +134,13 @@
>                        ;;
>                esac
>                eval "$cmd"
>+               if [ "X$wifi" = "Xcheckactive" ]
>+               then
>+                       # delay to let the status catch up
>+                       [ "$checkdelay" ] && sleep $checkdelay || sleep
>1
>+                       [ "$(ifconfig $if | grep status:.*active)" ] &&
>break
>+                       wifi=retry
>+               fi 
>        done </etc/hostname.$if
> }
> 
>
>[1] cat /etc/hostname.iwn0
>nwid APhop1 nwkey 0x1234567890abcdefabcdef1234
>inet 192.168.1.10 255.255.255.0
>up
>
>TRYNEXT 10
>
>nwid APhop2 nwkey 0x1234567890abcdefabcdef1234
>dhcp
>
>TRYNEXT
>
>nwid APhop3 nwkey 0x1234567890abcdefabcdef1234
>dhcp

Reply via email to