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
21 # Cleanup all temp files.
26 if [ -n "$temp_files" ]; then
27 for item in $temp_files; do
28 if [ -e "$item" ]; then
36 # Set trap for deleting all temp files.
40 # First, we do backup (inetd, xinetd)
42 if cp_check_and_backup "$INETDCONF"; then
43 cp_echo "CN: Old $INETDCONF saved as /var/backups/`basename $INETDCONF`.bak."
45 if cp_check_and_backup "$CONF"; then
46 cp_echo "CN: Old $CONF saved as /var/backups/`basename $CONF`.bak."
49 CONFTMP=`mktemp $CONF.tmp.XXXXXX`
52 if [ -f "$INETDCONF" ]; then
54 # Convert inetd.conf to temporary xinetd.conf file using xconv.pl tool
55 /usr/sbin/xconv.pl < $INETDCONF > $CONFTMP
58 # Parse /etc/xinetd.conf file and convert services' configuration to
59 # separated configurations in /etc/xinetd.d/ directory
61 conffile_list="$CONFTMP"
62 if [ -f "$CONF" ]; then
63 conffile_list="$CONF $conffile_list"
65 services_list="`cat $conffile_list | grep "^service " | uniq | sed 's/service //g'`" || true
67 if [ -n "$services_list" ]; then
69 for service in $services_list; do
71 if [ -f "/etc/xinetd.d/$service" ]; then
73 if cp_check_and_backup "/etc/xinetd.d/$service"; then
74 cp_echo "CN: Old /etc/xinetd.d/$service saved as /var/backups/`basename /etc/xinetd.d/$service`.bak."
77 rm -f /etc/xinetd.d/$service
80 touch /etc/xinetd.d/$service || true
81 # cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" | cp-update "$PKG" "/etc/xinetd.d/$service"
82 cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" >> "/etc/xinetd.d/$service"
87 if egrep -q "service " "$CONFTMP"; then
88 cp_echo "CN: All services were converted from $INETDCONF file to separated"
89 cp_echo "CN: configuration files located in /etc/xinetd.d/ directory."
92 if [ -f "$CONF" ]; then
93 cp_echo "CN: All services were converted from $CONF file to separated"
94 cp_echo "CN: configuration files located in /etc/xinetd.d/ directory."
100 # Configuration file /etc/xinetd.conf does not exist?
102 if [ ! -f "$CONF" ]; then
106 # Remove services from /etc/xinetd.conf file
108 cp_check_and_sed "^service " \
110 "$CONF" && need_restart=1 || true
112 # Check if there is no defaults block in /etc/xinetd.conf
114 if ! egrep -q '^defaults' "$CONF"; then
116 echo -e "defaults\n{\n\n}" | cp-update -m "$PKG" "$CONF"
117 cp_echo "CN: Added defaults block to $CONF"
122 # Check if /etc/xinetd.d/ directory is included or not
124 if ! egrep -q '^includedir /etc/xinetd.d' "$CONF"; then
126 echo "includedir /etc/xinetd.d" | cp-update -m "$PKG" "$CONF"
127 cp_echo "CN: Added \"includedir /etc/xinetd.d\" line to $CONF"
132 # Remove -inetd_compat option and set INETD_COMPAT to 'No' in /etc/default/xinetd
134 if [ -f "$DEFAULT" ]; then
136 # File exists, set INETD_COMPAT to 'No'
137 cp_check_and_sed "^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]" \
138 "s/^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]/INETD_COMPAT=No/g" \
139 "$DEFAULT" && need_restart=1 || true
141 # File exists, remove -inetd_compat option
142 cp_check_and_sed "^[[:space:]]*XINETD_OPTS.*\-inetd_compat" \
143 "s/\-inetd_compat//g" \
144 "$DEFAULT" && need_restart=1 || true
146 # No INETD_COMPAT line?
147 if ! egrep -q '^[[:space:]]*INETD_COMPAT' "$DEFAULT"; then
148 echo 'INETD_COMPAT=No' | cp-update -m "$PKG" "$DEFAULT"
149 cp_echo "CN: Added 'INETD_COMPAT=No' to $DEFAULT."
153 # Just in case there is no active XINETD_OPTS line
154 if ! egrep -q '^[[:space:]]*XINETD_OPTS' "$DEFAULT"; then
155 echo 'XINETD_OPTS="-stayalive"' | cp-update -m "$PKG" "$DEFAULT"
156 cp_echo "CN: Added -stayalive option to $DEFAULT."
160 # File wasn't there at all?
162 echo -e 'INETD_COMPAT=No\nXINETD_OPTS="-stayalive"' | cp-update "$PKG" "$DEFAULT"
163 cp_echo "CN: Created $DEFAULT file with -stayalive enabled and -inetd_compat disabled."
168 # Restart xinetd if needed
170 if [ $need_restart -eq 1 ]; then
173 pgrep -u root -f /usr/sbin/xinetd > /dev/null || do=start
175 if [ -n "$do" ]; then
178 if [ -x "/etc/init.d/xinetd" ]; then
179 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
180 invoke-rc.d xinetd "$do" || exit $?
182 /etc/init.d/xinetd "$do" || exit $?