Revert "debug; set -x to config"
[aiccu.git] / debian / aiccu.postinst
blob399d1e0583fee78fe5956b52cda229e045b343d1
1 #!/bin/sh
2 # postinst script for aiccu
4 # Abort if any command returns an error value
5 set -e
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
15 case "$1" in
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
22 USERNAME="$RET"
24 db_get aiccu/password || true
25 PASSWORD="$RET"
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' ')
42 case $COUNT in
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
58 db_go || true
60 esac
63 db_get aiccu/tunnelname || true
64 TUNNEL="$RET"
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
72 exit 0;
75 # Defaults when nothing gets chosen
76 # This might happen because of broken DNS
77 if [ "$PROTO" = "" ]; then
78 PROTO="tic"
81 if [ "$SERVER" = "" ]; then
82 SERVER="tic.sixxs.net"
85 # Make sure that files we create are not readable by anyone but us (root)
86 umask 077
88 # Note that it is under debconf control
89 echo $CTLINFO >> $TMPCONF
91 # Replace the example lines so that they become normals
92 sed -e "
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
108 rm -f $CONFIGFILE
111 # Put config file into place
112 if [ -f $CONFIGFILE ]; then
113 ucf --debconf-ok $TMPCONF $CONFIGFILE
114 rm -f $TMPCONF
115 else
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
130 exit 1
132 esac
134 rm -f $TUNCONF $TMPCONF $TUNFILE
136 # dh_installdeb will replace this with shell code automatically
137 # generated by other debhelper scripts.
139 #DEBHELPER#
141 exit 0