Skip to content

Commit ef0909a

Browse files
committed
introduce exit(); redirect error msgs to stderr; draft/work custom packages
1 parent 7f115ad commit ef0909a

File tree

1 file changed

+76
-27
lines changed

1 file changed

+76
-27
lines changed

aueb

+76-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
exit() {
4+
aueb
5+
builtin exit ${1:-0}
6+
}
7+
38
aueb() {
49
cat << EOM
510
-----------------------
@@ -24,7 +29,7 @@ usage: aueb option suboption
2429
notes:
2530
a) if your wireless interface is not 'wlan0' then
2631
set the IFACE variable to your interface name, eg;
27-
IFACE="ath0" aueb wifi up
32+
sudo IFACE="ath0" ./aueb wifi up
2833
b) you may need to turn off any running network
2934
managers to let wifi work.
3035
EOM
@@ -34,17 +39,17 @@ detect_dist() {
3439
printf " ** %s\n" "Detecting distribution .."
3540
dist="$(head -1 -q /etc/*release | sed 's/.*"\(.\+\)".*/\1/' \
3641
| tr [[:upper:]] [[:lower:]])"
37-
confirm_dist $dist && return 0
42+
confirm_dist && return 0
3843

3944
type lsb_release &>/dev/null && dist="$(lsb_release -i \
4045
| awk -F':\t' '{ print $2 }' | tr [[:upper:]] [[:lower:]])"
41-
confirm_dist $dist && return 0 \
46+
confirm_dist && return 0 \
4247
|| printf "\n ** %s\n" "Couldn't detect distribution" && return 1
4348
}
4449

4550
confirm_dist() {
4651
local answer
47-
printf "Is this your distribution: %s (Y/n)? " "$1" && read answer
52+
printf "Is this your distribution: %s (Y/n)? " "$dist" && read answer
4853
[[ -z $answer || $answer =~ ^[yY]$ ]] && return 0 || return 1
4954
}
5055

@@ -65,8 +70,7 @@ choose_dist() {
6570
break
6671
;;
6772
0)
68-
aueb
69-
exit 0
73+
exit
7074
;;
7175
*)
7276
printf " --> Unknown choice: %s. Please try again.\n" "$choice"
@@ -75,7 +79,48 @@ choose_dist() {
7579
done
7680
}
7781

78-
create_profile() {
82+
install_extra() {
83+
# FIXME
84+
echo "Install Extra"
85+
case $dist in
86+
arch)
87+
# TODO:
88+
# download package from AUR
89+
# unpack && makepkg
90+
# pacman -U
91+
;;
92+
ubuntu)
93+
for pkg in ${packages["extra-${dist}"]}; do
94+
# FIXME or create .deb packages ~ similar to arch/AUR
95+
make install $pkg
96+
done
97+
;;
98+
esac
99+
for pkg in ${packages["extra-both"]}; do
100+
# FIXME
101+
make install $pkg
102+
done
103+
}
104+
105+
uninstall_extra() {
106+
case $dist in
107+
arch)
108+
${uninstaller["$dist"]} ${packages["extra-${dist}"]}
109+
;;
110+
ubuntu)
111+
for pkg in ${packages["extra-${dist}"]}; do
112+
# FIXME or remove .deb ~ similar to arch/AUR
113+
make uninstall $pkg
114+
done
115+
;;
116+
esac
117+
for pkg in ${packages["extra-both"]}; do
118+
# FIXME
119+
make uninstall $pkg
120+
done
121+
}
122+
123+
create_wifi_profile() {
79124
[[ -e $wificonf ]] && return
80125
cat > "$wificonf" << EOF
81126
ctrl_interface=${PREFIX}/wpa_aueb
@@ -94,7 +139,10 @@ network={
94139
EOF
95140
}
96141

97-
(( UID )) && printf " --> %s\n" "You must have root priviledges to run this script" && aueb && exit 1
142+
# TODO: uncomment on deploy
143+
# (( UID )) && printf " --> %s\n" "You must have root priviledges to run this script" >&2 && exit 1
144+
145+
dist=
98146

99147
case $1 in
100148
packages)
@@ -108,26 +156,28 @@ case $1 in
108156
)
109157
declare -A packages
110158
packages=( [common]="netbeans geany nmap scilab tcsh wireshark"
111-
[ubuntu]="openjdk-6-jdk build-essential wireless-tools wpasupplicant"
112159
[arch]="openjdk6 base-devel wireless_tools wpa_supplicant"
160+
[extra-arch]="nessus omnetpp4 xampp" ## AUR
161+
[ubuntu]="openjdk-6-jdk build-essential wireless-tools wpasupplicant nessus"
162+
[extra-ubuntu]="omnetpp xampp"
163+
[extra-both]="quartus"
113164
)
114-
dist=
115165

