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 [ -f "$DEFAULT" ] && inetd_compat="`grep '^XINETD_OPTS.*=.*\-inetd_compat' "$DEFAULT"`" || true
43 CONFTMP=`mktemp $CONF.tmp.XXXXXX`
45 if [ -f "$INETDCONF" ] && [ -n "$inetd_compat" ]; then
47 # Convert inetd.conf to temporary xinetd.conf file using xconv.pl tool
48 /usr/sbin/xconv.pl < $INETDCONF > $CONFTMP
51 # Parse /etc/xinetd.conf file and convert services' configuration to
52 # separated configurations in /etc/xinetd.d/ directory
54 services_list="`cat $CONF $CONFTMP | grep "^service " | uniq | sed 's/service //g'`" || true
56 if [ -n "$services_list" ]; then
57 for service in $services_list; do
59 if [ -f "/etc/xinetd.d/$service" ]; then
60 cp_check_and_backup "/etc/xinetd.d/$service"
62 if ! egrep -q "^# .* update by CARNet package" "/etc/xinetd.d/$service"; then
63 rm -f /etc/xinetd.d/$service
67 touch /etc/xinetd.d/$service || true
68 # cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" | cp-update "$PKG" "/etc/xinetd.d/$service"
69 cat "$CONF" "$CONFTMP" | sed -n "/^service $service/,/^}/p" >> "/etc/xinetd.d/$service"
75 cp_echo "CN: All services were converted from $CONF file to separated configuration"
76 cp_echo "CN: files located in /etc/xinetd.d/ directory."
78 if [ -n "$inetd_compat" ]; then
79 cp_echo "CN: Since -inetd_compat option was active, all services in $INETDCONF"
80 cp_echo "CN: file were also moved to /etc/xinetd.d/ directory."
87 # Remove services from /etc/xinetd.conf file
89 cp_check_and_sed "^service " \
91 "$CONF" && need_restart=1 || true
93 # Check if there is no defaults block in /etc/xinetd.conf
95 if ! egrep -q '^defaults' "$CONF"; then
97 echo -e "defaults\n{\n\n}" | cp-update "$PKG" "$CONF"
98 cp_echo "CN: Added defaults block to $CONF"
103 # Check if /etc/xinetd.d/ directory is included or not
105 if ! egrep -q '^includedir /etc/xinetd.d' "$CONF"; then
107 echo "includedir /etc/xinetd.d" | cp-update "$PKG" "$CONF"
108 cp_echo "CN: Added \"includedir /etc/xinetd.d\" line to $CONF"
113 # Remove -inetd_compat option from /etc/default/xinetd
115 if [ -f "$DEFAULT" ]; then
117 # File exists, remove -inetd_compat option
118 cp_check_and_sed "^XINETD_OPTS.*\-inetd_compat" \
119 "s/\-inetd_compat//g" \
120 "$DEFAULT" && need_restart=1 || true
122 # Just in case there is no active XINETD_OPTS line
123 if ! egrep -q '^XINETD_OPTS' "$DEFAULT"; then
125 echo 'XINETD_OPTS="-stayalive"' | cp-update "$PKG" "$DEFAULT"
126 cp_echo "CN: Added -stayalive option to $DEFAULT."
131 # File wasn't there at all?
133 echo 'XINETD_OPTS="-stayalive"' | cp-update "$PKG" "$DEFAULT"
134 cp_echo "CN: Created $DEFAULT file with -stayalive option."
139 # Restart xinetd if needed
141 if [ $need_restart -eq 1 ]; then
144 pgrep -u root -f /usr/sbin/xinetd > /dev/null || do=start
147 if [ -n "$do" ]; then
150 if [ -x "/etc/init.d/xinetd" ]; then
151 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
152 invoke-rc.d xinetd "$do" || exit $?
154 /etc/init.d/xinetd "$do" || exit $?