aboutsummaryrefslogtreecommitdiffstats
path: root/del-syslog
blob: dbcf1c20433203717db591fbd9e4ff7addfa501f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
# rpm helper scriptlet to remove a syslog entry (sysklogd and syslog-ng)
# $Id$

die <<EOF if @ARGV < 2;
usage: $0 <pkg> <nb>
EOF

foreach my $file ('/etc/syslog.conf', '/etc/syslog-ng.conf') {
    del_syslog_entry($package, $file) if -f $file;
}

sub del_syslog_entry {
    my ($package, $file) = @_;

    my $content;
    open(my $in, '<', $file)
        or die "Can't open $file for reading: $!";
    while (my $line = <$in>) {
        if ($line =~ /^# BEGIN: Automatically added by $package installation$/) {
            while ($line = <$in>) {
                last if $line =~ /^# END$/;
            }
        } else {
            $content .= $line;
        }
    }

    open(my $out, '>', $file)
        or die "Can't open $file for writing: $!";
    print $out $content;
    close($out);
}