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

« back to all changes in this revision

Viewing changes to scripts/inetd2rlinetd.in

  • 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
#!@perlpath@ -w
2
 
# vim:ts=4
3
 
# $Id: inetd2rlinetd.in,v 1.9 2006-03-16 19:40:36 robert Exp $
 
2
# vim:ts=4:sts=4
 
3
# $Id: inetd2rlinetd.in 264 2009-01-01 22:28:45Z robert $
 
4
 
 
5
BEGIN {
 
6
        my $use_nls="@USE_NLS@" eq "yes" ? 1 : 0;
 
7
        if ($use_nls)
 
8
        {
 
9
                eval 'use Locale::gettext';
 
10
                $use_nls=!$@;
 
11
        }
 
12
        if ($use_nls)
 
13
        {
 
14
                textdomain("@PACKAGE@");
 
15
                eval ' sub _g { return gettext(shift); } ';
 
16
        }
 
17
        else
 
18
        {
 
19
                eval 'sub _g { return shift; }';
 
20
        }
 
21
}
 
22
 
4
23
 
5
24
my %services=();
6
25
my $dir="/etc/rlinetd.d";
7
26
my $ifile="";
8
27
my @lines=();
 
28
my $opt_force_overwrite=0;
 
29
my $opt_print_fnames=0;
9
30
 
10
 
