Merge branch 'mw/config'
[aiccu.git] / debian / aiccu.postinst
blobb6b7383bcb6bead48b4e2f636211fc6634b52d68
1 #!/bin/sh
2 # postinst script for aiccu
4 # Abort if any command returns an error value
5 set -ex
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 case "$1" in
14 configure|reconfigure)
15 # Load debconf libary
16 . /usr/share/debconf/confmodule
18 ### find out what the user answered.
19 db_get aiccu/username || true
20 USERNAME="$RET"
22 db_get aiccu/password || true
23 PASSWORD="$RET"
25 AICCUOUT=$($BINARY brokers)
27 db_get aiccu/brokername || true
28 URL=$(echo "$AICCUOUT" | grep "$RET")
29 PROTO=$(echo $URL | cut -f2 -d'|' | cut -f1 -d:)
30 SERVER=$(echo $URL | cut -f2 -d'|' | cut -f3 -d/)
32 db_get aiccu/tunnelname || true
33 TUNNEL="$RET"
35 # Register configuration file with ucf
36 ucfr aiccu $CONFIGFILE
38 if [ "$USERNAME" = "" ]; then
39 # Not configured yet, thus skip
40 cp $TEMPLATE $CONFIGFILE
41 exit 0;
44 # Defaults when nothing gets chosen
45 # This might happen because of broken DNS
46 if [ "$PROTO" = "" ]; then
47 PROTO="tic"
50 if [ "$SERVER" = "" ]; then
51 SERVER="tic.sixxs.net"
54 # Make sure that files we create are not readable by anyone but us (root)
55 umask 077
57 # Note that it is under debconf control
58 echo $CTLINFO >> $TMPCONF
60 # Replace the example lines so that they become normals
61 sed -e "
62 /^#username /c username $USERNAME
63 /^#protocol /c protocol $PROTO
64 /^#server /c server $SERVER
65 " < $TEMPLATE >> $TMPCONF
67 if [ "$PASSWORD" != "" ]; then
68 sed -i -e "/^#password /c password $PASSWORD" $TMPCONF
71 if [ "$TUNNEL" != "" ]; then
72 sed -i -e "/^#tunnel_id /c tunnel_id $TUNNEL" $TMPCONF
75 # Remove config if equal to template
76 if diff -q $TEMPLATE $CONFIGFILE; then
77 rm -f $CONFIGFILE
80 # Put config file into place
81 if [ -f $CONFIGFILE ]; then
82 ucf --debconf-ok $TMPCONF $CONFIGFILE
83 rm -f $TMPCONF
84 else
85 mv $TMPCONF $CONFIGFILE
88 # Just in case, make sure the permissions are perfect and dandy
89 chmod 600 $CONFIGFILE
91 # Remove password from database
92 db_reset aiccu/password
94 ### END (re)configure ###
97 abort-upgrade|abort-remove|abort-deconfigure)
101 echo "postinst called with unknown argument \`$1'" >&2
102 exit 1
104 esac
106 # dh_installdeb will replace this with shell code automatically
107 # generated by other debhelper scripts.
109 #DEBHELPER#
111 exit 0