2
# $Id: update-inetd.sh,v 1.5 2007-05-03 08:55:24 robert Exp $
2
# vim:ts=4:sts=4:fdm=marker:cms=\ #\ %s
3
# $Id: update-inetd.sh 286 2009-03-01 11:20:28Z robert $
4
5
# rlinetd's version of update-inetd.
5
# Robert Luberda <robert@debian.org>, Aug 2001
6
# Robert Luberda <robert@debian.org>, 2001, 2009
10
11
PATH=/usr/sbin:$PATH
12
version='$Revision: 1.5 $'
14
g_version='$Revision: 286 $'
15
g_rlinconfdir="/etc/rlinetd.d"
16
g_ucfdir="/var/lib/rlinetd/ucf"
23
# error - prints error message and exits the program # {{{
27
echo "update-inetd: $msg" >&2
28
debug "Program arguments: --$g_mode \"$line\""
32
# debug - prints debug info # {{{
35
[ $g_debug -eq 1 ] || return 0
40
# ucf_ack - asks user a question using ucf # {{{
46
if [ ! -e "$conffile" ] || ! cmp -s "$cachedfile" "$conffile"; then
47
debug "Running ucf on $cachedfile and $conffile"
48
# note: --debconf-ok would causes ucf to hang if db_stop has been called
49
# (e.g. samba's postinst does this)
50
ucf --three-way "$cachedfile" "$conffile"
51
ucfr "rlinetd" "$conffile"
54
debug "$cachedfile and $conffile identical, skipping ucf"
59
# ucf_purge - purges ucf configuration # {{{
64
debug "Removing $conffile from ucf"
65
ucf --purge "$conffile"
66
ucfr --purge "rlinetd" "$conffile" || true
70
# enable_disable_util - enables or disables an entry # {{{
77
debug "Setting enable to $3 in $cachedfile"
79
sed -e "s/^\([ \t]*enabled[ \t][ \t]*\).*$/\1$enable;/" < "$cachedfile" > "$cachedfile.tmp"
80
mv "$cachedfile.tmp" "$cachedfile"
83
ucf_ask "$cachedfile" "$conffile"
87
# enable - calls enable_disable_util to enable an entry # {{{
90
enable_disable_util "$1" "$2" "yes"
93
# disable - calls enable_disable_util to disable an entry # {{{
96
enable_disable_util "$1" "$2" "no"
99
# remove - removes an entry # {{{
105
debug "Removing $cachedfile, $conffile"
107
rm -f "$cachedfile" "$conffile"
108
ucf_purge "$conffile"
112
# add - adds a new entry # {{{
116
files=`inetd2rlinetd --force-overwrite --print-file-names -l "$line" "$g_ucfdir"`
117
debug "Converted $line saved in $files"
118
[ -z "$file" ] || return 0
120
for file in $files; do
124
basename="${file%_*}"
125
if [ ! -e "$g_rlinconfdir/$file" ] &&
126
[ ! -e "$g_ucfdir/$basename" ] &&
127
[ -f "$g_rlinconfdir/$basename" ]; then
128
# rename previous versions of file
129
debug "Renaming $g_rlinconfdir/$basename to $g_rlinconfdir/$file"
130
mv -f "$g_rlinconfdir/$basename" "$g_rlinconfdir/$file"
135
ucf_ask "$g_ucfdir/$file" "$g_rlinconfdir/$file"
139
# operation - calls add, remove, enable or disable # {{{
145
[ -n "$line" ] || error "--$operation requires argument"
147
debug "Running $operation for $line"
150
if [ "$operation" = "add" ]; then
155
# disable, enable, remove; line can be comma separated list of values
157
while [ "$line" != "$service" ] ; do
161
for proto in "" _udp; do
162
basefile="${service}${proto}"
163
file="$g_ucfdir/$basefile"
164
debug "Checking for file $file"
165
if [ -e "$file" ]; then
167
"$operation" "$file" "$g_rlinconfdir/$basefile"
171
if [ $found -eq 0 ]; then
172
echo "Cannot find cached rlinetd's config files for service $service, ignoring $operation request" >&2;
177
# reload_rlinetd - reloads rlinetd daemon # {{{
180
if [ "$g_need_reload" -eq 0 ]; then
181
debug "Configuration not changed, not reloading rlinetd"
185
debug "Reloading rlinetd config files"
187
killall -HUP rlinetd || true
191
# MAIN FUNCTION # {{{
193
# parse arguments # {{{
16
195
for i in "$@" ; do
196
# note: the original update-inetd allows things like "--add --comment-chars XX LINE_TO_ADD"
197
if [ "$ignore_next" -eq 1 ] ; then
18
"--remove"|"--disable"|"--enable")
19
echo "Warning: Operation $i is not supported by rlinetd's version of update-inetd" 1>&2
203
"--add"|"--remove"|"--disable"|"--enable")
204
[ -z "$mode" ] || error "$i conflicts with --$mode"
206
g_mode="${g_mode#--}"
22
212
echo "rlinetd's version of update-inetd"
23
echo "version: $version"
213
echo "version: $g_version"
26
*) if [ "x$last" = "x--add" ] ; then
216
"--multi"|"--verbose")
219
"--file"|"--group"|"--comment-chars")
223
echo "Unknown option \`$i\' passed to $0, ignoring" >&2;
225
*) if [ -n "$g_mode" ] ; then
226
[ -z "$g_line" ] || error "--$g_mode requires only one argument"
36
if [ "x$last" = "x--add" ] ;then
37
echo "Option --add requires an argument" 1>&2
42
if [ "x$line" != "x" ] ; then
43
inetd2rlinetd -l "$line" /etc/rlinetd.d
45
# reload configuration
46
killall -HUP rlinetd || true
49
if [ -f /etc/inetd.conf ] ; then
50
real_upd=`dpkg-divert --truename /usr/sbin/update-inetd`
51
[ -x "$real_upd" ] && "$real_upd" "$@" || true
234
[ -z "$g_mode" ] || operation "$g_mode" "$g_line"
236
# reload configuration
239
# execute real update-inetd
240
real_upd=`dpkg-divert --truename /usr/sbin/update-inetd`
241
[ -x "$real_upd" ] && exec "$real_upd" "$@"