diff options
Diffstat (limited to 'trunk/del-syslog')
-rwxr-xr-x | trunk/del-syslog | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/trunk/del-syslog b/trunk/del-syslog new file mode 100755 index 0000000..456ffe0 --- /dev/null +++ b/trunk/del-syslog @@ -0,0 +1,74 @@ +#!/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; + + my $release_file = '/etc/release'; + open(my $fh, '<', $release_file) + or die "can't open $release_file: $!"; + my $line = <$fh>; + $line =~ /^Mageia release (\d\d\d\d\.\d)/; + my $release = $1; + close($fh); + + del_rsyslog_entry($package); +} + +sub del_sysklogd_entry { + my ($package) = @_; + + my $file = "/etc/syslog.conf"; + + 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); + + system('service syslog condrestart 2>&1 >/dev/null'); +} + +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; |