#!/bin/sh # # Usage: modinetd [-n] [package] usage() { echo "Usage: $(basename $0) [options] [package]" echo "options:" echo " -h | --help - print this help" echo " -n | --nosave - do not modsave flash" exit $1 } inetd_conf_line() { line="$inetdcfg_port\t$inetdcfg_sock\t$inetdcfg_proto\t$inetdcfg_flags\t$inetdcfg_user\t$inetdcfg_exe\t$inetdcfg_arg0 $inetdcfg_args" if [ "escape" = "$1" ]; then line=$(echo -n "$line" | sed -e "s@/@\\\\/@g") fi echo -en "$line" } update_inetd() { if [ -e "/etc/init.d/rc.$1" ]; then echo -n "Updating inetd config for $1: " icnf="/var/tmp/flash/inetd.conf" . /etc/default.$1/$1.inetd if ! grep "#:$1:" $icnf > /dev/null; then echo >> $icnf echo "#:$1: $inetdcfg_desc" >> $icnf echo "$(inetd_conf_line)" >> $icnf fi if [ "inetd" == $(/etc/init.d/rc.$1 status) ]; then sed -i -e "/#:$1:.*/{N};s/\(#:$1:[^\n]*\)\n\(##\)\?\(.*\)/\1\n$(inetd_conf_line "escape")/g" $icnf echo "active." else sed -i -e "/#:$1:.*/{N};s/\(#:$1:[^\n]*\)\n\([^#].*\)/\1\n##$(inetd_conf_line "escape")/g" $icnf echo "inactive." fi else error "package $1 has no rc script" exit 1 fi } error() { echo "$0: $*" 1>&2 } save="true" TEMP=$(getopt -o hn --long help,nosave -n "$(basename $0)" -- "$@") [ $? == 0 ] || usage 1 eval set -- "$TEMP" while true ; do case "$1" in -h|--help) usage 0; shift ;; -n|--nosave) save="false"; shift ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac done if [ "" == "$1" ]; then for package in $(ls /etc/default.*/*.inetd | sed -e "s@/etc/default[.]\(.*\)/.*[.]inetd@\1@"); do update_inetd $package done else while [ "" != "$1" ]; do if [ -e "/etc/default.$1/$1.inetd" ]; then update_inetd $1 else error "package $1 has no default inetd file" fi shift done fi /etc/init.d/rc.inetd reload if [ "true" == "$save" ]; then /usr/bin/modsave flash fi exit 0