2 # postinst script for aiccu
4 # Abort if any command returns an error value
7 CONFIGFILE
="/etc/aiccu.conf"
8 TMPCONF
=/etc
/aiccu.conf.dpkg-tmp
9 TEMPLATE
=/usr
/share
/aiccu
/conf-templates
/aiccu.conf
10 CTLINFO
="# Under control from debconf, please use 'dpkg-reconfigure aiccu' to reconfigure"
11 BINARY
=/usr
/sbin
/aiccu
13 trap 'rm -f $TUNCONF $TMPCONF $TUNFILE' TERM INT EXIT QUIT
16 configure|reconfigure
)
17 # source debconf libary.
18 .
/usr
/share
/debconf
/confmodule
20 # find out what the user answered.
21 db_get aiccu
/username || true
24 db_get aiccu
/password || true
27 db_get aiccu
/brokername || true
28 PROTO
=$
(echo $RET | cut
-f1 -d:)
29 SERVER
=$
(echo $RET | cut
-f3 -d/)
31 # Try to get the tunnels using the provided user/pass
32 if [ "$USERNAME" != "" -a "$PASSWORD" != "" ]; then
33 TUNCONF
=$
(tempfile
-p aiccu
-s tunconf
)
34 TUNFILE
=$
(tempfile
-p aiccu
-s tunfile
)
36 echo "username $USERNAME" >> $TUNCONF
37 echo "password $PASSWORD" >> $TUNCONF
39 $BINARY tunnels
$TUNCONF >$TUNFILE || true
41 COUNT
=$
(wc -l $TUNFILE | cut
-f1 -d' ')
44 # No tunnels or bad authentication -> leave unconfigured
48 # 1 tunnel found -> auto config
49 db_set aiccu
/tunnelname $
(cat $TUNFILE | cut
-f1 -d' ')
52 # >1 tunnel found -> ask user which tunnel to use
53 TUNNELS
=$
(cat $TUNFILE | cut
-f1 -d' ' |
awk '{print $0","}')
54 TUNNELS
=$
(echo -n $TUNNELS |
sed -e 's/,$//g')
56 db_subst aiccu
/tunnelname tunnels
"$TUNNELS"
57 db_input high aiccu
/tunnelname || true
63 db_get aiccu
/tunnelname || true
66 # Register configuration file with ucf
67 ucfr aiccu
$CONFIGFILE
69 if [ "$USERNAME" = "" ]; then
70 # Not configured yet, thus skip
71 install -m 600 $TEMPLATE $CONFIGFILE
75 # Defaults when nothing gets chosen
76 # This might happen because of broken DNS
77 if [ "$PROTO" = "" ]; then
81 if [ "$SERVER" = "" ]; then
82 SERVER
="tic.sixxs.net"
85 # Make sure that files we create are not readable by anyone but us (root)
88 # Note that it is under debconf control
89 echo $CTLINFO >> $TMPCONF
91 # Replace the example lines so that they become normals
93 /^#username /c username $USERNAME
94 /^#protocol /c protocol $PROTO
95 /^#server /c server $SERVER
96 " < $TEMPLATE >> $TMPCONF
98 if [ "$PASSWORD" != "" ]; then
99 sed -i -e "/^#password /c password $PASSWORD" $TMPCONF
102 if [ "$TUNNEL" != "" ]; then
103 sed -i -e "/^#tunnel_id /c tunnel_id $TUNNEL" $TMPCONF
106 # Remove config if equal to template
107 if diff -q $TEMPLATE $CONFIGFILE; then
111 # Put config file into place
112 if [ -f $CONFIGFILE ]; then
113 ucf
--debconf-ok $TMPCONF $CONFIGFILE
116 install -m 600 $TMPCONF $CONFIGFILE
119 # Remove password from database
120 db_reset aiccu
/password
122 ### END (re)configure ###
125 abort-upgrade|abort-remove|abort-deconfigure
)
129 echo "postinst called with unknown argument \`$1'" >&2
134 rm -f $TUNCONF $TMPCONF $TUNFILE
136 # dh_installdeb will replace this with shell code automatically
137 # generated by other debhelper scripts.