-
Notifications
You must be signed in to change notification settings - Fork 1
/
unh_wifi.sh
executable file
·131 lines (111 loc) · 2.81 KB
/
unh_wifi.sh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Contribution of the President, Keith M. Hoodlet, 04.13.2016
#
# Written by the UNH Linux Club
check_reqs() {
# Make sure we're running Linux and not on a Mac
OS_NAME=`uname`
if [ ! $OS_NAME == "Linux" ]
then
return 0
fi
return 1
}
intro() {
echo "======================================"
echo "===== UNH Easy WiFi Setup Script ====="
echo "======================================"
echo ""
check_reqs
if [ ! $? -eq 1 ]
then
echo "Error: distribution not supported."
exit 1
fi
}
run_nmcli() {
echo "Finding network interface..."
interface=$(ip link | grep wlan)
if [ $? == 0 ]; then
interface=$(ip link | grep wlan | cut -d ':' -f 2 | xargs)
else
interface=$(ip link | grep wlp)
if [ $? == 0 ]; then
interface=$(ip link | grep wlp | cut -d ':' -f 2 | xargs)
else
ip link
echo
echo "Cannot find interface! Is your wireless card working?"
fi
fi
echo "Creating UNH-Secure profile..."
nmcli con add type wifi ifname $interface con-name UNH-Secure ssid UNH-Secure
# The main reason fro this script is to set up the options that would
# have to be set up manually, such as peap and disabling the certificate.
# I would like to have the certificate working, however, but that may
# be done at a later date.
echo "Editing UNH-Secure profile..."
nmcli con modify UNH-Secure \
802-1x.eap peap \
802-1x.identity $user \
802-1x.password $passw \
802-1x.phase2-auth mschapv2 \
802-11-wireless-security.auth-alg open \
802-11-wireless-security.key-mgmt wpa-eap
if [ $? == 0 ]; then
echo "Done!"
else
exit 1
fi
}
check_if_already_registered() {
if [ -f /etc/NetworkManager/system-connections/UNH-Secure ]
then
echo "There is already a network named UNH-Secure registered with the system."
echo "Please forget it and then try again."
read -n 1 -p "Would you like us to remove it? [yn] " yn
echo # read -n 1 doesn't make a new line
case $yn in
[Yy]* )
nmcli con delete UNH-Secure
echo
;;
[Nn]* )
exit 1
;;
* ) echo "Please answer Yes or No"; exit;;
esac
fi
}
get_info() {
read -p "Username: " user
echo
while true; do
read -s -p "Password (the text will not show up): " passw
echo
read -s -p "Type your password again to verify: " passwTest
echo
if [ $passw != $passwTest ]; then
echo "Passwords do not match, try again..."
echo
else
break
fi
done
}
main() {
intro
echo "======================================"
echo "This script will attempt to automatically setup the WiFi connection"
echo "on your new Linux PC. You will need your UNH username and password."
echo "(same as Blackboard)."
echo
# We can assume they are using netowrk manager
check_if_already_registered
get_info
run_nmcli
echo
echo "IMPORTANT: Restart your system, then try to connect to UNH-Secure via the wifi menu. Good luck."
}
main
exit 0