blob: 86b5d0932dd9c8a776ca06ef38d299ec97ccbda0 (
plain)
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
|
#! /bin/bash
. /usr/lib/network/network
if ! type dialog &> /dev/null; then
echo "Please install 'dialog' to use netcfg-menu"
exit 1
fi
check_make_state_dir
# JP: we'll use $STATE_DIR/menu to record what profile is being connected in this way
rm -f "$STATE_DIR/menu"
# Scan all profiles
i=0
# JP: change for prof to while read prof to avoid assumption that profile names are always single tokens (no spaces etc.)
while read prof; do
# if there is a profile called "main", Use as default
[[ "$prof" = "main" ]] && DEFAULT="main"
profiles[i++]="$prof"
profiles[i++]=$(. "$PROFILE_DIR/$prof"; echo "$DESCRIPTION")
done < <(list_profiles | sort) # JP: re-use list_profiles instead of duplicating it; avoid subshell we'd get by piping it to the while read...
if [[ ${#profiles} -eq 0 ]]; then
exit_err "No profiles were found in $PROFILE_DIR"
fi
[[ -n "$NETWORKS_MENU_DEFAULT" ]] && DEFAULT="$NETWORKS_MENU_DEFAULT"
# if no default yet, use the first entry
[[ -z "$DEFAULT" ]] && DEFAULT="${profiles[0]}"
# Set timeout
if [[ -z "$1" ]]; then
TIMEOUT="0"
else
TIMEOUT="$1"
fi
# Display Dialog
PROFILE=$(dialog --timeout "$TIMEOUT" --default-item "$DEFAULT" --stdout \
--menu 'Select the network profile you wish to use' \
13 50 6 "${profiles[@]}")
ret=$?
case $ret in
1) ;; # Cancel - do nothing
255|0) # Timeout (use default) or user selection
[[ -z "$PROFILE" ]] && PROFILE="$DEFAULT"
profile_up "$PROFILE"
ret=$?
(( ret == 0 )) && echo "$PROFILE" > "$STATE_DIR/menu"
;;
*) # Shouldnt happen
exit_err "Abnormal ret code from dialog: $ret"
;;
esac
exit $ret # JP: exit with caught $?
# vim: ft=sh ts=4 et sw=4:
|