~ubuntu-branches/ubuntu/quantal/aiccu/quantal

« back to all changes in this revision

Viewing changes to debian/aiccu.postinst

  • Committer: Bazaar Package Importer
  • Author(s): Reinier Haasjes
  • Date: 2010-01-06 10:02:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100106100224-x7vwy93uaexg8rhr
Tags: 20070115-11
* New maintainer. (Closes: #529185: ITA: aiccu -- SixXS Automatic IPv6
  Connectivity Client Utility)
* Install aiccu.conf to usr/share/aiccu/conf-templates/ 
  and use in postinst (Closes: #559683) - Thanks to Patrick Schoenfeld
* Fix "leaves password in debconf database" add db_reset to postinst
  (Closes: #512674)
* Fix "tunnel does not survive suspend" Add restart script to 
  /etc/pm/sleep.d (Closes: #531003)
* Added Japanese translation (Closes: #562803) - Thanks to Hideki Yamane
* Fix "uses non-essential tools in the config script" (Closes: #561324)
  - get brokers list by dns (instead of own binary)
  - supply static brokerlist if dns is unavailable
  - get tunnel ID in postinst (using own binary)
* Minimize rules file - Thanks to Patrick Schoenfeld
* Added VCS-Headers
* Fixed spelling-error-in-binary
* Fixed maintainer-script-empty preinst
* Fixed maintainer-script-without-set-e postinst
* Upgraded compat version to 7
* Added debian/README.source
* Upgraded standards-version to 3.8.3
* Added "no-upstream-changelog" to lintian-overrides
* Add dependency on ucf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash -e
 
1
#!/bin/sh
 
2
# postinst script for aiccu
 
3
 
 
4
# Abort if any command returns an error value
 
5
set -e
2
6
 
3
7
CONFIGFILE="/etc/aiccu.conf"
4
8
TMPCONF=/etc/aiccu.conf.dpkg-tmp
5
 
EXAMPLE=/usr/share/doc/aiccu/examples/aiccu.conf
 
9
TEMPLATE=/usr/share/aiccu/conf-templates/aiccu.conf
6
10
CTLINFO="# Under control from debconf, please use 'dpkg-reconfigure aiccu' to reconfigure"
7
11
BINARY=/usr/sbin/aiccu
8
12
 
9
 
. /usr/share/debconf/confmodule
10
 
 
11
 
db_get aiccu/username
12
 
USERNAME="$RET"
13
 
 
14
 
db_get aiccu/password
15
 
PASSWORD="$RET"
16
 
 
17
 
AICCUOUT=$($BINARY brokers)
18
 
 
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/)
23
 
 
24
 
db_get aiccu/tunnelname
25
 
TUNNEL="$RET"
26
 
 
27
 
db_stop
28
 
 
29
 
if [ "$USERNAME" = "" ]; then
30
 
        # Not configured yet, thus skip
31
 
        exit 0;
32
 
fi
33
 
 
34
 
# Defaults when nothing gets chosen
35
 
# This might happen because of broken DNS
36
 
if [ "$PROTO" = "" ]; then
37
 
        PROTO="tic"
38
 
fi
39
 
 
40
 
if [ "$SERVER" = "" ]; then
41
 
        SERVER="tic.sixxs.net"
42
 
fi
43
 
 
44
 
# Make sure that files we create are not readable by anyone but us (root)
45
 
umask 077
46
 
 
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"
52
 
fi
53
 
 
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
57
 
 
58
 
        # Note that it is under debconf control
59
 
        echo $CTLINFO >> $TMPCONF
60
 
 
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
69
 
 
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
75
 
        fi
76
 
 
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
81
 
                fi
82
 
        fi
83
 
 
84
 
        if ! grep -q "^password" $CONFIGFILE; then
85
 
                if [ "$PASSWORD" != "" ]; then
86
 
                        echo "password $PASSWORD" >> $TMPCONF
87
 
                fi
88
 
        fi
89
 
 
90
 
        if ! grep -q "^protocol" $CONFIGFILE; then
91
 
                if [ "$PROTO" != "" ]; then
92
 
                        echo "protocol $PROTO" >> $TMPCONF
93
 
                fi
94
 
        fi
95
 
        if ! grep -q "^server" $CONFIGFILE; then
96
 
                if [ "$SERVER" != "" ]; then
97
 
                        echo "server $SERVER" >> $TMPCONF
98
 
                fi
99
 
        fi
100
 
 
101
 
        if ! grep -q "^tunnel_id" $CONFIGFILE; then
102
 
                if [ "$TUNNEL" != "" ]; then
103
 
                        echo "tunnel_id $TUNNEL" >> $TMPCONF
104
 
                fi
105
 
        fi
106
 
 
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
114
 
fi
115
 
 
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
 
13
trap 'rm -f $TUNCONF $TMPCONF $TUNFILE' TERM INT EXIT QUIT
 
14
 
 
15
case "$1" in
 
16
    configure|reconfigure)
 
17
    # source debconf libary.
 
18
    . /usr/share/debconf/confmodule
 
19
 
 
20
    # find out what the user answered.
 
21
    db_get aiccu/username || true
 
22
    USERNAME="$RET"
 
23
 
 
24
    db_get aiccu/password || true
 
25
    PASSWORD="$RET"
 
26
 
 
27
    db_get aiccu/brokername || true
 
28
    PROTO=$(echo $RET | cut -f1 -d:)
 
29
    SERVER=$(echo $RET | cut -f3 -d/)
 
30
 
 
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)
 
35
 
 
36
        echo "username $USERNAME" >> $TUNCONF
 
37
        echo "password $PASSWORD" >> $TUNCONF
 
38
 
 
39
        $BINARY tunnels $TUNCONF >$TUNFILE || true
 
40
 
 
41
        COUNT=$(wc -l $TUNFILE | cut -f1 -d' ')
 
42
        case $COUNT in
 
43
        0)
 
44
                # No tunnels or bad authentication -> leave unconfigured
 
45
                :
 
46
                ;;
 
47
        1)
 
