forked from foss-aueb/aueb-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aueb
executable file
·222 lines (202 loc) · 6.09 KB
/
aueb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
exit() {
aueb
builtin exit ${1:-0}
}
aueb() {
cat << EOM
-----------------------
Foss Aueb Team
http://foss.aueb.gr
-----------------------
EOM
}
usage() {
cat << EOM
usage: aueb option suboption
options:
packages install or remove packages
install install packages
remove remove packages
wifi toggle university wireless connection
up connect to the wireless network
down disconnect from the wireless network
notes:
a) if your wireless interface is not 'wlan0' then
set the IFACE variable to your interface name, eg;
sudo IFACE="ath0" ./aueb wifi up
b) you may need to turn off any running network
managers to let wifi work.
EOM
}
detect_dist() {
printf " ** %s\n" "Detecting distribution .."
dist="$(head -1 -q /etc/*release | sed 's/.*"\(.\+\)".*/\1/' \
| tr [[:upper:]] [[:lower:]])"
confirm_dist && return 0
type lsb_release &>/dev/null && dist="$(lsb_release -i \
| awk -F':\t' '{ print $2 }' | tr [[:upper:]] [[:lower:]])"
confirm_dist && return 0 \
|| printf "\n ** %s\n" "Couldn't detect distribution" && return 1
}
confirm_dist() {
local answer
printf "Is this your distribution: %s (Y/n)? " "$dist" && read answer
[[ -z $answer || $answer =~ ^[yY]$ ]] && return 0 || return 1
}
choose_dist() {
printf "\nPlease choose your distribution, from the list below:\n"
printf "\t%s\n" "1. Ubuntu" "2. Arch" "0. exit"
local choice
while true; do
read -p "Your distribution: " choice
case $choice in
1)
dist="ubuntu"
break
;;
2)
dist="arch"
break
;;
0)
exit
;;
*)
printf " --> Unknown choice: %s. Please try again.\n" "$choice"
;;
esac
done
}
install_extra() {
# FIXME
echo "Install Extra"
case $dist in
arch)
# TODO:
# download package from AUR
# unpack && makepkg
# pacman -U
;;
ubuntu)
for pkg in ${packages["extra-${dist}"]}; do
# FIXME or create .deb packages ~ similar to arch/AUR
make install $pkg
done
;;
esac
for pkg in ${packages["extra-both"]}; do
# FIXME
make install $pkg
done
}
uninstall_extra() {
case $dist in
arch)
${uninstaller["$dist"]} ${packages["extra-${dist}"]}
;;
ubuntu)
for pkg in ${packages["extra-${dist}"]}; do
# FIXME or remove .deb ~ similar to arch/AUR
make uninstall $pkg
done
;;
esac
for pkg in ${packages["extra-both"]}; do
# FIXME
make uninstall $pkg
done
}
create_wifi_profile() {
[[ -e $wificonf ]] && return
cat > "$wificonf" << EOF
ctrl_interface=${PREFIX}/wpa_aueb
eapol_version=1
ap_scan=1
fast_reauth=1
network={
ssid="AUEB-Wireless"
key_mgmt=WPA-EAP
pairwise=CCMP TKIP
eap=PEAP
phase2="auth=MSCHAPV2"
identity="aueb"
password="wireless"
}
EOF
}
# TODO: uncomment on deploy
# (( UID )) && printf " --> %s\n" "You must have root priviledges to run this script" >&2 && exit 1
dist=
case $1 in
packages)
declare -A installer
installer=( [ubuntu]="aptitude install"
[arch]="pacman -S"
)
declare -A uninstaller
installer=( [ubuntu]="aptitude remove"
[arch]="pacman -Rs"
)
declare -A packages
packages=( [common]="netbeans geany nmap scilab tcsh wireshark"
[arch]="openjdk6 base-devel wireless_tools wpa_supplicant"
[extra-arch]="nessus omnetpp4 xampp" ## AUR
[ubuntu]="openjdk-6-jdk build-essential wireless-tools wpasupplicant nessus"
[extra-ubuntu]="omnetpp xampp"
[extra-both]="quartus"
)
case $2 in
install)
detect_dist || choose_dist
printf " ** Running: %s\n" "${installer["$dist"]} ${packages["common"]} ${packages["$dist"]}" \
&& install_extra && printf " ==> %s\n" "Software ready to use" \
|| { printf " --> %s\n" "Failed to install packages. Check with your package manager." >&2; exit 1; }
;;
remove)
detect_dist || choose_dist
printf " ** Running: %s\n" "${uninstaller["$dist"]} ${packages["common"]} ${packages["$dist"]}" \
&& uninstall_extra && printf " ==> %s\n" "Software removed" \
|| { printf " --> %s\n" "Failed to uninstall packages. Check with your package manager." >&2; exit 1; }
;;
*)
printf " --> Unknown option: %s\n" "$2" >&2
exit 1
;;
esac
;;
wifi)
netdir="/etc/wpa_supplicant"
wificonf="$netdir/wpa_aueb.conf"
mkdir -p "$netdir"
IFACE="${IFACE:-wlan0}"
case $2 in
up)
create_wifi_profile
printf " ** Running: %s\n" "wpa_supplicant -Dwext -i${IFACE} -c${wificonf}" \
&& printf " ==> %s\n" "Connected to aueb wireless network" \
|| printf " --> %s\n" "Couldn't connect to wireless network" >&2
;;
down)
printf " ** Running: %s\n" "ifconfig ${IFACE} down"
printf " ==> %s\n" "Disconnected wireless connection"
;;
*)
printf " --> Unknown option: %s\n" "$2" >&2
exit 1
;;
esac
;;
help)
usage
;;
*)
printf " --> Unknown option: %s\n" "$1" >&2
exit 1
;;
esac
exit
# TODO:
# custom packages: omnet xampp quartus nessus
# test wpa_supplicant
# vim: nospell