116166
case $2 in
117167
install)
118168
detect_dist || choose_dist
119-
printf " ** Running: %s\n" "${installer["$dist"]} ${packages["common"]} ${packages["$dist"]}" \
120-
&& { printf " ==> %s\n" "Software ready to use"; aueb; exit 0; } \
121-
|| { printf " --> %s\n" "Failed to install packages. Check with your package manager."; aueb; exit 1; }
169+
printf " ** Running: %s\n" "${installer["$dist"]} ${packages["common"]} ${packages["$dist"]}" \
170+
&& install_extra && printf " ==> %s\n" "Software ready to use" \
171+
|| { printf " --> %s\n" "Failed to install packages. Check with your package manager." >&2; exit 1; }
122172
;;
123173
remove)
124174
detect_dist || choose_dist
125175
printf " ** Running: %s\n" "${uninstaller["$dist"]} ${packages["common"]} ${packages["$dist"]}" \
126-
&& { printf " ==> %s\n" "Software removed"; aueb; exit 0; } \
127-
|| { printf " --> %s\n" "Failed to uninstall packages. Check with your package manager."; aueb; exit 1; }
176+
&& uninstall_extra && printf " ==> %s\n" "Software removed" \
177+
|| { printf " --> %s\n" "Failed to uninstall packages. Check with your package manager." >&2; exit 1; }
128178
;;
129179
*)
130-
printf " --> Unknown option: %s\n" "$2"
180+
printf " --> Unknown option: %s\n" "$2" >&2
131181
exit 1
132182
;;
133183
esac
@@ -140,34 +190,33 @@ case $1 in
140190

141191
case $2 in
142192
up)
143-
create_profile
144-
printf " ** Running: %s\n" "wpa_supplicant -Dwext -i${IFACE} -c${wificonf}" \
145-
&& printf " ==> %s\n" "Connected to aueb wireless network" \
146-
|| printf " --> %s\n" "Couldn't connect to wireless network"
193+
create_wifi_profile
194+
printf " ** Running: %s\n" "wpa_supplicant -Dwext -i${IFACE} -c${wificonf}" \
195+
&& printf " ==> %s\n" "Connected to aueb wireless network" \
196+
|| printf " --> %s\n" "Couldn't connect to wireless network" >&2
147197
;;
148198
down)
149199
printf " ** Running: %s\n" "ifconfig ${IFACE} down"
150200
printf " ==> %s\n" "Disconnected wireless connection"
151201
;;
152202
*)
153-
printf " --> Unknown option: %s\n" "$2"
203+
printf " --> Unknown option: %s\n" "$2" >&2
154204
exit 1
155205
;;
156206
esac
157207
;;
158208
help)
159209
usage
160-
exit 0
161210
;;
162211
*)
163-
printf " --> Unknown option: %s\n" "$1"
212+
printf " --> Unknown option: %s\n" "$1" >&2
164213
exit 1
165214
;;
166215
esac
216+
exit
167217

168218
# TODO:
169-
# -- install/remove --
170-
# custom packages for: omnet spim xampp quartus nessus
171-
# -- wifi_toggle --
172-
# follow output and react <- tailf?
219+
# custom packages: omnet xampp quartus nessus
220+
# test wpa_supplicant
173221

222+
# vim: nospell

0 commit comments

Comments
 (0)