Fix "uses non-essential tools in the config script" (Closes: #561324)
[aiccu.git] / debian / aiccu.config
blob800be430ac9838ac21c80380ccea084d8f844e6d
1 #!/bin/bash
3 set -ex
5 CONFIGFILE=/etc/aiccu.conf
6 DIG=/usr/bin/dig
7 HOST=/usr/bin/host
9 BROKERS_LIST=/usr/share/aiccu/conf-templates/brokers.list
11 TMPCONF=$(tempfile -p aiccu -s conf)
12 TMPFILE=$(tempfile -p aiccu -s temp)
13 BROKERS=$(tempfile -p aiccu -s brokers)
15 trap 'rm -f $TMPCONF $TMPFILE $BROKERS' TERM INT EXIT QUIT
17 # Make sure that files we create are not readable by anyone but us (root)
18 umask 077
20 # Source debconf library.
21 . /usr/share/debconf/confmodule
23 if [ -e $CONFIGFILE ]; then
24 USERNAME=$(grep ^username $CONFIGFILE | awk '{print $2}')
25 PASSWORD=$(grep ^password $CONFIGFILE | awk '{print $2}')
26 PROTO=$(grep ^protocol $CONFIGFILE | awk '{print $2}')
27 SERVER=$(grep ^server $CONFIGFILE | awk '{print $2}')
28 TUNNEL=$(grep ^tunnel_id $CONFIGFILE | awk '{print $2}')
30 if [ "$USERNAME" != "" ]; then
31 db_set aiccu/username "$USERNAME"
34 if [ "$PASSWORD" != "" ]; then
35 db_set aiccu/password "$PASSWORD"
38 if [ "$PROTO" != "" -a "$SERVER" != "" ]; then
39 db_set aiccu/brokername "$PROTO://$SERVER"
42 if [ "$TUNNEL" != "" ]; then
43 db_set aiccu/tunnelname "$TUNNEL"
47 STATE=1
48 if [ "$DEBCONF_RECONFIGURE" = "1" -o "$1" = "reconfigure" ]; then
49 STATE=1
50 elif [ "$TUNNEL" != "" -a "$PROTO" != "" -a "$SERVER" != "" ]; then
51 # Assume that we do not need further configuration.
52 STATE=4
55 # Fetch the list of tunnel brokers
56 if [ -x $DIG ]; then
57 $DIG _aiccu.sixxs.net TXT +short +time=5 +tries=2 |
58 sed -e "s/\"$/|/" -e "s/\" \"/|/g" -e "s/\"//" -e "/^[#;]/d" | sort > $BROKERS
59 else
60 if [ -x $HOST ]; then
61 $HOST -t TXT -W 5 _aiccu.sixxs.net |
62 sed -e "s/^_.*text //" -e "s/\"$/|/" -e "s/\" \"/|/g" -e "s/\"//" -e "/^[#;]/d" |
63 sort > $BROKERS
64 else
65 # Copy default
66 sed -e "/^#/d" $BROKERS_LIST > $BROKERS
70 # Copy default if dig/host gave error
71 if [ ${PIPESTATUS[0]} -ne 0 ]; then
72 sed -e "/^#/d" $BROKERS_LIST > $BROKERS
75 # State What
76 # 1 Get Tunnel Brokername
77 # 2 Get User/pass
78 # 3 Exit
80 while [ $STATE -ge 1 -a $STATE -le 2 ]; do
81 case "$STATE" in
83 # Request broker
84 BROKERS_=$(cat $BROKERS | cut -f1 -d'|' | awk '{print $0","}')
85 BROKERS_=$(echo -n $BROKERS_ | sed 'N;s/\n//g' | sed 's/,$//g')
86 db_get aiccu/brokername
87 if [ "$RET" != "" ]; then
88 SELECTED=$(grep "$RET" $BROKERS | cut -f1 -d'|')
89 db_set aiccu/brokername "$SELECTED"
91 db_subst aiccu/brokername brokers "$BROKERS_"
92 db_input high aiccu/brokername || true
93 db_go || true
95 # Convert brokername to URL of broker
96 db_get aiccu/brokername || true
97 URL=$(grep $RET $BROKERS | cut -f2 -d'|')
98 db_set aiccu/brokername "$URL"
102 # Request User / Pass
103 db_input high aiccu/username || true
104 db_input high aiccu/password || true
105 db_go || true
107 esac
109 db_go
110 STATE=$(($STATE + 1))
112 done
114 rm -f $TMPCONF $TMPFILE $BROKERS