summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/wlanboot/init-hooks/10-nw-if-config/wlanboot.sh
blob: fee893d45e3670973f0d6e70091133f6dae54bbc (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
# Copyright (c) 2009 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# stage3 init-hook 10 of 'wlanboot' plugin - firing up the wlan connection

#setting udhcpc up
mkdir -p /usr/share/udhcpc
echo -e "#!/bin/ash\nunset infomsg HOME IFS mask lease interface DEBUGLEVEL \
BOOT_IMAGE\nset >/tmp/ipstuff" >/usr/share/udhcpc/default.script
chmod u+x /usr/share/udhcpc/default.script

echo "! shutting down watchdog for debugging";
killall watchdog;

essid=$(sed -n 's/.*essid=\([^[:blank:]]*\) .*/\1/p' /proc/cmdline);
[ $DEBUGLEVEL -gt 0 ] && echo "set essid to ${essid}";
#value of essid unchecked yet


# load network adaptor modules
#modprobe iwl3945
cd /lib/modules/$(ls /lib/modules/)/kernel/drivers/net/wireless
for mod in $(find . | grep .ko | sed 's,.*/\([^/]*\).ko,\1',); do
  echo "Mod:";
  echo $mod;
  modprobe $mod || echo "module $mod did not load for some reason"
  usleep 10000 
done
cd /

wlanif=$(iwconfig 2>/dev/null|sed -n "/ESSID:/p"|sed "s/    .*//")
[ $DEBUGLEVEL -gt 0 ] && echo "wlancard recognized as ${wlanif}";

if [ -n "$wlanif" ] ; then
  ip link set dev ${wlanif} up
  if iwconfig ${wlanif} mode managed essid "${essid}"; then
    nwif=${wlanif}
  else
    error "  Unable to configure the WLAN interface."
  fi  
  
  
  ( sleep 6 ; killall udhcpc >/dev/null 2>&1 ) &
  udhcpc -f -n -q $vci -s /usr/share/udhcpc/default.script -i $nwif 2>/dev/null
  if grep "ip=" /tmp/ipstuff >/dev/null 2>&1 ; then
	. /tmp/ipstuff
	for i in $dns ; do
		echo "nameserver $i" >>/etc/resolv.conf
	done
    # simply add a single dns server for passing via kernel cmdline to stage3
    # (quickhack, just the last, list of dns might be better ...)
    echo "dnssrv=$i" >>/tmp/ipstuff
    return
  else
    if [ $i -eq 1 ] ; then
      sleep 1
    else
      echo "Did not get any proper IP configuration"; /bin/ash
    fi
  fi
  
  ip addr add $ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//) dev $nwif
  ip route add default via $router
  [ $DEBUGLEVEL -gt 0 ] && echo "IP-Configuration: $ip on interface $wlanif."
else
  error "  No wireless LAN capable interface found. Did you provide the \
proper kernel\n  modules and firmware?"
fi