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
15 BACKUPDIR=/var/backups/xinetd-cn
23 # Cleanup all temp files.
28 if [ -n "$temp_files" ]; then
29 for item in $temp_files; do
30 if [ -e "$item" ]; then
38 # Set trap for deleting all temp files.
42 # First, we do backup (inetd, xinetd)
44 if cp_backup_conffile -r -d $BACKUPDIR -p $INETDCONF; then
45 cp_echo "CN: Old $INETDCONF saved as $BACKUPDIR/`basename $INETDCONF`.bak."
47 if cp_backup_conffile -r -d $BACKUPDIR -p $CONF; then
48 cp_echo "CN: Old $CONF saved as $BACKUPDIR/`basename $CONF`.bak."
51 CONFTMP=`mktemp $CONF.tmp.XXXXXX`
54 if [ -f "$INETDCONF" ]; then
56 # Convert inetd.conf to temporary xinetd.conf file using xconv.pl tool
57 /usr/sbin/xconv.pl < $INETDCONF > $CONFTMP
60 # Parse /etc/xinetd.conf file and convert services' configuration to
61 # separated configurations in /etc/xinetd.d/ directory
63 conffile_list="$CONFTMP"
64 if [ -f "$CONF" ]; then
65 if egrep -q "^service[[:space:]]+" "$CONF"; then
66 conffile_list="$CONF $conffile_list"
70 services_list="`cat $conffile_list | egrep "^service[[:space:]]+" | sed -r 's/service[[:space:]]+//g' | uniq`" || true
72 if [ -n "$services_list" ]; then
74 for service in $services_list; do
76 if [ -f "/etc/xinetd.d/$service" ]; then
78 if cp_backup_conffile -r -d $BACKUPDIR -p /etc/xinetd.d/$service; then
79 cp_echo "CN: Old /etc/xinetd.d/$service saved as $BACKUPDIR/`basename /etc/xinetd.d/$service`.bak."
82 rm -f /etc/xinetd.d/$service
85 touch /etc/xinetd.d/$service || true
86 # cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" | cp-update "$PKG" "/etc/xinetd.d/$service"
87 cat $conffile_list | sed -rn "/^service[[:space:]]+$service/,/^}/p" >> "/etc/xinetd.d/$service"
92 if egrep -q "^service[[:space:]]+" "$CONFTMP"; then
93 cp_echo "CN: All services were converted from $INETDCONF file to separated"
94 cp_echo "CN: configuration files located in /etc/xinetd.d/ directory."
97 if [ $xinetd_conf_did -eq 1 ]; then
98 cp_echo "CN: All services were converted from $CONF file to separated"
99 cp_echo "CN: configuration files located in /etc/xinetd.d/ directory."
105 # Configuration file /etc/xinetd.conf does not exist?
107 if [ ! -f "$CONF" ]; then
111 # Remove services from /etc/xinetd.conf file
113 cp_check_and_sed "^service[[:space:]]+" \
114 "/^service[[:space:]]/,/^}/d" \
115 "$CONF" && need_restart=1 || true
117 # Check if there is no defaults block in /etc/xinetd.conf
119 if ! egrep -q '^defaults' "$CONF"; then
121 echo -e "defaults\n{\n\n}" | cp-update -m "$PKG" "$CONF"
122 cp_echo "CN: Added defaults block to $CONF"
127 # Check if /etc/xinetd.d/ directory is included or not
129 if ! egrep -q '^includedir /etc/xinetd.d' "$CONF"; then
131 echo "includedir /etc/xinetd.d" | cp-update -m "$PKG" "$CONF"
132 cp_echo "CN: Added \"includedir /etc/xinetd.d\" line to $CONF"
137 # Remove -inetd_compat option and set INETD_COMPAT to 'No' in /etc/default/xinetd
139 if [ -f "$DEFAULT" ]; then
141 # File exists, set INETD_COMPAT to 'No'
142 cp_check_and_sed "^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]" \
143 "s/^[[:space:]]*INETD_COMPAT.*[Yy][Ee][Ss]/INETD_COMPAT=No/g" \
144 "$DEFAULT" && need_restart=1 || true
146 # File exists, remove -inetd_compat option
147 cp_check_and_sed "^[[:space:]]*XINETD_OPTS.*\-inetd_compat" \
148 "s/\-inetd_compat//g" \
149 "$DEFAULT" && need_restart=1 || true
151 # No INETD_COMPAT line?
152 if ! egrep -q '^[[:space:]]*INETD_COMPAT' "$DEFAULT"; then
153 echo 'INETD_COMPAT=No' | cp-update -m "$PKG" "$DEFAULT"
154 cp_echo "CN: Added 'INETD_COMPAT=No' to $DEFAULT."
158 # Just in case there is no active XINETD_OPTS line
159 if ! egrep -q '^[[:space:]]*XINETD_OPTS' "$DEFAULT"; then
160 echo 'XINETD_OPTS="-stayalive"' | cp-update -m "$PKG" "$DEFAULT"
161 cp_echo "CN: Added -stayalive option to $DEFAULT."
165 # File wasn't there at all?
167 echo -e 'INETD_COMPAT=No\nXINETD_OPTS="-stayalive"' | cp-update "$PKG" "$DEFAULT"
168 cp_echo "CN: Created $DEFAULT file with -stayalive enabled and -inetd_compat disabled."
173 # Restart xinetd if needed
175 if [ $need_restart -eq 1 ]; then
178 pgrep -u root -f /usr/sbin/xinetd > /dev/null || do=start
180 if [ -n "$do" ]; then
183 if [ -x "/etc/init.d/xinetd" ]; then
184 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
185 invoke-rc.d xinetd "$do" || exit $?
187 /etc/init.d/xinetd "$do" || exit $?