wok view nomad/stuff/nomad @ rev 23417
updated perl-xml-simple (2.18 -> 2.25)
author | Hans-G?nter Theisgen |
---|---|
date | Wed Apr 01 07:44:12 2020 +0100 (2020-04-01) |
parents | |
children |
line source
1 #! /bin/sh
2 # nomad: configure wifi and change acces point easily.
4 # Copyright (C) <2008> <Pierre-Jean Fichet> <sygnes@ombres.eu>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 CONFIG="/etc/nomad.conf"
22 . $CONFIG
23 . /etc/init.d/rc.functions
26 case "$1" in
27 # we want to configure au new interface
28 new)
29 TYPE="wifi"
30 WIFI_INTERFACE="$2"
31 ESSID="$3"
32 KEYTYPE="$4"
33 KEY="$5"
34 DRIVER="$6"
35 if [ "$KEYTYPE" = "wpa" ]; then
36 WPA="
37 ap_scan=1
38 network={
39 ssid=\"$ESSID\"
40 scan_ssid=1
41 proto=WPA
42 key_mgmt=WPA-PSK
43 psk=\"$KEY\"
44 priority=5
45 }"
46 fi
47 ;;
49 # we want to poweroff wifi
50 stop)
51 echo -n "pidof wpa_supplicant: "
52 if pidof wpa_supplicant; then
53 echo -n "stopping wpa_supplicant..."
54 killall wpa_supplicant
55 status
56 else
57 echo "None"
58 fi
59 echo -n "power off wifi..."
60 iwconfig $WIFI_INTERFACE txpower off
61 status
62 ;;
65 *)
66 # we want to join a known access point
67 if [ "$1" != "" ] && grep -q "$1() {" $CONFIG ; then
68 $1 # here we launch the function to set variables
69 # we don't know how to use nomad
70 else
71 echo -n -e "\033[01musage:\033[0m `basename $0` ["
72 for line in `grep "() {" $CONFIG | sed "/#.*/d" | sed -e "s/() {//g"`
73 do
74 echo -n "$line|"
75 done
76 echo -n "stop]"
77 echo ""
78 echo -e "\033[1mOr :\033[0m `basename $0` new \
79 WIFI_INTERFACE ESSID KEYTYPE KEY DRIVER"
80 echo " KEYTYPE is: wpa or wep"
81 echo " DRIVER is wext or another-wpa_supplicant-driver"
82 echo ""
83 echo -e " But first, you have to edit \033[1m/etc/nomad.conf\033[0m "
84 echo ""
85 echo -e "You can also use \033[1mnomadbox\033[0m, if you want a graphical interface for nomad"
86 echo ""
87 exit 1
88 fi
89 ;;
90 esac
93 #Si ethernet
94 if [ "$TYPE" = "ethernet" ]; then
95 if [ "$DHCP" = "yes" ] ; then
96 echo "Starting udhcpc client on: $INTERFACE... "
97 /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid
98 status
99 fi
100 # For a static IP.
101 if [ "$STATIC" = "yes" ] ; then
102 echo -n "Configuring static IP on $INTERFACE: $IP... "
103 /sbin/ifconfig $INTERFACE $IP netmask $NETMASK up
104 /sbin/route add default gateway $GATEWAY
105 status
106 # Multi-DNS server in $DNS_SERVER.
107 /bin/mv /etc/resolv.conf /tmp/resolv.conf.$$
108 for NS in $DNS_SERVER
109 do
110 echo "nameserver $NS" >> /etc/resolv.conf
111 done
112 fi
114 #si wifi
115 elif [ "$TYPE" = "wifi" ]; then
116 iwconfig $WIFI_INTERFACE txpower on
117 status
118 iwconfig $WIFI_INTERFACE essid $ESSID
119 if [ -n "$WPA" ]; then
120 echo "$WPA" >/tmp/wpa.conf
121 echo "starting wpa_supplicant for $INTERFACE..."
122 wpa_supplicant -B -w -c/tmp/wpa.conf -D$DRIVER -i$WIFI_INTERFACE
123 status
124 rm /tmp/wpa.conf
125 elif [ -n "$KEY" ]; then
126 iwconfig $WIFI_INTERFACE key $KEY
127 fi
128 /sbin/udhcpc -b -i $WIFI_INTERFACE -p /var/run/udhcpc.$WIFI_INTERFACE.pid
129 fi
131 exit 0