2
# postinst script for aiccu
4
# Abort if any command returns an error value
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
9
. /usr/share/debconf/confmodule
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
29
if [ "$USERNAME" = "" ]; then
30
# Not configured yet, thus skip
34
# Defaults when nothing gets chosen
35
# This might happen because of broken DNS
36
if [ "$PROTO" = "" ]; then
40
if [ "$SERVER" = "" ]; then
41
SERVER="tic.sixxs.net"
44
# Make sure that files we create are not readable by anyone but us (root)
47
# Check if the /etc/aiccu.conf is actually the example
48
if [ diff -q $EXAMPLE $CONFIGFILE 2>/dev/null >/dev/null ]; then
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
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
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
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
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
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.