5 CONFIGFILE
=/etc
/aiccu.conf
8 TMPCONF
=$
(tempfile
-p aiccu
-s conf
)
9 TMPFILE
=$
(tempfile
-p aiccu
-s temp
)
10 BROKERS
=$
(tempfile
-p aiccu
-s brokers
)
11 trap 'rm -f $TMPCONF $TMPFILE $BROKERS' TERM INT EXIT QUIT
13 if [ ! -x $BINARY ]; then
14 # Can't configure yet as we don't have our binary yet
18 # Make sure that files we create are not readable by anyone but us (root)
21 .
/usr
/share
/debconf
/confmodule
23 if [ -e $CONFIGFILE ]; then
24 USERNAME
=$
(grep ^username
$CONFIGFILE |
awk '{print $2}')
25 PASSWORD
=$
(grep ^password
$CONFIGFILE |
awk '{print $2}')
26 PROTO
=$
(grep ^protocol
$CONFIGFILE |
awk '{print $2}')
27 SERVER
=$
(grep ^server
$CONFIGFILE |
awk '{print $2}')
28 TUNNEL
=$
(grep ^tunnel_id
$CONFIGFILE |
awk '{print $2}')
30 if [ "$USERNAME" != "" ]; then
31 db_set aiccu
/username
"$USERNAME"
34 if [ "$PASSWORD" != "" ]; then
35 db_set aiccu
/password
"$PASSWORD"
38 if [ "$PROTO" != "" -a "$SERVER" != "" ]; then
39 db_set aiccu
/brokername
"$PROTO://$SERVER"
42 if [ "$TUNNEL" != "" ]; then
43 db_set aiccu
/tunnelname
"$TUNNEL"
48 if [ "$DEBCONF_RECONFIGURE" = "1" -o "$1" = "reconfigure" ]; then
50 elif [ "$TUNNEL" != "" -a "$PROTO" != "" -a "$SERVER" != "" ]; then
51 # Assume that we do not need further configuration.
55 db_reset aiccu
/badauth
58 # 1 Get Tunnel Brokername
63 # Fetch the list of tunnel brokers
64 $BINARY brokers |
sort > $BROKERS
65 BROKERS_RET
="${PIPESTATUS[0]}"
67 while [ $STATE -ge 1 -a $STATE -le 3 ]; do
70 if [ $BROKERS_RET -ne 0 ]; then
71 # No TunnelBrokers found
72 db_input high aiccu
/nobrokers || true
75 # Found Tunnel brokers, present them to the user
76 BROKERS_
=$
(cat $BROKERS | cut
-f1 -d'|' |
awk '{print $0","}')
77 BROKERS_
=$
(echo -n $BROKERS_ |
sed 'N;s/\n//g' |
sed 's/,$//g')
78 db_get aiccu
/brokername
79 if [ "$RET" != "" ]; then
80 SELECTED
=$
(grep "$RET" $BROKERS | cut
-f1 -d'|')
81 db_set aiccu
/brokername
"$SELECTED"
83 db_subst aiccu
/brokername brokers
"$BROKERS_"
84 db_input high aiccu
/brokername || true
91 db_input high aiccu
/username || true
92 db_input high aiccu
/password || true
97 # Reset our temp config file
98 echo "# Temporary AICCU config written by debconf" > $TMPCONF
99 #echo "verbose true" >> $TMPCONF
101 # Take the Protocol and server from the Brokername
102 db_get aiccu
/brokername
103 URL
=$
(cat $BROKERS |
grep "$RET")
104 PROTO
=$
(echo $URL | cut
-f2 -d'|' | cut
-f1 -d:)
105 SERVER
=$
(echo $URL | cut
-f2 -d'|' | cut
-f3 -d/)
106 db_set aiccu
/brokername
"$PROTO://$SERVER"
108 echo "protocol $PROTO" >> $TMPCONF
109 echo "server $SERVER" >> $TMPCONF
111 db_get aiccu
/username
114 db_get aiccu
/password
117 # Try to get the tunnels using the provided user/pass
118 if [ "$USERNAME" != "" -a "$PASSWORD" != "" ]; then
119 echo "username $USERNAME" >> $TMPCONF
120 echo "password $PASSWORD" >> $TMPCONF
122 TUNNELS
=$
($BINARY tunnels
$TMPCONF >$TMPFILE ||
echo badauth
)
124 if [ "$TUNNELS" = "badauth" ]; then
125 db_input high aiccu
/badauth || true
127 db_set aiccu
/badauth
"false"
129 TUNNELS
=$
(cat $TMPFILE | cut
-f1 -d' ' |
awk '{print $0","}')
130 TUNNELS
=$
(echo -n $TUNNELS |
sed 'N;s/\n//g' |
sed 's/,$//g')
132 if [ "$TUNNELS" = "" ]; then
133 db_input high aiccu
/notunnels || true
135 db_subst aiccu
/tunnelname tunnels
"$TUNNELS"
136 db_input high aiccu
/tunnelname || true
141 db_set aiccu
/badauth
"false"
158 # When badly authenticated do it all over
159 if [ "$RET" = "true" ]; then
161 db_reset aiccu
/brokername
162 db_reset aiccu
/username
163 db_reset aiccu
/password
164 db_reset aiccu
/tunnelname
168 db_reset aiccu
/badauth
173 rm -f $TMPCONF $TMPFILE $BROKERS