summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/wlan-boot/hooks/start_wlan.sh
blob: c39b91610c152a98a3c44e3fe7e6b8824e1c2e44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh

shell () {
        if [ $# -eq 0 ] ; then
            REASON="Unknown Reason"
        else
            REASON="$1"
        fi
        warn ''
        warn "ERROR: $REASON"
        warn '  Entering rescue shell.'
        warn '  Exit shell to continue booting.'
        emergency_shell
}

# wiface name should be wlan0, if not udev failed
WIFACE=wlan0
timeout=20
#LEASES="/var/lib/dhcp/dhclient.leases"

### OLD, now use dhcpcd
## Install udhcpc (maybe do this in module-setup-sh)
#[ -f /root/busybox.tar ] || shell "cant find /root/busybox.tar"
#tar xf /root/busybox.tar usr/bin/busybox
#tar xf /root/busybox.tar usr/sbin/udhcpc

# require the 99base dracut module
type strstr >/dev/null 2>&1 || . /lib/dracut-lib.sh || shell "/lib/dracut-lib.sh doesnt exist"

# set interface up
cnt=0
while [ $cnt -lt $timeout ]; do
    if [ -e /sys/class/net/wlan0 ] ; then
        /sbin/ip link set dev "$WIFACE" up || shell "Could not set dev $WIFACE up"
        break
    fi
    sleep 1
    cnt=$(($cnt+1))
    warn "waiting for wlan interface up ("$cnt"s / 20s)"
    [ $cnt -eq $timeout ] && shell "Could not find a valid wlan interface, make sure its enabled by hardware side"
done

## start wpa_supplicant service
#systemctl start wpa_supplicant.service || shell "Could not start wpa_supplicant.service"
#
## wait for wpa_supplicant, similair to the network dracut module 40network/net-lib.sh
#cnt=0
#while [ $cnt -lt $timeout ]; do
#    li=$(ip -o link show up dev "$WIFACE")
#    if ! strstr "$li" "NO-CARRIER"; then
#        if [ -n "$li" ]; then
#            case "$li" in
#                *\<UP*)
#                    break;;
#                *\<*,UP\>*)
#                    break;;
#                *\<*,UP,*\>*)
#                    break;;
#            esac
#        fi
#    fi
#    sleep 1
#    cnt=$(($cnt+1))
#    warn "Waiting for wpa_supplicant. Make sure interface is up and the AP is reachable with the correct credentials ("$cnt"s / 20s)"
#    [ $cnt -eq $timeout ] && shell "Could not find a CARRIER please check the credentials and if the AP is active"
#done

systemctl start dhcp.service || shell "Could not start dhcp.service"

## wait for dhcpcd
SLXSRV=$(getarg slxsrv=)
cnt=0
while [ $cnt -lt $timeout ]; do
    ping -c 1 -q "$SLXSRV"
    if [ $? -eq 0 ] ; then
        break
    fi
    sleep 1
    cnt=$(($cnt+1))
    warn "Waiting for dhcpcd. Make sure wpa_supplicant finished startup and slxserver $SLXSRV is reachable ("$cnt"s / 20s)"
    [ $cnt -eq $timeout ] && shell "Could not ping slx server."
done

## dhclient didnt set route, now i use dhcpcd this works fine
# set route
#TODO: look into /sbin/dhclient-script why no route is set automaticly
##ADDRESS=$(sed -n '/wlan0/,/}/p' $LEASES | grep 'fixed-address' | sort -u | awk -F' ' '{print $2}' | awk -F';' '{print $1}' | head -1)
#ROUTE=$(sed -n '/wlan0/,/}/p' $LEASES | grep 'option routers' | sort -u | awk -F' ' '{print $3}' | awk -F';' '{print $1}'| head -1)
#echo "ROUTE=$ROUTE" >> /tmp/wlan.log
#
##ip addr add "$ADDRESS/24" dev "$WIFACE"
#ip route add default via "$ROUTE" dev "$WIFACE" &>> /tmp/wlan.log
#echo $? >> /tmp/wlan.log