~ubuntu-branches/debian/sid/rlinetd/sid

« back to all changes in this revision

Viewing changes to debian/update-inetd.sh

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2010-03-20 18:03:45 UTC
  • mfrom: (2.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320180345-x1srfbe2tg00ezsf
Tags: 0.7-1
* New upstream version.
* Recommend rsyslog instead of sysklogd (closes: #526922).
* update-inetd:
  + add support for enabling, disabling and removing entries;
  + use ucf for managing generated files;
  + ignore ucf files in rlinetd.conf;
  + make appropriate changes in  postinst and postrm scripts.
* Set debhelper compat level to 7
* Standards-Version: 3.8.4 (no changes). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
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 $
3
4
#
4
5
# rlinetd's version of update-inetd.
5
 
# Robert Luberda <robert@debian.org>, Aug 2001
 
6
# Robert Luberda <robert@debian.org>, 2001, 2009
6
7
#
7
8
 
8
9
set -e
9
10
 
10
11
PATH=/usr/sbin:$PATH
11
12
 
12
 
version='$Revision: 1.5 $'
13
 
line=""
14
 
last=""
15
 
 
 
13
# global variables
 
14
g_version='$Revision: 286 $'
 
15
g_rlinconfdir="/etc/rlinetd.d"
 
16
g_ucfdir="/var/lib/rlinetd/ucf"
 
17
 
 
18
g_debug=0
 
19
g_need_reload=0
 
20
g_line=""
 
21
g_mode=""
 
22
 
 
23
# error - prints error message and exits the program  # {{{
 
24
error() 
 
25
{
 
26
        msg="$1"
 
27
        echo "update-inetd: $msg" >&2
 
28
        debug "Program arguments: --$g_mode \"$line\""
 
29
        exit 1
 
30
} # }}}
 
31
 
 
32
# debug - prints debug info # {{{
 
33
debug()
 
34
{
 
35
        [ $g_debug -eq 1 ] || return 0
 
36
        msg="$1"
 
37
        echo "$msg"
 
38
} # }}}
 
39
 
 
40
# ucf_ack - asks user a question using ucf # {{{
 
41
ucf_ask() 
 
42
{
 
43
        cachedfile="$1"
 
44
        conffile="$2"
 
45
 
 
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"
 
52
                g_need_reload=1
 
53
        else
 
54
                debug "$cachedfile and $conffile identical, skipping ucf"
 
55
        fi
 
56
 
 
57
} # }}}
 
58
 
 
59
# ucf_purge - purges ucf configuration # {{{
 
60
ucf_purge()
 
61
{
 
62
        conffile="$1"
 
63
 
 
64
        debug "Removing $conffile from ucf"
 
65
        ucf --purge "$conffile"
 
66
    ucfr --purge "rlinetd" "$conffile" || true
 
67
        g_need_reload=1
 
68
} # }}}
 
69
 
 
70
# enable_disable_util - enables or disables an entry # {{{
 
71
enable_disable_util()
 
72
{
 
73
        cachedfile="$1"
 
74
        conffile="$2"
 
75
        enable="$3"
 
76
 
 
77
        debug "Setting enable to $3 in $cachedfile"
 
78
 
 
79
        sed -e "s/^\([ \t]*enabled[ \t][ \t]*\).*$/\1$enable;/" < "$cachedfile" >  "$cachedfile.tmp"
 
80
        mv "$cachedfile.tmp"  "$cachedfile"
 
81
 
 
82
 
 
83
        ucf_ask "$cachedfile" "$conffile"
 
84
 
 
85
} # }}}
 
86
 
 
87
# enable - calls enable_disable_util to enable an entry # {{{
 
88
enable()
 
89
{
 
90
        enable_disable_util "$1" "$2" "yes"
 
91
} # }}}
 
92
 
 
93
# disable - calls enable_disable_util to disable an entry # {{{
 
94
disable()
 
95
{
 
96
        enable_disable_util "$1" "$2" "no"
 
97
} # }}}
 
98
 
 
99
# remove - removes an entry # {{{
 
100
remove()
 
101
{
 
102
        cachedfile="$1"
 
103
        conffile="$2"
 
104
 
 
105
        debug "Removing $cachedfile, $conffile"
 
106
 
 
107
        rm -f "$cachedfile" "$conffile"
 
108
        ucf_purge "$conffile"
 
109
 
 
110
} # }}}
 
111
 
 
112
# add - adds a new entry # {{{
 
113
add()
 
114
{
 
115
        line="$1"
 
116
        files=`inetd2rlinetd --force-overwrite --print-file-names -l "$line" "$g_ucfdir"`
 
117
        debug "Converted $line saved in $files"
 
118
        [ -z "$file" ] || return 0
 
119
 
 
120
        for file in $files; do
 
121
                file="${file##*/}"
 
122
                case "$file" in
 
123
                        *_udp)
 
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"
 
131
                                fi
 
132
                                ;;
 
133
                esac
 
134
 
 
135
                ucf_ask "$g_ucfdir/$file" "$g_rlinconfdir/$file"
 
136
        done
 
137
} # }}}
 
138
 
 
139
# operation  - calls add, remove, enable or disable # {{{
 
140
operation()
 
141
{
 
142
        operation="$1"
 
143
        line="$2"
 
144
 
 
145
        [ -n "$line" ] || error "--$operation requires argument"
 
146
 
 
147
        debug "Running $operation for $line"
 
148
 
 
149
        # add
 
150
        if [ "$operation" = "add" ]; then
 
151
                add "$line"
 
152
                return 0
 
153
        fi
 
154
 
 
155
        # disable, enable, remove; line can be comma separated list of values
 
156
        service=""
 
157
        while [ "$line" != "$service" ] ; do
 
158
                service="${line%,*}"
 
159
                line="${line#*,}"
 
160
                found=0
 
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
 
166
                                found=1
 
167
                                "$operation" "$file" "$g_rlinconfdir/$basefile"
 
168
                        fi
 
169
                done
 
170
 
 
171
                if [ $found -eq 0 ]; then
 
172
                        echo "Cannot find cached rlinetd's config files for service $service, ignoring $operation request" >&2;
 
173
                fi
 
174
        done
 
175
} # }}}
 
176
 
 
177
# reload_rlinetd - reloads rlinetd daemon # {{{
 
178
reload_rlinetd()
 
179
{
 
180
        if [ "$g_need_reload" -eq 0 ]; then
 
181
                debug "Configuration not changed, not reloading rlinetd"
 
182
                return 0
 
183
        fi
 
184
 
 
185
        debug "Reloading rlinetd config files"
 
186
 
 
187
    killall -HUP rlinetd || true
 
188
} # }}}
 
189
 
 
190
 
 
191
# MAIN FUNCTION # {{{
 
192
 
 
193
# parse arguments # {{{
 
194
ignore_next=0
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
 
198
                ignore_next=0
 
199
                continue
 
200
        fi
 
201
 
17
202
        case "$i" in
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"
 
205
                        g_mode="$i"
 
206
                        g_mode="${g_mode#--}"
 
207
                        ;;
 
208
                "--debug")
 
