diff options
author | Arnaud Desmons <adesmons@mandriva.com> | 2002-07-26 09:35:17 +0000 |
---|---|---|
committer | Arnaud Desmons <adesmons@mandriva.com> | 2002-07-26 09:35:17 +0000 |
commit | 2f36de3e050d051244f93c807ba2556e30c297f7 (patch) | |
tree | 81080a379953bb8f3076110fc9c031844eb04abc /news_wizard/scripts/Newsconf.pm | |
parent | ff4638889d241e8c6e9d6b8bbcb411d77f459e74 (diff) | |
download | drakwizard-2f36de3e050d051244f93c807ba2556e30c297f7.tar drakwizard-2f36de3e050d051244f93c807ba2556e30c297f7.tar.gz drakwizard-2f36de3e050d051244f93c807ba2556e30c297f7.tar.bz2 drakwizard-2f36de3e050d051244f93c807ba2556e30c297f7.tar.xz drakwizard-2f36de3e050d051244f93c807ba2556e30c297f7.zip |
first perl traduction
Diffstat (limited to 'news_wizard/scripts/Newsconf.pm')
-rw-r--r-- | news_wizard/scripts/Newsconf.pm | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/news_wizard/scripts/Newsconf.pm b/news_wizard/scripts/Newsconf.pm new file mode 100644 index 00000000..a0968891 --- /dev/null +++ b/news_wizard/scripts/Newsconf.pm @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +package Newsconf; +require "__WIZ_HOME__/common/scripts/Vareqval.pm"; +use MDK::Common; +use strict; + +sub normalize_freq { + my ($freq) = @_; + + if ($freq =~ /(\d*)/) { + $freq = $1; + } + if ($freq <= 0) { + $freq = 0; + } + if ($freq >= 24) { + $freq = 24; + } + $freq; +} + +sub normalize_server { + my ($server) = @_; + + $server; +} + +sub do_it { + defined $ENV{wiz_news_freq} and my $freq = normalize_freq($ENV{wiz_news_freq}) or + die "freq not defined: $!"; + defined $ENV{wiz_news_server} and my $server = normalize_server($ENV{wiz_news_server}) or + die "server not defined: $!"; + my %mdk = Vareqval->get("/etc/sysconfig/mdk_serv"); + $mdk{wiz_news_freq} = $freq; + $mdk{wiz_news_server} = $server; + Vareqval->commit("/etc/sysconfig/mdk_serv", \%mdk); + my $file = "/etc/leafnode/config"; + if (! -f $file) { die "$file not found: $!"}; + my $tmp = `mktemp /tmp/Newsconf.XXXXXX` + or die "can't make a temp file: $!"; + open(OLD, "< __WIZ_HOME__/news_wizard/scripts/config.default") + or die "can't open default: $!"; + open(NEW, "> $tmp") + or die "can't open $tmp: $!"; + while (<OLD>) { + s|__server__|$server|g; + print NEW $_; + } + close(OLD); + close(NEW); + chomp($tmp); + system("mv $tmp $file"); + $file = "/var/spool/cron/news"; + if (-f $file) { + MDK::Common::cp_af($file, "/etc/leafnode/crontab"); + } + $file = "/etc/leafnode/crontab"; + MDK::Common::cp_af($file, $file . ".orig"); + my $file = "/etc/leafnode/crontab"; + my $tmp = `mktemp /tmp/Newsconf.XXXXXX` + or die "can't make a temp file: $!"; + open(OLD, "< __WIZ_HOME__/news_wizard/scripts/news.cron") + or die "can't open default: $!"; + open(NEW, "> $tmp") + or die "can't open $tmp: $!"; + while (<OLD>) { + s|__freq__|$freq|g; + print NEW $_; + } + close(OLD); + close(NEW); + chomp($tmp); + system("mv $tmp $file"); + print "hello\n"; + system("crontab -u news /etc/leafnode/crontab"); + print "hello\n"; +} |