1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
NETSTAT=/bin/netstat
SERVICES=/etc/services
CONFFILE=/etc/thttpd/thttpd.conf
DEFPORT=80
. /usr/share/debconf/confmodule
#set -e
resolve_port_problem ()
{
OK=0
db_text high thttpd/port_prob_dsc || true
db_go
#
# Loop until a valid port is selected.
#
while [ $OK = 0 ]; do
db_input high thttpd/port_prob || true
db_go
db_get thttpd/port_prob
if [ "$RET" = "Do nothing" ]; then
OK=1
elif [ "$RET" = "Specify an alternative port" ]; then
db_input critical thttpd/select_port || true
db_go
db_get thttpd/select_port
PORT=$RET
check_port && OK=1
fi
if [ $OK = 0 ]; then
db_text high thttpd/input_prob_dsc || true
db_fset thttpd/port_prob seen false
db_fset thttpd/select_port seen false
db_go
fi
done
}
select_port () {
OK=0
db_text high thttpd/port_no_prob_dsc || true
db_go
#
# Loop until a valid port is selected.
#
while [ $OK = 0 ]; do
db_input high thttpd/port_prob || true
db_go
db_get thttpd/port_prob
if [ "$RET" = "Do nothing" ]; then
OK=1
elif [ "$RET" = "Specify an alternative port" ]; then
db_input high thttpd/select_port || true
db_go
db_get thttpd/select_port
PORT=$RET
check_port && OK=1
fi
if [ $OK = 0 ]; then
db_text high thttpd/input_prob_dsc || true
db_fset thttpd/port_prob seen false
db_fset thttpd/select_port seen false
db_go
fi
done
}
port_to_name () {
RESULT=`grep -w $PORT_TMP $SERVICES | grep tcp | awk '{print $1}'`
if [ -n "$RESULT" ]; then
PORT_TMP=$RESULT
fi
}
# Determine if thttpd is set to something other then port 80
get_setting () {
db_get thttpd/select_port
PORT=$RET
if [ -z $PORT ]; then
PORT=$DEFPORT
fi
}
# Determine whether the specified port is bound.
check_port () {
OUTPUT=`$NETSTAT -plunt | awk '{print $4}' | grep -w $PORT `
if [ "$OUTPUT" ]; then
PORT_OUT=1
return 1
else
PORT_OUT=0
return 0
fi
}
INSTALL_STAT=`dpkg -s thttpd | grep Status | awk '{print $4}'`
test -f $CONFFILE && PORT_CONF=`grep "port=80" $CONFFILE`
if [ "$INSTALL_STAT" = "installed" ]; then
if [ -x /etc/init.d/thttpd ]; then
/etc/init.d/thttpd stop 1>&2> /dev/null || true
fi
fi
# do we want to chroot
db_input medium thttpd/chroot || true
db_go
if [ "$INSTALL_STAT" = "installed" ]; then
# Ok, we're not installed, so someone called re-configure
# So, if we're not using port 80, ask the question
PORT=$DEFPORT
check_port
get_setting
if [ "$PORT" != "$DEFPORT" ]; then
if [ "$PORT_OUT" = "1" ]; then
resolve_port_problem
else
select_port
fi
fi
else
# We're installing, see if 80 is in use.
PORT=$DEFPORT
check_port
if [ "$PORT_OUT" = "1" ]; then
resolve_port_problem
PROBLEM=1
fi
fi
|