5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
9 . /usr/share/carnet-tools/functions.sh
13 INETDCONF=/etc/inetd.conf
14 DEFAULT=/etc/default/xinetd
20 # First, we do backup (inetd, xinetd)
22 if cp_check_and_backup "$INETDCONF"; then
25 if cp_check_and_backup "$CONF"; then
29 # Print backup information
32 if [ $did_inetd_backup -eq 1 ]; then
33 cp_echo "CN: Old $INETDCONF saved as /var/backups/`basename $INETDCONF`.bak."
35 if [ $did_backup -eq 1 ]; then
36 cp_echo "CN: Old $CONF saved as /var/backups/`basename $CONF`.bak."
39 # If there are some services enabled in /etc/inetd.conf, convert them to
40 # temporary xinetd configuration file.
42 if [ -f "$DEFAULT" ]; then
43 inetd_compat="`egrep '^[[:space:]]*XINETD_OPTS[[:space:]]*=.*\-inetd_compat' "$DEFAULT"`" || true
44 if [ -z "$inetd_compat" ]; then
45 inetd_compat="`egrep '^[[:space:]]*INETD_COMPAT[[:space:]]*=[[:space:]]*[Yy][Ee][Ss]' "$DEFAULT"`" || true
48 CONFTMP=`mktemp $CONF.tmp.XXXXXX`
50 if [ -f "$INETDCONF" ] && [ -n "$inetd_compat" ]; then
52 # Convert inetd.conf to temporary xinetd.conf file using xconv.pl tool
53 /usr/sbin/xconv.pl < $INETDCONF > $CONFTMP
56 # Parse /etc/xinetd.conf file and convert services' configuration to
57 # separated configurations in /etc/xinetd.d/ directory
59 services_list="`cat $CONF $CONFTMP | grep "^service " | uniq | sed 's/service //g'`" || true
61 if [ -n "$services_list" ]; then
62 for service in $services_list; do
64 if [ -f "/etc/xinetd.d/$service" ]; then
65 cp_check_and_backup "/etc/xinetd.d/$service"
67 if ! egrep -q "^# .* update by CARNet package" "/etc/xinetd.d/$service"; then
68 rm -f /etc/xinetd.d/$service
72 touch /etc/xinetd.d/$service || true
73 # cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" | cp-update "$PKG" "/etc/xinetd.d/$service"
74 cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" >> "/etc/xinetd.d/$service"
80 cp_echo "CN: All services were converted from $CONF file to separated configuration"
81 cp_echo "CN: files located in /etc/xinetd.d/ directory."
83 if [ -n "$inetd_compat" ]; then
84 cp_echo "CN: Since -inetd_compat option was active, all services in $INETDCONF"
85 cp_echo "CN: file were also moved to /etc/xinetd.d/ directory."
92 # Remove services from /etc/xinetd.conf file
94 cp_check_and_sed "^service " \
96 "$CONF" && need_restart=1 || true
98 # Check if there is no defaults block in /etc/xinetd.conf
100 if ! egrep -q '^defaults' "$CONF"; then
102 echo -e "defaults\n{\n\n}" | cp-update -m "$PKG" "$CONF"
103 cp_echo "CN: Added defaults block to $CONF"
108 # Check if /etc/xinetd.d/ directory is included or not
110 if ! egrep -q '^includedir /etc/xinetd.d' "$CONF"; then
112 echo "includedir /etc/xinetd.d" | cp-update -m "$PKG" "$CONF"
113 cp_echo "CN: Added \"includedir /etc/xinetd.d\" line to $CONF"
118 # Remove -inetd_compat option and set INETD_COMPAT to 'No' in /etc/default/xinetd
120 if [ -f "$DEFAULT" ]; then
122 # File exists, set INETD_COMPAT to 'No'
123 cp_check_and_sed "^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]" \
124 "s/^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]/INETD_COMPAT=No/g" \
125 "$DEFAULT" && need_restart=1 || true
127 # File exists, remove -inetd_compat option
128 cp_check_and_sed "^[[:space:]]*XINETD_OPTS.*\-inetd_compat" \
129 "s/\-inetd_compat//g" \
130 "$DEFAULT" && need_restart=1 || true
132 # No INETD_COMPAT line?
133 if ! egrep -q '^[[:space:]]*INETD_COMPAT' "$DEFAULT"; then
134 echo 'INETD_COMPAT=No' | cp-update -m "$PKG" "$DEFAULT"
135 cp_echo "CN: Added 'INETD_COMPAT=No' to $DEFAULT."
139 # Just in case there is no active XINETD_OPTS line
140 if ! egrep -q '^[[:space:]]*XINETD_OPTS' "$DEFAULT"; then
141 echo 'XINETD_OPTS="-stayalive"' | cp-update -m "$PKG" "$DEFAULT"
142 cp_echo "CN: Added -stayalive option to $DEFAULT."
146 # File wasn't there at all?
148 echo -e 'INETD_COMPAT=No\nXINETD_OPTS="-stayalive"' | cp-update "$PKG" "$DEFAULT"
149 cp_echo "CN: Created $DEFAULT file with -stayalive enabled and -inetd_compat disabled."
154 # Restart xinetd if needed
156 if [ $need_restart -eq 1 ]; then
159 pgrep -u root -f /usr/sbin/xinetd > /dev/null || do=start
162 if [ -n "$do" ]; then
165 if [ -x "/etc/init.d/xinetd" ]; then
166 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
167 invoke-rc.d xinetd "$do" || exit $?
169 /etc/init.d/xinetd "$do" || exit $?