From 63c47ccccde0395b8df118ac93b65ccb258ecea0 Mon Sep 17 00:00:00 2001 From: Stew Benedict Date: Tue, 10 Feb 2004 00:09:49 +0000 Subject: Fix failure to disable user cron job. Code reduction. --- perl-install/standalone/drakbackup | 53 +++++++++++++------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'perl-install/standalone/drakbackup') diff --git a/perl-install/standalone/drakbackup b/perl-install/standalone/drakbackup index ca29cc8d9..bd150e95b 100755 --- a/perl-install/standalone/drakbackup +++ b/perl-install/standalone/drakbackup @@ -595,55 +595,38 @@ sub read_cron_files() { } sub save_cron_files() { - my $entry_changed = 0; my $tmpcron = "$ENV{HOME}/tmp/crontab.tmp"; if ($nonroot_user && $when_space ne "custom" && $when_space ne '' && $backup_daemon) { show_warning("w", N("Interval cron not available as non-root")); $backup_daemon = 0; return 1; - } - my @cron_file = ("#!/bin/sh\n", "export USER=root\n", "/usr/sbin/drakbackup --daemon > /dev/null 2>&1\n"); - - if ($backup_daemon) { - if ($when_space ne "custom") { - output_p("/etc/cron.$when_space/drakbackup", @cron_file); - system("chmod +x /etc/cron.$when_space/drakbackup"); } else { - my $newdetail = join(" ", $time_string, $exec_string, "\n"); - system("crontab -l | tail +4 > $tmpcron"); - my @cronlines = cat_($tmpcron); - my $index = 0; - foreach (@cronlines) { - if (/$exec_string/) { - $cronlines[$index] = $newdetail; - $entry_changed = 1; - } - $index++; - } - push(@cronlines, $newdetail) if $entry_changed == 0; - output($tmpcron, @cronlines); - system("crontab $tmpcron"); - unlink($tmpcron); - } - } elsif (!$nonroot_user) { foreach (qw(hourly daily weekly monthly)) { -f "/etc/cron.$_/drakbackup" and rm_rf("/etc/cron.$_/drakbackup"); } + } + my @cron_file = ("#!/bin/sh\n", "export USER=root\n", "/usr/sbin/drakbackup --daemon > /dev/null 2>&1\n"); + + if ($when_space ne "custom" && $when_space ne '' && $backup_daemon) { + output_p("/etc/cron.$when_space/drakbackup", @cron_file); + system("chmod +x /etc/cron.$when_space/drakbackup"); + } + if ($when_space eq "custom" || !$backup_daemon) { + my $newdetail = join(" ", $time_string, $exec_string, "\n") if $backup_daemon; system("crontab -l | tail +4 > $tmpcron"); my @cronlines = cat_($tmpcron); - if (any { /$exec_string/ } @cronlines) { - my $index = 0; - foreach (@cronlines) { - if (/$exec_string/) { - splice(@cronlines, $index, 1); - } - $index++; + my $index = 0; + foreach (@cronlines) { + if (/$exec_string/) { + splice(@cronlines, $index, 1); } - output($tmpcron, @cronlines); - system("crontab $tmpcron"); - unlink($tmpcron); + $index++ } + push(@cronlines, $newdetail) if $backup_daemon; + output($tmpcron, @cronlines); + system("crontab $tmpcron"); + unlink($tmpcron); } } -- cgit v1.2.1