-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathewoc-cli.sh
More file actions
96 lines (91 loc) · 3.03 KB
/
Copy pathewoc-cli.sh
File metadata and controls
96 lines (91 loc) · 3.03 KB
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
94
95
96
#!/bin/bash
##########################################################################################################################
# ewoc-cli.sh v0.02 (15/01/2011) aka Easy Wifi Configurator -- EWoC #
# By Russell K. Davis with input from jaldher, g8787/geordy, Ray Dios Haque, pcurtis, wicknix, brianith and lfod et al. #
# This version is tailored for use on debian based distros, it definatly won't work on IZ2S/IZ2Se/EZ2S but it might work #
# on other distros. #
##########################################################################################################################
# Read the desired wifi device from the command line, else use the default.
wifidevice=$1
if [ "$wifidevice" == "" ]; then
wifidevice=eth0
fi
# Make sure the wifi device is ready for use (scanning)
ifconfig $wifidevice down
sleep 5
ifconfig $wifidevice up
sleep 5
# Do you want to use the existing settings in /etc/wpa_supplicant.conf
if [ -e /etc/wpa_supplicant.conf ]; then
currentssid=`grep ssid /etc/wpa_supplicant.conf | sed -e 's/.*ssid="//' -e 's/"//'`
echo -n "Use existing wpa_supplicant.conf settings ($currentssid) [Y/n] "
read existingsettings
fi
if [ "$existingsettings" == "n" ]; then
# No we do not want to use the existing settings in /etc/wpa_supplicant.conf
array=(`iwlist $wifidevice scan | grep 'ESSID' | sed -e 's/.*ESSID:"\([^"]\+\)".*/ \1/'`)
LIST=${array[@]}
select SSID in $LIST; do
NEWSSID=$SSID
break
done
LIST="WPA/WPA2 WEP(Hex) WEP(ASCII) None"
select OPT in $LIST; do
CIPHER=$OPT
break
done
case $CIPHER in
"WPA/WPA2")
echo -n "Enter Passphrase: "
read passphrase
wpa_passphrase $NEWSSID $passphrase | grep -v "^#" | grep -v "#psk=" > /etc/wpa_supplicant.conf
;;
"WEP(Hex)")
echo -n "Enter Hex WEP Key: "
read passphrase
echo "network={
ssid=\"$NEWSSID\"
key_mgmt=NONE
wep_key0=$passphrase
}" > /etc/wpa_supplicant.conf
;;
"WEP(Ascii)")
echo -n "Enter ASCII WEP Key: "
read passphrase
echo "network={
i ssid=\"$NEWSSID\"
key_mgmt=NONE
wep_key0=i\"$passphrase\"
}" > /etc/wpa_supplicant.conf
;;
"None")
echo "network={
ssid=\"$NEWSSID\"
key_mgmt=NONE
}" > /etc/wpa_supplicant.conf
;;
esac
fi
# Try to start wifi
wpa_supplicant -B -i$wifidevice -c /etc/wpa_supplicant.conf
dhclient $wifidevice -1 > /dev/tty
nolease=$?
if [ $nolease -eq 2 ] ; then
LIST="Poweroff Reboot Continue"
select OPT in $LIST; do
case $OPT in
Poweroff)
echo "Powering off"
poweroff
;;
Reboot)
echo "Rebooting"
reboot
;;
Continue)
echo "Exitting. If you wish to start wifi later"
echo "then rerun the ewoc-cli.sh script."
;;
esac
done
fi