Changes for kernel and Busybox
[tomato.git] / release / src / router / bpalogin / bpalogin.conf.sh
blobc37170b5da15cd5071172c3d558d7c59a50117cd
1 #!/bin/sh
2 #
3 # Configuration script for BPALogin
5 # Creates a new bpalogin.conf file based on the installed template, prompting
6 # for overrides.
8 # Relies heavily on the formatting of the bpalogin.conf file and is sensitive
9 # to whitespace! Be careful when changing bpalogin.conf.
11 # Copyright 2003 William Rose <wdrose@sourceforge.net> and licensed under the
12 # GNU GPL, as per the rest of BPALogin.
13 ###
15 CONFIG_FILE="${1:-/etc/bpalogin.conf}"
16 TMP_DIR="${TMPDIR:-/tmp}"
17 NEW_CONFIG="`mktemp $TMP_DIR/bpalogin.conf-XXXXXX`"
19 if ! [ -r "$CONFIG_FILE" ]
20 then
21 echo "Usage: bpalogin.conf.sh config-file-name"
22 exit 1
25 eval `cat "$CONFIG_FILE" | \
26 (while read
28 case "$REPLY" in
29 '# '*)
30 # Comment line
33 '#'*)
34 # Unspecified option
35 REPLY="${REPLY#\#}"
36 if [ -n "$REPLY" ]
37 then
38 name="${REPLY%% *}"
39 value="${REPLY#* }"
41 echo "$name=\"$value\""
42 echo "${name}_disabled=\"yes\""
43 disabled="$disabled $name"
48 # Empty line or specified option
49 if [ -n "$REPLY" ]
50 then
51 name="${REPLY%% *}"
52 value="${REPLY#* }"
54 echo "$name=\"$value\""
55 echo "${name}_disabled=\"no\""
56 variables="$variables $name"
59 esac
60 done
61 echo "variables=\"${variables# }\""
62 echo "disabled=\"${disabled# }\""
66 # Prompt for new values for already configured variables.
68 if [ -n "$variables" ]
69 then
70 cat <<EOF
73 BPALogin Configuration
74 ----------------------
76 You will now be prompted for some basic details about your connection.
78 When prompted, the current information is displayed in square brackets.
79 Press Enter to accept the current information, or else type the new details
80 and press Enter.
83 EOF
85 for var in $variables
87 echo -n "Enter $var [`eval 'echo $'$var`]: "
88 if read && [ -n "$REPLY" ]
89 then
90 eval "$var=\"$REPLY\""
92 done
96 # Prompt for additional configuration details if disabled configuration
97 # options were detected.
98 if [ -n "$disabled" ]
99 then
100 echo
101 echo -n "Would you like to configure additional options? (y/n): "
102 read
103 case "$REPLY" in
104 [Yy]*)
105 cat <<EOF
108 Additional Configuration
109 ------------------------
111 You will now be prompted for some additional details about your connection.
113 When prompted, the default information is displayed in square brackets.
114 Press Enter to use the default information in your configuration file, or
115 else type the new details. If you do not wish to have any value recorded
116 in your configuration file, type # and press Enter.
120 for var in $disabled
122 echo -n "Enter $var [`eval 'echo $'$var`]: "
123 if read
124 then
125 if [ -n "$REPLY" ]
126 then
127 if [ "$REPLY" = "#" ]
128 then
129 eval "${var}_disabled=\"yes\""
130 else
131 eval "${var}_disabled=\"no\""
132 eval "$var=\"$REPLY\""
134 else
135 eval "${var}_disabled=\"no\""
138 done
142 esac
147 # Create the new bpalogin.conf file
148 cat "$CONFIG_FILE" | \
149 (while read;
151 case "$REPLY" in
152 '# '*)
153 # Comment line
154 echo $REPLY >> "$NEW_CONFIG"
157 '#'*)
158 # Unspecified option
159 REPLY="${REPLY#\#}"
160 if [ -n "$REPLY" ]
161 then
162 name="${REPLY%% *}"
164 if eval "[ \"\$${name}_disabled\" = \"yes\" ]"
165 then
166 echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
167 else
168 echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
170 else
171 echo $REPLY >> "$NEW_CONFIG"
176 if [ -n "$REPLY" ]
177 then
178 name="${REPLY%% *}"
180 if eval "[ \"\$${name}_disabled\" = \"yes\" ]"
181 then
182 echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
183 else
184 echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
186 else
187 echo $REPLY >> "$NEW_CONFIG"
190 esac
191 done)
193 echo
194 echo "New configuration successfully saved in $NEW_CONFIG"
195 echo -n "Overwrite $CONFIG_FILE with this file? (y/n) "
196 read
198 case "$REPLY" in
199 [Yy]*)
200 if mv "$NEW_CONFIG" "$CONFIG_FILE"
201 then
202 echo "Your BPALogin configuration file has been updated."
203 else
204 echo "Action failed. Please copy $NEW_CONFIG to $CONFIG_FILE manually."
207 if ! chmod 600 "$CONFIG_FILE"
208 then
209 echo "Unable to change permissions for your configuration file."
210 echo "Please check your configuration file is not readable by others."
214 echo "Your original BPALogin configuration file was not changed."
216 esac
218 echo