3
# $Id: inetd2rlinetd.in,v 1.9 2006-03-16 19:40:36 robert Exp $
3
# $Id: inetd2rlinetd.in 264 2009-01-01 22:28:45Z robert $
6
my $use_nls="@USE_NLS@" eq "yes" ? 1 : 0;
9
eval 'use Locale::gettext';
14
textdomain("@PACKAGE@");
15
eval ' sub _g { return gettext(shift); } ';
19
eval 'sub _g { return shift; }';
6
25
my $dir="/etc/rlinetd.d";
28
my $opt_force_overwrite=0;
29
my $opt_print_fnames=0;
10
while ( defined($opt = $ARGV[0]) && ($opt eq "-f" || $opt eq "-l" ) ) {
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;
35
} elsif ($opt eq "--print-file-names") {
36
$opt_print_fnames = 1;
38
} elsif ($opt eq "-f" || $opt eq "-l" ) {
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";
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);
22
53
if ($#lines > -1) {
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, $!);
32
63
&add_single_line($_);
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+(.+)/);
61
93
my $instances = "";
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");
71
103
if($proto =~ /^rpc\/(.+)$/) {
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");
82
114
if($uid =~ /^(.+)\.(.+)$/) {
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};
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";
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};
127
161
$realfile = "$dir/$service";
162
print $realfile . "\n" if $opt_print_fnames;
128
163
my $mode= (-e $realfile) ? &ask_user($realfile, $tempfile) : "rename";
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};
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"), $!);
140
175
unlink $tempfile;
149
184
my $tmp_f = shift;
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>;
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>;
159
194
# they don't differ, don't
160
195
return "skip" if join('', @real_data) eq join('', @tmp_data);
197
return "rename" if $opt_force_overwrite;
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));
174
210
while ($mode eq "") {
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";
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> ;