48
                # 1 tunnel found -> auto config
 
49
                db_set aiccu/tunnelname $(cat $TUNFILE | cut -f1 -d' ') 
 
50
                ;;
 
51
        *)
 
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')
 
55
 
 
56
                db_subst aiccu/tunnelname tunnels "$TUNNELS"
 
57
                db_input high aiccu/tunnelname || true
 
58
                db_go || true
 
59
                ;;
 
60
        esac
 
61
    fi
 
62
 
 
63
    db_get aiccu/tunnelname || true
 
64
    TUNNEL="$RET"
 
65
 
 
66
    # Register configuration file with ucf
 
67
    ucfr aiccu $CONFIGFILE
 
68
 
 
69
    if [ "$USERNAME" = "" ]; then
 
70
        # Not configured yet, thus skip
 
71
        install -m 600 $TEMPLATE $CONFIGFILE
 
72
        exit 0;
 
73
    fi
 
74
 
 
75
    # Defaults when nothing gets chosen
 
76
    # This might happen because of broken DNS
 
77
    if [ "$PROTO" = "" ]; then
 
78
        PROTO="tic"
 
79
    fi
 
80
 
 
81
    if [ "$SERVER" = "" ]; then
 
82
        SERVER="tic.sixxs.net"
 
83
    fi
 
84
 
 
85
    # Make sure that files we create are not readable by anyone but us (root)
 
86
    umask 077
 
87
 
 
88
    # Note that it is under debconf control
 
89
    echo $CTLINFO >> $TMPCONF
 
90
 
 
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
 
97
 
 
98
    if [ "$PASSWORD" != "" ]; then
 
99
        sed -i -e "/^#password /c password $PASSWORD" $TMPCONF
 
100
    fi
 
101
 
 
102
    if [ "$TUNNEL" != "" ]; then
 
103
        sed -i -e "/^#tunnel_id /c tunnel_id $TUNNEL" $TMPCONF
 
104
    fi
 
105
 
 
106
    # Remove config if equal to template
 
107
    if diff -q $TEMPLATE $CONFIGFILE; then
 
108
        rm -f $CONFIGFILE
 
109
    fi
 
110
 
 
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
 
117
    fi
 
118
 
 
119
    # Remove password from database
 
120
    db_reset aiccu/password
 
121
 
 
122
    ### END (re)configure ###
 
123
    ;;
 
124
 
 
125
    abort-upgrade|abort-remove|abort-deconfigure)
 
126
    ;;
 
127
 
 
128
    *)
 
129
        echo "postinst called with unknown argument \`$1'" >&2
 
130
        exit 1
 
131
    ;;
 
132
esac
 
133
 
 
134
rm -f $TUNCONF $TMPCONF $TUNFILE
 
135
 
 
136
# dh_installdeb will replace this with shell code automatically
 
137
# generated by other debhelper scripts.
120
138
 
121
139
#DEBHELPER#
122
140
 
 
141
exit 0