Imported Debian patch 20070115-9
[aiccu.git] / debian / aiccu.postinst
blobce6ecec397c22181e3f38f7478fad79a514eb2dc
1 #!/bin/bash -e
3 CONFIGFILE="/etc/aiccu.conf"
4 TMPCONF=/etc/aiccu.conf.dpkg-tmp
5 EXAMPLE=/usr/share/doc/aiccu/examples/aiccu.conf
6 CTLINFO="# Under control from debconf, please use 'dpkg-reconfigure aiccu' to reconfigure"
7 BINARY=/usr/sbin/aiccu
9 . /usr/share/debconf/confmodule
11 db_get aiccu/username
12 USERNAME="$RET"
14 db_get aiccu/password
15 PASSWORD="$RET"
17 AICCUOUT=$($BINARY brokers)
19 db_get aiccu/brokername
20 URL=$(echo "$AICCUOUT" | grep "$RET")
21 PROTO=$(echo $URL | cut -f2 -d'|' | cut -f1 -d:)
22 SERVER=$(echo $URL | cut -f2 -d'|' | cut -f3 -d/)
24 db_get aiccu/tunnelname
25 TUNNEL="$RET"
27 db_stop
29 if [ "$USERNAME" = "" ]; then
30 # Not configured yet, thus skip
31 exit 0;
34 # Defaults when nothing gets chosen
35 # This might happen because of broken DNS
36 if [ "$PROTO" = "" ]; then
37 PROTO="tic"
40 if [ "$SERVER" = "" ]; then
41 SERVER="tic.sixxs.net"
44 # Make sure that files we create are not readable by anyone but us (root)
45 umask 077
47 # Check if the /etc/aiccu.conf is actually the example
48 if [ diff -q $EXAMPLE $CONFIGFILE 2>/dev/null >/dev/null ]; then
49 DEFAULTCONFIG="true"
50 else
51 DEFAULTCONFIG="false"
54 # Install a default config when it didn't exist yet or it is the same as the example
55 # bash uses '==', dash uses '=', thus use '!=' as that is the same
56 if [ "$DEFAULTCONFIG" != "false" -o ! -e "$CONFIGFILE" ]; then
58 # Note that it is under debconf control
59 echo $CTLINFO >> $TMPCONF
61 # Replace the example lines so that they become normals
62 sed -e "
63 /^#username /c username $USERNAME
64 /^#password /c password $PASSWORD
65 /^#protocol /c protocol $PROTO
66 /^#server /c server $SERVER
67 /^#tunnel_id /c tunnel_id $TUNNEL
68 " < $EXAMPLE >> $TMPCONF
70 # Modify the existing one
71 else
72 # Note that it is under debconf control
73 if ! grep -q "^$CTLINFO" $CONFIGFILE; then
74 echo $CTLINFO >> $TMPCONF >>$TMPCONF
77 # Make sure that all the variables can be stored somewhere
78 if ! grep -q "^username" $CONFIGFILE; then
79 if [ "$USERNAME" != "" ]; then
80 echo "username $USERNAME" >> $TMPCONF
84 if ! grep -q "^password" $CONFIGFILE; then
85 if [ "$PASSWORD" != "" ]; then
86 echo "password $PASSWORD" >> $TMPCONF
90 if ! grep -q "^protocol" $CONFIGFILE; then
91 if [ "$PROTO" != "" ]; then
92 echo "protocol $PROTO" >> $TMPCONF
95 if ! grep -q "^server" $CONFIGFILE; then
96 if [ "$SERVER" != "" ]; then
97 echo "server $SERVER" >> $TMPCONF
101 if ! grep -q "^tunnel_id" $CONFIGFILE; then
102 if [ "$TUNNEL" != "" ]; then
103 echo "tunnel_id $TUNNEL" >> $TMPCONF
107 sed -e "
108 /^username /c username $USERNAME
109 /^password /c password $PASSWORD
110 /^protocol /c protocol $PROTO
111 /^server /c server $SERVER
112 /^tunnel_id /c tunnel_id $TUNNEL
113 " < $CONFIGFILE >> $TMPCONF
116 # Move it into place
117 mv -f $TMPCONF $CONFIGFILE
118 # Just in case, make sure the permissions are perfect and dandy
119 chmod 600 $CONFIGFILE
121 #DEBHELPER#