while ( defined($opt = $ARGV[0]) && ($opt eq "-f" || $opt eq "-l" ) ) {
11
 
        shift(@ARGV);
12
 
        $arg = shift(@ARGV);
13
 
        die "Option \`$opt' requires an argument\n" unless ($arg);
14
 
        $ifile =  $arg if $opt eq "-f";
15
 
        push(@lines, $arg) if $opt eq "-l";
 
31
while ( defined($opt = $ARGV[0]))  {
 
32
        if ($opt eq "--force-overwrite") {
 
33
                $opt_force_overwrite = 1;
 
34
            shift(@ARGV);
 
35
        } elsif ($opt eq "--print-file-names") {
 
36
                $opt_print_fnames = 1;
 
37
            shift(@ARGV);
 
38
        } elsif ($opt eq "-f" || $opt eq "-l" ) {        
 
39
            shift(@ARGV);
 
40
                $arg = shift(@ARGV);
 
41
                die sprintf( _g("Option \`%s' requires an argument\n"), $opt) unless ($arg);
 
42
                $ifile =  $arg if $opt eq "-f";
 
43
                push(@lines, $arg) if $opt eq "-l";
 
44
        } else {
 
45
                last;
 
46
        }
16
47
}
17
48
 
18
49
$dir = $ARGV[0] if defined $ARGV[0];
19
 
die "Directory $dir does not exist\n" unless -d $dir;
20
 
die "Options \`-f' and \`-l' cannot be mixed together\n" if ($ifile ne "" && $#lines > -1);
 
50
die sprintf(_g("Directory %s does not exist\n", $dir)) unless -d $dir;
 
51
die _g("Options \`-f' and \`-l' cannot be mixed together\n") if ($ifile ne "" && $#lines > -1);
21
52
 
22
53
if ($#lines > -1) {
23
54
        for $_ (@lines) {
27
58
} else {
28
59
 
29
60
        $ifile = "-" if $ifile eq "";
30
 
        open IFILE, $ifile or die "Cannot open $ifile: $!\n";
 
61
        open IFILE, $ifile or die sprintf(_g("Cannot open %s: %s\n"), $ifile, $!);
31
62
        while (<IFILE>) {
32
63
                &add_single_line($_);
33
64
        }
51
82
 
52
83
        chomp;
53
84
        s/\\t/ /g;
 
85
        my $enabled = s/^\s*#<off>#\s*// ? "no" : "yes";
54
86
        return if(/^\s*#/);
55
87
        return unless(/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)/);
56
88
 
57
 
        my $out         = "";
58
 
        my $server      = "";
59
 
        my $gid         = "";
60
 
        my $rpcvers     = "";
 
89
        my $out                 = "";
 
90
        my $server              = "";
 
91
        my $gid                 = "";
 
92
        my $rpcvers             = "";
61
93
        my $instances   = "";
62
 
        my $name        = $1;
63
 
        my $proto       = $2;
64
 
        my $wait        = $3;
65
 
        my $uid         = $4;
66
 
        my $exec        = $5;
 
94
        my $name                = $1;
 
95
        my $proto               = $2;
 
96
        my $wait                = $3;
 
97
        my $uid                 = $4;
 
98
        my $exec                = $5;
67
99
 
68
 
        &warn("skipping internal service: $name\n") && return 
 
100
        &warn(sprintf(_g("skipping internal service: %s\n"), $name)) && return 
69
101
                if ($exec eq "internal");
70
102
 
71
103
        if($proto =~ /^rpc\/(.+)$/) {
76
108
                }
77
109
        }
78
110
 
79
 
        &warn("unknown protocol: $proto\n; skipping service $name") && return 
 
111
        &warn(sprintf(_g("unknown protocol: %s\n; skipping service %s"), $proto, $name)) && return 
80
112
                unless ($proto eq "udp" || $proto eq "tcp");
81
113
 
82
114
        if($uid =~ /^(.+)\.(.+)$/) {
95
127
                $instances = $1;
96
128
        }       
97
129
 
98
 
        $out .= $services{$name} if defined $services{$name};
 
130
        my $key = $proto eq "tcp" ? $name : "${name}_${proto}";
 
131
        $out .= $services{$key} if defined $services{$key};
99
132
 
100
133
        $out .= "service \"${name}_${proto}\" {\n";
 
134
        $out .= "\tenabled $enabled;\n";
101
135
        $out .= "\tprotocol $proto;\n";
102
136
        $out .= "\tport \"$name\";\n" unless ($rpcvers);
103
137
        $out .= "\tuser \"$uid\";\n";
109
143
        $out .= "\trpc {\n\t\tname \"$name\";\n\t\tversion $rpcvers;\n\t}\n" if($rpcvers);
110
144
        $out .= "}\n";
111
145
 
112
 
        $services{$name} = $out;
 
146
        $services{$key} = $out;
113
147
 
114
148
}
115
149
 
119
153
        my $realfile; 
120
154
 
121
155
        for my $service (keys %services) {
122
 
                open OFILE, ">$tempfile" or die "Cannot open temporary file for writing: $!\n";
 
156
                open OFILE, ">$tempfile" or die sprintf(_g("Cannot open temporary file for writing: %s\n"), $!);
123
157
                print OFILE "# This file was automatically generated by inetd2rlinetd\n\n";
124
158
                print OFILE $services{$service};
125
159
                close OFILE;
126
160
                
127
161
                $realfile = "$dir/$service";
 
162
                print $realfile . "\n" if $opt_print_fnames;
128
163
                my $mode= (-e $realfile) ? &ask_user($realfile, $tempfile) : "rename";
129
164
                
130
165
 
131
166
                if ($mode eq "append") {
132
 
                        open OFILE, ">>$realfile" or die "Cannot open file $realfile: $!\n";
 
167
                        open OFILE, ">>$realfile" or die sprintf(_g("Cannot open file %s: %s\n"), $realfile, $!);
133
168
                        print OFILE "\n" . $services{$service};
134
169
                        close OFILE;
135
170
                }
136
171
                elsif ($mode eq "rename") {
137
 
                        rename($tempfile, $realfile) or die "Cannot rename tempfile: $!\n";
 
172
                        rename($tempfile, $realfile) or die sprintf(_g("Cannot rename tempfile: %s\n"), $!);
138
173
                }
139
174
 
140
175
                unlink $tempfile;
149
184
        my $tmp_f  = shift;
150
185
 
151
186
        # check if the two files are different
152
 
        open FILE, "<$real_f" or die "Cannot open file $real_f: $!";
 
187
        open FILE, "<$real_f" or die sprintf(_g("Cannot open file %s: %s\n"), $real_f, $!);
153
188
        my @real_data = <FILE>;
154
189
        close FILE;
155
 
        open FILE,  "<$tmp_f"   or die "Cannot open file $tmp_f: $!";
 
190
        open FILE,  "<$tmp_f"   or die sprintf(_g("Cannot open file %s: %s\n"), $tmp_f, $!);
156
191
        my @tmp_data  = <FILE>; 
157
192
        close FILE;
158
193
        
159
194
        # they don't differ, don't 
160
195
        return "skip" if join('', @real_data) eq join('', @tmp_data);
161
196
 
 
197
        return "rename" if $opt_force_overwrite;
 
198
 
162
199
 
163
200
        my $mode="";
164
201
        my $input = undef;
165
202
        my $on_tty = ( -t STDERR ) and 
166
203
                        ( -t STDIN or open $input, "</dev/tty" );
167
204
        if (! $on_tty ) {
168
 
                &warn(  "File $real_f already exists.\n" .
169
 
                        "I'm refusing to overwrite it with different version,\n" .
170
 
                        "when I'm not running on the terminal.\n");
 
205
                &warn( sprintf(_g("File %s already exists.\n") .
 
206
                        _g("I'm refusing to overwrite it with different version,\nwhen I'm not running on the terminal.\n"), $real_f));
171
207
                return "skip"
172
208
        }
173
209
 
174
210
        while ($mode eq "") {
175
211
 
176
 
                print STDERR "\n\nFile $real_f already exists\n\n";
177
 
                print STDERR "* Show [d]ifference between new version\n";
178
 
                print STDERR "* [O]verwrite the file\n";
179
 
                print STDERR "* [S]kip the file\n";
180
 
                print STDERR "* [A]ppend to the end of the file\n\n";
 
212
                print STDERR sprintf("\n\n" . _g("File %s already exists.\n") . "\n", $real_f);
 
213
                print STDERR _g("* Show [d]ifference between new version.\n");
 
214
                print STDERR _g("* [O]verwrite the file.\n");
 
215
                print STDERR _g("* [S]kip the file.\n");
 
216
                print STDERR _g("* [A]ppend to the end of the file.\n") . "\n";
181
217
 
182
218
                do {
183
 
                        print STDERR "Please choose: [D/O/S/A]: ";
 
219
                        print STDERR _g("Please choose: [D/O/S/A]: ");
184
220
                        $_=  (defined $input) ? <$input> : <STDIN>  ;
185
221
                        chomp;
186
222
                        $_= uc $_;