Imported Upstream version 20070115
[aiccu.git] / debian / aiccu.config
blob6f7d8eb82696b392483b1e3e0e5aff2938be526f
1 #!/bin/sh
3 CONFIGFILE=/etc/aiccu.conf
4 TMPCONF=/etc/aiccu.conf.$$.dpkg-tmp
5 TMPFILE=/etc/aiccu.temp.$$.dpkg-tmp
6 BINARY=/usr/sbin/aiccu
8 # Note: the two temp files are placed in /etc thus should be symlink-attack safe
10 if [ ! -x $BINARY ]; then
11 # Can't configure yet as we don't have our binary yet
12 exit 0;
15 # Make sure that files we create are not readable by anyone but us (root)
16 umask 077
18 . /usr/share/debconf/confmodule
20 if [ -e $CONFIGFILE ]; then
21 USERNAME=$(grep ^username $CONFIGFILE | awk '{print $2}')
22 PASSWORD=$(grep ^password $CONFIGFILE | awk '{print $2}')
23 PROTO=$(grep ^protocol $CONFIGFILE | awk '{print $2}')
24 SERVER=$(grep ^server $CONFIGFILE | awk '{print $2}')
25 TUNNEL=$(grep ^tunnel_id $CONFIGFILE | awk '{print $2}')
27 if [ "$USERNAME" != "" ]; then
28 db_set aiccu/username "$USERNAME"
31 if [ "$PASSWORD" != "" ]; then
32 db_set aiccu/password "$PASSWORD"
35 if [ "$PROTO" != "" -a "$SERVER" != "" ]; then
36 db_set aiccu/brokername "$PROTO://$SERVER"
39 if [ "$TUNNEL" != "" ]; then
40 db_set aiccu/tunnelname "$TUNNEL"
45 db_reset aiccu/badauth
48 # State What
49 # 1 Get Tunnel Brokername
50 # 2 Get User/pass
51 # 3 Get Tunnel ID
52 # 4 Exit
54 STATE=1
55 while [ $STATE -ge 1 -a $STATE -le 3 ]; do
57 case "$STATE" in
59 # Fetch the list of tunnel brokers
60 BROKERS=$($BINARY brokers | sort >$TMPFILE)
62 if [ "$?" != "0" ]; then
63 # No TunnelBrokers found
64 db_input high aiccu/nobrokers || true
65 echo "No brokers"
66 else
67 # Found Tunnel brokers, present them to the user
68 BROKERS=$(cat $TMPFILE | cut -f1 -d'|' | awk '{print $0","}')
69 BROKERS=$(echo -n $BROKERS | sed 'N;s/\n//g' | sed 's/,$//g')
70 db_subst aiccu/brokername brokers "$BROKERS"
71 db_fset aiccu/brokername seen false
72 db_input high aiccu/brokername || true
73 db_go || true
76 # Remove temporary file
77 rm $TMPFILE
81 # Request User / Pass
82 db_input high aiccu/username || true
83 db_input high aiccu/password || true
84 db_go || true
88 # Reset our temp config file
89 echo "# Temporary AICCU config written by debconf" > $TMPCONF
90 #echo "verbose true" >> $TMPCONF
92 # Take the Protocol and server from the Brokername
93 db_get aiccu/brokername
94 URL=$($BINARY brokers | grep "$RET")
95 PROTO=$(echo $URL | cut -f2 -d'|' | cut -f1 -d:)
96 SERVER=$(echo $URL | cut -f2 -d'|' | cut -f3 -d/)
98 echo "protocol $PROTO" >> $TMPCONF
99 echo "server $SERVER" >> $TMPCONF
101 db_get aiccu/username
102 USERNAME="$RET"
104 db_get aiccu/password
105 PASSWORD="$RET"
107 # Try to get the tunnels using the provided user/pass
108 if [ "$USERNAME" != "" -a "$PASSWORD" != "" ]; then
109 echo "username $USERNAME" >> $TMPCONF
110 echo "password $PASSWORD" >> $TMPCONF
112 TUNNELS=$($BINARY tunnels $TMPCONF >$TMPFILE)
114 if [ "$?" != "0" ]; then
115 db_input high aiccu/badauth || true
116 else
117 db_set aiccu/badauth "false"
119 TUNNELS=$(cat $TMPFILE | cut -f1 -d' ' | awk '{print $0","}')
120 TUNNELS=$(echo -n $TUNNELS | sed 'N;s/\n//g' | sed 's/,$//g')
122 if [ "$TUNNELS" = "" ]; then
123 db_input high aiccu/notunnels || true
124 else
125 db_subst aiccu/tunnelname tunnels "$TUNNELS"
126 db_input high aiccu/tunnelname || true
127 db_go || true
131 # Remove temporary file
132 rm $TMPFILE
133 else
134 db_set aiccu/badauth "false"
137 # Remove the temporary as we don't need it anymore
138 rm $TMPCONF
140 esac
142 db_go
144 case "$STATE" in
146 STATE=2
149 STATE=3
152 db_get aiccu/badauth
154 # When badly authenticated do it all over
155 if [ "$RET" = "true" ]; then
156 STATE=1
157 db_reset aiccu/brokername
158 db_reset aiccu/username
159 db_reset aiccu/password
160 db_reset aiccu/tunnelname
161 else
162 STATE=4
164 db_reset aiccu/badauth
166 esac
167 done