diff options
author | Stew Benedict <stewb@mandriva.org> | 2003-08-22 00:04:55 +0000 |
---|---|---|
committer | Stew Benedict <stewb@mandriva.org> | 2003-08-22 00:04:55 +0000 |
commit | bc689cd2922d556a50198f34eac72709b23da255 (patch) | |
tree | dfbf804a352e0e532835ed5fae69b08dd9c14138 | |
parent | a94e99671187c0bf7eb593ec1eee9a3565afc411 (diff) | |
download | drakx-backup-do-not-use-bc689cd2922d556a50198f34eac72709b23da255.tar drakx-backup-do-not-use-bc689cd2922d556a50198f34eac72709b23da255.tar.gz drakx-backup-do-not-use-bc689cd2922d556a50198f34eac72709b23da255.tar.bz2 drakx-backup-do-not-use-bc689cd2922d556a50198f34eac72709b23da255.tar.xz drakx-backup-do-not-use-bc689cd2922d556a50198f34eac72709b23da255.zip |
fix crash on file select of "Other"
finish custom cron configuration - normal users can now do cron backups
-rwxr-xr-x | perl-install/standalone/drakbackup | 148 |
1 files changed, 105 insertions, 43 deletions
diff --git a/perl-install/standalone/drakbackup b/perl-install/standalone/drakbackup index 035ef4aa8..c38a45c31 100755 --- a/perl-install/standalone/drakbackup +++ b/perl-install/standalone/drakbackup @@ -270,20 +270,13 @@ my $max_space = 1000.0; my @no_devices = translate("No devices found"); my %help; my $time_string = "* * * * *"; - -foreach (@ARGV) { - - /--default/ and backend_mode(); - /--daemon/ and daemon_mode(); - /--show-conf/ and show_conf(); - /--config-info/ and explain_conf(); - /--cd-info/ and get_cd_info(), exit(0); - /--debug/ and $DEBUG = 1, next; -} +my $exec_string = "export USER=$ENV{USER}; /usr/sbin/drakbackup --daemon > /dev/null 2>&1"; # allow not-root user with own config if ($ENV{HOME} ne '/root') { standalone::explanations("Running as $ENV{USER}..."); + #- doesn't get defined when run from cron + $user_home = "/home/$ENV{USER}" if $user_home eq ''; $cfg_dir = "$user_home/.drakbackup/"; $save_path = $cfg_dir . "backups"; $log_file = $cfg_dir . "drakbackup.log"; @@ -291,12 +284,20 @@ if ($ENV{HOME} ne '/root') { $nonroot_user = 1; $not_warned = 1; $backup_sys = 0; - $backup_daemon = 0; - $daemon = 0; @user_list = $ENV{USER}; } $cfg_file = $cfg_dir . "drakbackup.conf"; +foreach (@ARGV) { + + /--default/ and backend_mode(); + /--daemon/ and daemon_mode(); + /--show-conf/ and show_conf(); + /--config-info/ and explain_conf(); + /--cd-info/ and get_cd_info(), exit(0); + /--debug/ and $DEBUG = 1, next; +} + sub setup_tooltips() { %help = ( 'use_expect' => N("Expect is an extension to the Tcl scripting language that allows interactive sessions without user intervention."), @@ -456,7 +457,7 @@ sub the_time() { sub get_tape_info() { my @line_data; - my $info = "/tmp/dmesg"; + my $info = "$ENV{HOME}/tmp/dmesg"; @tape_devices = (); system("dmesg | grep 'st[0-9] at' > $info"); @@ -474,7 +475,7 @@ sub get_tape_info() { sub get_free_space { my ($dir) = @_; my @line_data; - my $free = "/tmp/free_space"; + my $free = "$ENV{HOME}/tmp/free_space"; system("df -P $dir | tail -1 > $free"); local *FREE; @@ -484,14 +485,14 @@ sub get_free_space { @line_data = split(/[ \t,]+/, $_); } close FREE; -# unlink($free); + unlink($free); my $free_space = int($line_data[3] / 1024); return $free_space; } sub check_storage_quota { my ($dir) = @_; - my $used = "/tmp/used_space"; + my $used = "$ENV{HOME}/tmp/used_space"; my $used_space; system("du $dir > $used"); @@ -554,7 +555,7 @@ sub get_cd_info() { #- this is scsi-channel, id, lun from /dev/scsi/host* #- oops - can't count on devfs - use dmesg - $info = "/tmp/dmesg"; + $info = "$ENV{HOME}/tmp/dmesg"; system("dmesg | grep sr[0-9] > $info"); local *INFO; open INFO, $info or warn("Can't open $info\n"); @@ -566,9 +567,9 @@ sub get_cd_info() { $line_data[5] =~ s/scsi//; $cd_devices{$line_data[3]}{rec_dev} = $line_data[5] . "," . $line_data[9] . "," . $line_data[11]; } - } - close INFO; - unlink($info); + } + close INFO; + unlink($info); #- should we also try to get the human readable name for display purposes? @@ -605,12 +606,12 @@ sub save_conf_file() { "NET_PROTO=$net_proto\n", "CD_TIME=$cd_time\n", "USER_MAIL=$user_mail\n", - "DAEMON_TIME_SPACE=$when_space\n", "CD_DEVICE=$cd_device\n", "LOGIN=$login_user\n", "TAPE_DEVICE=$tape_device\n", "HOST_NAME=$host_name\n" ); + $backup_daemon and push @cfg_list, "DAEMON_TIME_SPACE=$when_space\n"; $no_critical_sys and push @cfg_list, "NO_CRITICAL_SYS\n"; $no_critical_sys or push @cfg_list, "CRITICAL_SYS\n"; $backupignore and push @cfg_list, "BACKUPIGNORE\n"; @@ -674,11 +675,23 @@ sub read_cron_files() { !$daemon_found and $backup_daemon = 0; } else { $custom_cron = 1; + my $tmpcron = "$ENV{HOME}/tmp/crontab.tmp"; + system("crontab -l | tail +4 > $tmpcron"); + my @cronline = grep { /drakbackup/ } cat_($tmpcron); + if (@cronline) { + @cronline = split(" ", $cronline[0]); + my @crondetail = splice(@cronline, 0, 5); + $time_string = join(" ", @crondetail); + } + unlink($tmpcron); } } sub save_cron_files() { - if ($nonroot_user) { + my $entry_changed = 0; + my $tmpcron = "$ENV{HOME}/tmp/crontab.tmp"; + + if ($nonroot_user && $when_space ne "custom" && $backup_daemon) { show_warning("w", N("Cron not available yet as non-root")) if $not_warned; $not_warned = 0; $backup_daemon = 0; @@ -694,18 +707,45 @@ sub save_cron_files() { 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); } } else { foreach (qw(hourly daily weekly monthly)) { -f "/etc/cron.$_/drakbackup" and rm_rf("/etc/cron.$_/drakbackup"); } + 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++; + } + output($tmpcron, @cronlines); + system("crontab $tmpcron"); + unlink($tmpcron); + } } } sub read_conf_file() { if (-e $cfg_file) { -# %config = getVarsFromSh($cfg_file) || print "You must be root to read configuration file. \n"; local *CONF_FILE; open(CONF_FILE, "<" . $cfg_file) || print "You must be root to read configuration file. \n"; local $_; @@ -1515,7 +1555,7 @@ sub build_backup_files() { build_cd() if $daemon_media eq 'cd'; build_tape() if $daemon_media eq 'tape'; - $results .= N("\nDrakbackup activities via %s:\n\n", $daemon_media); + $results .= N("\nDrakbackup activities via %s:\n\n", $daemon_media) if $daemon_media ne 'hd'; $results .= $log_buff; } @@ -1551,9 +1591,10 @@ sub build_backup_files() { $results .= N("\nDrakbackup activities via tape:\n\n"); } $results .= $log_buff; - results_to_logfile(); } + results_to_logfile(); + if ($send_mail) { if (send_mail($results)) { $interactive and send_mail_pb(); @@ -1682,8 +1723,7 @@ sub file_ok_sel { my $file_name = $file_selection->get_filename; if (!member($file_name, @list_other)) { push(@list_other, $file_name); - $list_model->append($iter); - $list_model->set($iter, [ 0 => $file_name ]); + $list_model->append_set(undef, $file_name); } } @@ -2498,14 +2538,16 @@ sub advanced_when() { #- custom setup - let user specify month, day of month, day of week, hour, minute my $combo_month_when = new Gtk2::OptionMenu(); - $combo_month_when->set_popdown_strings("*", N("January"), N("February"), N("March"), + my @months = ("*", N("January"), N("February"), N("March"), N("April"), N("May"), N("June"), N("July"), N("August"), N("September"), N("October"), N("November"), N("December")); + $combo_month_when->set_popdown_strings(@months); my $combo_day_when = new Gtk2::OptionMenu(); $combo_day_when->set_popdown_strings("*", (1..31)); my $combo_weekday_when = new Gtk2::OptionMenu(); - $combo_weekday_when->set_popdown_strings("*", N("Sunday"), N("Monday"), N("Tuesday"), - N("Wednesday"), N("Thursday"), N("Friday"), N("Saturday")); + my @weekdays = ("*", N("Sunday"), N("Monday"), N("Tuesday"), + N("Wednesday"), N("Thursday"), N("Friday"), N("Saturday")); + $combo_weekday_when->set_popdown_strings(@weekdays); my $combo_hour_when = new Gtk2::OptionMenu(); $combo_hour_when->set_popdown_strings("*", (0..23)); my $combo_minute_when = new Gtk2::OptionMenu(); @@ -2513,7 +2555,21 @@ sub advanced_when() { my $entry_crontab = new Gtk2::Entry(); gtkset_editable($entry_crontab, 0); - + + my @time_list = split(" ", $time_string); + $combo_minute_when->entry->set_text($time_list[0]); + $combo_hour_when->entry->set_text($time_list[1]); + $combo_day_when->entry->set_text($time_list[2]); + if ($time_list[3] =~ /\*/) { + $combo_month_when->entry->set_text($time_list[3]); + } else { + $combo_month_when->entry->set_text($months[$time_list[3]]); + } + if ($time_list[4] =~ /\*/) { + $combo_weekday_when->entry->set_text($time_list[4]); + } else { + $combo_weekday_when->entry->set_text($weekdays[$time_list[4] + 1]); + } # my $button_apply = new Gtk2::Button(N("Apply")); #- drop down list of possible media - default to config value @@ -2593,25 +2649,31 @@ sub advanced_when() { advanced_when(); }); if ($custom_cron) { - my $exec_string = "/export USER=root; usr/sbin/drakbackup --daemon > /dev/null 2>&1"; $entry_crontab->set_text("$time_string $exec_string") } - $combo_month_when->entry->signal_connect('changed', sub { -# my @time_list = split($time_string); - - $time_string = join(" ", $combo_month_when->get_history, "* * * *"); - destroy_widget(); - advanced_when(); - }); + $combo_minute_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_minute_when->get_history - 1, 0) }); + $combo_hour_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_hour_when->get_history - 1, 1) }); + $combo_day_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_day_when->get_history, 2) }); + $combo_month_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_month_when->get_history, 3) }); + $combo_weekday_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_weekday_when->get_history - 1, 4) }); - $entry_media_type->entry->signal_connect('changed', sub { - $daemon_media = $entry_media_type->entry->get_text; - }); + $entry_media_type->entry->signal_connect('changed', sub { $daemon_media = $entry_media_type->entry->get_text }); fonction_env(\$box_when, \&advanced_when, \&advanced_box); $up_box->show_all; } +sub combo_to_cron_string { + my ($field, $location) = @_; + $field = "*" if $field == 0 && $location > 1 && $location < 4; + $field = "*" if $field == -1 && ($location < 2 || $location == 4); + my @time_list = split(" ", $time_string); + splice(@time_list, $location, 1, $field); + $time_string = join(" ", @time_list); + destroy_widget(); + advanced_when(); +} + sub advanced_options() { my $box_options; |