]> git.ipfire.org Git - people/stevee/aiccu.git/blame - debian/aiccu.config
Add setup script functionality to Linux client
[people/stevee/aiccu.git] / debian / aiccu.config
CommitLineData
d98f6a46
SS
1#!/bin/sh
2
3CONFIGFILE=/etc/aiccu.conf
4TMPCONF=/etc/aiccu.conf.$$.dpkg-tmp
5TMPFILE=/etc/aiccu.temp.$$.dpkg-tmp
6BINARY=/usr/sbin/aiccu
7
8# Note: the two temp files are placed in /etc thus should be symlink-attack safe
9
10if [ ! -x $BINARY ]; then
11 # Can't configure yet as we don't have our binary yet
12 exit 0;
13fi
14
15# Make sure that files we create are not readable by anyone but us (root)
16umask 077
17
18. /usr/share/debconf/confmodule
19
20if [ -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}')
26
27 if [ "$USERNAME" != "" ]; then
28 db_set aiccu/username "$USERNAME"
29 fi
30
31 if [ "$PASSWORD" != "" ]; then
32 db_set aiccu/password "$PASSWORD"
33 fi
34
35 if [ "$PROTO" != "" -a "$SERVER" != "" ]; then
36 db_set aiccu/brokername "$PROTO://$SERVER"
37 fi
38
39 if [ "$TUNNEL" != "" ]; then
40 db_set aiccu/tunnelname "$TUNNEL"
41 fi
42fi
43
44
45db_reset aiccu/badauth
46
47#
48# State What
49# 1 Get Tunnel Brokername
50# 2 Get User/pass
51# 3 Get Tunnel ID
52# 4 Exit
53
54STATE=1
55while [ $STATE -ge 1 -a $STATE -le 3 ]; do
56
57 case "$STATE" in
58 1)
59 # Fetch the list of tunnel brokers
60 BROKERS=$($BINARY brokers | sort >$TMPFILE)
61
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
74 fi
75
76 # Remove temporary file
77 rm $TMPFILE
78 ;;
79
80 2)
81 # Request User / Pass
82 db_input high aiccu/username || true
83 db_input high aiccu/password || true
84 db_go || true
85 ;;
86
87 3)
88 # Reset our temp config file
89 echo "# Temporary AICCU config written by debconf" > $TMPCONF
90 #echo "verbose true" >> $TMPCONF
91
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/)
97
98 echo "protocol $PROTO" >> $TMPCONF
99 echo "server $SERVER" >> $TMPCONF
100
101 db_get aiccu/username
102 USERNAME="$RET"
103
104 db_get aiccu/password
105 PASSWORD="$RET"
106
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
111
112 TUNNELS=$($BINARY tunnels $TMPCONF >$TMPFILE)
113
114 if [ "$?" != "0" ]; then
115 db_input high aiccu/badauth || true
116 else
117 db_set aiccu/badauth "false"
118
119 TUNNELS=$(cat $TMPFILE | cut -f1 -d' ' | awk '{print $0","}')
120 TUNNELS=$(echo -n $TUNNELS | sed 'N;s/\n//g' | sed 's/,$//g')
121
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
128 fi
129 fi
130
131 # Remove temporary file
132 rm $TMPFILE
133 else
134 db_set aiccu/badauth "false"
135 fi
136
137 # Remove the temporary as we don't need it anymore
138 rm $TMPCONF
139 ;;
140 esac
141
142 db_go
143
144 case "$STATE" in
145 1)
146 STATE=2
147 ;;
148 2)
149 STATE=3
150 ;;
151 3)
152 db_get aiccu/badauth
153
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
163 fi
164 db_reset aiccu/badauth
165 ;;
166 esac
167done
168