aboutsummaryrefslogtreecommitdiffstats
path: root/del-syslog
blob: c5c9725fa492768bd45bc9ca3519300ad533e3d7 (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
34
35
36
37
38
39
40
#!/usr/bin/perl
# rpm helper scriptlet to remove a syslog entry (sysklogd and syslog-ng)
# $Id$
use strict;

main(@ARGV) unless caller();

sub main {
    die <<EOF if @ARGV < 2;
usage: $0 <pkg> <nb>
EOF
    my ($package, $number) = @ARGV;

    # don't do anything for upgrade
    exit(0) if $number == 1;

    del_rsyslog_entry($package);
}

sub del_rsyslog_entry {
    my ($package) = @_;

    my $file = "/etc/rsyslog.d/$package.conf";

    # check the file exists
    return unless -f $file;

    # check the file is the one created by package installation
    open(my $in, '<', $file)
        or die "Can't open $file for reading: $!";
    my $line = <$in>;
    close($in);
    return if $line ne "# Automatically added by $package installation\n";

    unlink $file
        or die "Can't delete $file: $!";
    system('service rsyslog condrestart 2>&1 >/dev/null');
}

1;