209
                        g_debug=1
20
210
                        ;;
21
211
                "--version")
22
212
                        echo "rlinetd's version of update-inetd"
23
 
                        echo "version: $version"
 
213
                        echo "version: $g_version"
24
214
                        exit 0
25
215
                        ;;
26
 
                *)      if [ "x$last" = "x--add" ] ; then
27
 
                                line="$i"
 
216
                "--multi"|"--verbose")
 
217
                        # ignore
 
218
                        ;;
 
219
                "--file"|"--group"|"--comment-chars")
 
220
                        ignore_next=1
 
221
                        ;;
 
222
                "--*")
 
223
                        echo "Unknown option \`$i\' passed to $0, ignoring" >&2;
 
224
                        ;;      
 
225
                *)      if [ -n "$g_mode" ] ; then
 
226
                                [ -z "$g_line" ] || error "--$g_mode requires only one argument"
 
227
                                g_line="$i"
28
228
                        fi
29
229
                        ;;
30
230
        esac
31
 
 
32
 
        last="$i"
33
 
done
34
 
 
35
 
 
36
 
if [ "x$last" = "x--add" ] ;then
37
 
        echo "Option --add requires an argument" 1>&2
38
 
        exit 1;
39
 
fi
40
 
 
41
 
 
42
 
if [ "x$line" != "x" ] ; then
43
 
        inetd2rlinetd  -l "$line" /etc/rlinetd.d
44
 
 
45
 
        # reload configuration
46
 
        killall -HUP rlinetd || true
47
 
fi
48
 
 
49
 
if [ -f /etc/inetd.conf ] ; then
50
 
        real_upd=`dpkg-divert --truename /usr/sbin/update-inetd`
51
 
        [ -x "$real_upd" ] && "$real_upd" "$@" || true
52
 
fi
 
231
done # }}}
 
232
 
 
233
# do our job
 
234
[ -z "$g_mode" ] || operation "$g_mode" "$g_line"
 
235
 
 
236
# reload configuration
 
237
reload_rlinetd
 
238
 
 
239
# execute real update-inetd
 
240
real_upd=`dpkg-divert --truename /usr/sbin/update-inetd`
 
241
[ -x "$real_upd" ] && exec "$real_upd" "$@"
53
242
 
54
243
exit 0
 
244
 # }}}