File: bpalogin.conf.sh

package info (click to toggle)
bpalogin 2.0.2-12
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 320 kB
  • ctags: 92
  • sloc: ansic: 1,248; sh: 418; makefile: 83
file content (219 lines) | stat: -rwxr-xr-x 4,469 bytes parent folder | download
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
#!/bin/sh
# 
# Configuration script for BPALogin
#
# Creates a new bpalogin.conf file based on the installed template, prompting
# for overrides.
#
# Relies heavily on the formatting of the bpalogin.conf file and is sensitive
# to whitespace!  Be careful when changing bpalogin.conf.
#
# Copyright 2003 William Rose <wdrose@sourceforge.net> and licensed under the
# GNU GPL, as per the rest of BPALogin.
###

CONFIG_FILE="${1:-/etc/bpalogin.conf}"
TMP_DIR="${TMPDIR:-/tmp}"
NEW_CONFIG="`mktemp $TMP_DIR/bpalogin.conf-XXXXXX`"

if ! [ -r "$CONFIG_FILE" ]
then
  echo "Usage: bpalogin.conf.sh config-file-name"
  exit 1
fi

eval `cat "$CONFIG_FILE" | \
(while read REPLY
  do
    case "$REPLY" in
      '# '*)
        # Comment line
      ;;
      
      '#'*)
        # Unspecified option
	REPLY="${REPLY#\#}"
        if [ -n "$REPLY" ]
	then
	  name="${REPLY%% *}"
	  value="${REPLY#* }"

	  echo "$name=\"$value\""
	  echo "${name}_disabled=\"yes\""
	  disabled="$disabled $name"
	fi
      ;;
      
      *)
	# Empty line or specified option
        if [ -n "$REPLY" ]
	then
	  name="${REPLY%% *}"
	  value="${REPLY#* }"

	  echo "$name=\"$value\""
	  echo "${name}_disabled=\"no\""
	  variables="$variables $name"
	fi
      ;;
    esac
  done
  echo "variables=\"${variables# }\""
  echo "disabled=\"${disabled# }\""
)`

##
# Prompt for new values for already configured variables.
#
if [ -n "$variables" ]
then
  cat <<EOF


BPALogin Configuration
----------------------

You will now be prompted for some basic details about your connection.

When prompted, the current information is displayed in square brackets.
Press Enter to accept the current information, or else type the new details
and press Enter.


EOF

  for var in $variables
  do
    echo -n "Enter $var [`eval 'echo $'$var`]: "
    if read REPLY && [ -n "$REPLY" ]
    then
      eval "$var=\"$REPLY\""
    fi
  done
fi

##
# Prompt for additional configuration details if disabled configuration
# options were detected.
if [ -n "$disabled" ]
then
  echo
  echo -n "Would you like to configure additional options? (y/n): "
  read REPLY
  case "$REPLY" in
    [Yy]*)
      cat <<EOF


Additional Configuration
------------------------

You will now be prompted for some additional details about your connection.

When prompted, the default information is displayed in square brackets.
Press Enter to use the default information in your configuration file, or
else type the new details.  If you do not wish to have any value recorded
in your configuration file, type # and press Enter.


EOF
      for var in $disabled
      do
	echo -n "Enter $var [`eval 'echo $'$var`]: "
	if read REPLY
	then
	  if [ -n "$REPLY" ]
	  then
	    if [ "$REPLY" = "#" ]
	    then
	      eval "${var}_disabled=\"yes\""
	    else
	      eval "${var}_disabled=\"no\""
	      eval "$var=\"$REPLY\""
	    fi
	  else
	    eval "${var}_disabled=\"no\""
	  fi
	fi
      done
      ;;
    *)
      ;;
  esac
fi


##
# Create the new bpalogin.conf file
cat "$CONFIG_FILE" | \
(while read REPLY;
  do
    case "$REPLY" in
      '# '*)
	# Comment line
	echo $REPLY >> "$NEW_CONFIG"
      ;;
      
      '#'*)
        # Unspecified option
	REPLY="${REPLY#\#}"
	if [ -n "$REPLY" ]
	then
	  name="${REPLY%% *}"

	  if eval "[ \"\$${name}_disabled\" = \"yes\" ]"
	  then
	    echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
	  else
	    echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
	  fi
	else
	  echo $REPLY >> "$NEW_CONFIG"
	fi
      ;;
      
      *)
	if [ -n "$REPLY" ]
	then
	  name="${REPLY%% *}"

	  if eval "[ \"\$${name}_disabled\" = \"yes\" ]"
	  then
	    echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
	  else
	    echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG"
	  fi
	else
	  echo $REPLY >> "$NEW_CONFIG"
	fi
      ;;
    esac
  done)

echo
echo "New configuration successfully saved in $NEW_CONFIG"
echo -n "Overwrite $CONFIG_FILE with this file? (y/n) "
read REPLY

case "$REPLY" in
  [Yy]*)
    if mv "$NEW_CONFIG" "$CONFIG_FILE"
    then
      echo "Your BPALogin configuration file has been updated."
    else
      echo "Action failed.  Please copy $NEW_CONFIG to $CONFIG_FILE manually."
    fi

    if ! chmod 600 "$CONFIG_FILE"
    then
      echo "Unable to change permissions for your configuration file."
      echo "Please check your configuration file is not readable by others."
    fi
    ;;
  *)
    echo "Your original BPALogin configuration file was not changed."
    ;;
esac

echo