summaryrefslogtreecommitdiffstats
path: root/perl-install/run_program.pm
blob: 43b7c3d28386c52373d40bc9122803860e1f410a (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package run_program; # $Id$

use diagnostics;
use strict;

use MDK::Common;
use log;

1;

sub run_or_die {
    my ($name, @args) = @_;
    run($name, @args) or die "$name failed\n";
}
sub rooted_or_die {
    my ($root, $name, @args) = @_;
    rooted($root, $name, @args) or die "$name failed\n";
}

sub get_stdout {
    my ($name, @args) = @_;
    my @r;
    run($name, '>', \@r, @args) or return;
    wantarray() ? @r : join('', @r);
}
sub rooted_get_stdout {
    my ($root, $name, @args) = @_;
    my @r;
    rooted($root, $name, '>', \@r, @args) or return;
    wantarray() ? @r : join('', @r);
}

sub run { raw({}, @_) }

sub rooted {
    my ($root, $name, @args) = @_;
    raw({ root => $root }, $name, @args);
}

sub raw {
    my ($options, $name, @args) = @_;
    my $root = $options->{root} || '';
    my $str = ref($name) ? $name->[0] : $name;
    log::l("running: $str @args" . ($root ? " with root $root" : ""));

    return 1 if $root && $<;

    $root ? ($root .= '/') : ($root = '');
    install_any::check_prog(ref($name) ? $name->[0] : $name) if !$root && $::isInstall;


    my ($stdout_raw, $stdout_mode, $stderr_raw, $stderr_mode);
    ($stdout_mode, $stdout_raw, @args) = @args if $args[0] =~ /^>>?$/;
    ($stderr_mode, $stderr_raw, @args) = @args if $args[0] =~ /^2>>?$/;
    
    $ENV{HOME} || $::isInstall or $ENV{HOME} = '/root';
    my $stdout = $stdout_raw && (ref($stdout_raw) ? "$ENV{HOME}/tmp/.drakx-stdout.$$" : "$root$stdout_raw");
    my $stderr = $stderr_raw && (ref($stderr_raw) ? "$ENV{HOME}/tmp/.drakx-stderr.$$" : "$root$stderr_raw");

    if (my $pid = fork()) {
	if ($options->{detach}) {
	    $pid;
	} else {
	    my $ok;
	    eval {
		local $SIG{ALRM} = sub { die "ALARM" };
		alarm($options->{timeout} || 10 * 60);
		waitpid $pid, 0;
		$ok = $? == 0;
		alarm 0;
	    };
	    if ($@) {
		log::l("ERROR: killing runaway process (process=$str, pid=$pid, args=@args, error=$@)");
		kill 9, $pid;
		return;
	    }

	    if ($stdout_raw && ref($stdout_raw)) {	    
		if (ref($stdout_raw) eq 'ARRAY') { 
		    @$stdout_raw = cat_($stdout);
		} else { 
		    $$stdout_raw = cat_($stdout);
		}
		unlink $stdout;
	    }
	    if ($stderr_raw && ref($stderr_raw)) {
		if (ref($stderr_raw) eq 'ARRAY') { 
		    @$stderr_raw = cat_($stderr);
		} else { 
		    $$stderr_raw = cat_($stderr);
		}
		unlink $stderr;
	    }
	    $ok;
	}
    } else {
	if ($stderr && $stderr eq 'STDERR') {
	} elsif ($stderr) {
	    $stderr_mode =~ s/2//;
	    open STDERR, "$stderr_mode $stderr" or die "run_program can't output in $stderr (mode `$stderr_mode')";
	} elsif ($::isInstall) {
	    open STDERR, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log";
	}
	if ($stdout && $stdout eq 'STDOUT') {
	} elsif ($stdout) {
	    open STDOUT, "$stdout_mode $stdout" or die "run_program can't output in $stdout (mode `$stdout_mode')";
	} elsif ($::isInstall) {
	    open STDOUT, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log";
	}

	$root and chroot $root;
	chdir "/";

	if (ref $name) {
	    unless (exec { $name->[0] } $name->[1], @args) {
		log::l("exec of $name->[0] failed: $!");
		c::_exit(128);
	    }
	} else {
	    unless (exec $name, @args) {
		log::l("exec of $name failed: $!");
		c::_exit(128);
	    }

	}
    }

}
c">#: lib/isodumper.py:225 msgid "Wrote: {}% " msgstr "" #: lib/isodumper.py:251 msgid "Backup confirmation" msgstr "" #: lib/isodumper.py:251 msgid "Do you want to overwrite the file?" msgstr "Chcete prepísať súbor?" #: lib/isodumper.py:259 #, python-format msgid "" "The destination directory is too small to receive the backup (%s Mb needed)" msgstr "Cieľový adresár je pre uloženie zálohy príliš malý (potrebných %s Mb)" #: lib/isodumper.py:265 lib/isodumper.py:560 lib/isodumper.py:736 msgid "Backup to:" msgstr "" #: lib/isodumper.py:278 #, python-brace-format msgid "{source} successfully written to {target}" msgstr "" #: lib/isodumper.py:300 msgid "The device is too small to contain the ISO file." msgstr "Zariadenie je príliš malé aby mohlo obsahovať ISO obraz." #: lib/isodumper.py:304 msgid "Writing confirmation" msgstr "" #: lib/isodumper.py:307 msgid "The device is bigger than 32 Gbytes. Are you sure you want use it?" msgstr "Zariadenie je väčšie ako 32 GB. Ste si istý že ho chcete použiť?" #: lib/isodumper.py:307 lib/isodumper.py:390 msgid "Warning" msgstr "Upozornenie" #: lib/isodumper.py:314 #, python-brace-format msgid "Writing {source} to {target}" msgstr "" #: lib/isodumper.py:315 msgid " to " msgstr " do " #: lib/isodumper.py:315 msgid "Executing copy from " msgstr "Spúšťam kópiu z" #: lib/isodumper.py:331 #, python-brace-format msgid "Image {source} successfully written to {target}" msgstr "" #: lib/isodumper.py:332 msgid "Bytes written: " msgstr "Zapísaných bytov:" #: lib/isodumper.py:333 msgid "Checking " msgstr "Kontrolujem" #: lib/isodumper.py:351 msgid "Adding persistent partition" msgstr "" #: lib/isodumper.py:354 msgid "No key for encrypted partition provided. Adding the partition aborted." msgstr "" #: lib/isodumper.py:358 msgid "Added encrypted persistent partition" msgstr "" #: lib/isodumper.py:363 msgid "Added persistent partition" msgstr "" #: lib/isodumper.py:378 msgid "Success" msgstr "Úspech" #: lib/isodumper.py:378 msgid "" "The operation completed successfully.\n" " You are free to unplug it now, a logfile \n" "(/home/-user- or /root)/.isodumper/isodumper.log will be saved when\n" " you close the application." msgstr "" #: lib/isodumper.py:390 msgid "" "Writing is in progress. Exiting during writing \n" " will make the device or the backup unusable.\n" " Are you sure you want to quit during writing?" msgstr "" #: lib/isodumper.py:402 lib/isodumper.py:486 msgid "Error" msgstr "Chyba" #: lib/isodumper.py:442 msgid "Image " msgstr "Obraz " #: lib/isodumper.py:446 lib/isodumper.py:508 msgid "IsoDumper" msgstr "IsoDumper" #: lib/isodumper.py:446 msgid "Mageia IsoDumper" msgstr "" #: lib/isodumper.py:448 msgid "" "This GUI program is primarily for safely writing a bootable ISO image to a " "USB flash drive, an operation devious & potentially hazardous when done by " "hand. As a bonus, it can also back up the entire previous contents of the " "flash drive onto the hard disc, and restore the flash drive to its previous " "state subsequently." msgstr "" #: lib/isodumper.py:452 msgid "It gives also a feature for formatting the USB device." msgstr "" #: lib/isodumper.py:453 msgid "" "IsoDumper can be launched either from the menus, or a user console with the " "command 'isodumper'." msgstr "" #: lib/isodumper.py:454 msgid "" "The root password is solicited when this is necessary for the program's " "operation." msgstr "" #: lib/isodumper.py:455 msgid "" "The flash drive can be inserted beforehand or once the program is started. " "In the latter case, a dialogue will say that there is no flash drive " "inserted, and allow a 'retry' to find it once it is. <BR />(You may have to " "close any automatically opened File Manager window)." msgstr "" #: lib/isodumper.py:458 msgid "" "The fields of the main window are as follows:<BR />- Device to work on: the " "device of the USB flash drive, a drop-down list to choose from.<BR />- Write " "Image: to choose the source ISO image *.iso (or flash drive backup file *." "img) to write out.<BR />- Write to device: This button launches the " "operation - with a prior warning dialogue." msgstr "" #: lib/isodumper.py:462 msgid "" "- Add a persistent partition: the remaining space will be used in a new " "partition where data from the Live system can be written and recovered " "between sessions." msgstr "" #: lib/isodumper.py:463 msgid "" "- Encrypt: the persistent partition will be encrypted with the key provided " "in <i>Key</i> field." msgstr "" #: lib/isodumper.py:464 msgid "The operation is shown in the progress bar beneath." msgstr "" #: lib/isodumper.py:465 msgid "" "- Backup to: define the name and placement of the backup image file. The " "current flash drive will be backed up to a disc file. Note that the entire " "flash drive is preserved, regardless of its actual contents; ensure that you " "have the necessary free disc space (the same size as the USB device). This " "backup file can be used later to restore the flash drive by selecting it as " "the source *.img file to write out." msgstr "" #: lib/isodumper.py:469 msgid "- Backup the device: launch the backup operation." msgstr "" #: lib/isodumper.py:470 msgid "" "- Format the device: create an unique partition on the entire volume in the " "specified format in FAT, exFAT, NTFS or ext. You can specify a volume name " "and the format in a new dialog box." msgstr "" #: lib/isodumper.py:486 msgid "There is another instance of Isodumper already running." msgstr "" #: lib/isodumper.py:500 msgid "Choose an image" msgstr "" #: lib/isodumper.py:501 msgid "" "Warning\n" "This will destroy all data on the target device,\n" " are you sure you want to proceed?\n" " If you say ok here, please <b>do not unplug</b> the device " "during the following operation." msgstr "" #: lib/isodumper.py:535 msgid "Device to work on:" msgstr "Zariadenie na ktoré sa bude zapisovať" #: lib/isodumper.py:539 msgid "Write Image:" msgstr "Zapísať obraz:" #: lib/isodumper.py:545 msgid "&Write to device" msgstr "" #: lib/isodumper.py:550 msgid "Add a persistent partition in the remaining space" msgstr "" #: lib/isodumper.py:552 msgid "Encrypt partition" msgstr "Šifrovať oddiel" #: lib/isodumper.py:553 msgid "Key:" msgstr "" #: lib/isodumper.py:566 msgid "Backup the device" msgstr "" #: lib/isodumper.py:569 msgid "Format the device in FAT, exFAT, NTFS or ext:" msgstr "" #: lib/isodumper.py:571 msgid "Format the device" msgstr "" #: lib/isodumper.py:574 msgid "Progress" msgstr "" #: lib/isodumper.py:578 msgid "Report" msgstr "Správa" #: lib/isodumper.py:581 lib/isodumper.py:691 msgid "Refresh" msgstr "" #: lib/isodumper.py:583 msgid "About" msgstr "" #: lib/isodumper.py:585 msgid "Help" msgstr "" #: lib/isodumper.py:587 msgid "Quit" msgstr "" #: lib/isodumper.py:593 msgid "UDisks2 is not available on your system" msgstr "UDisks2 nenájdené vo vašom systéme" #: lib/isodumper.py:609 msgid "Label for the device:" msgstr "Meno pre zariadenie:" #: lib/isodumper.py:613 msgid "FAT 32 (Windows)" msgstr "FAT 32 (Windows)" #: lib/isodumper.py:615 msgid "exFAT (Windows)" msgstr "" #: lib/isodumper.py:617 msgid "NTFS (Windows)" msgstr "NTFS (Windows)" #: lib/isodumper.py:619 msgid "ext4 (Linux)" msgstr "ext4 (Linux)" #: lib/isodumper.py:621 msgid "Execute" msgstr "Vykonať" #: lib/isodumper.py:622 lib/isodumper.py:692 msgid "Cancel" msgstr "Zrušiť" #: lib/isodumper.py:663 msgid "OK" msgstr "OK" #: lib/isodumper.py:673 msgid "Yes" msgstr "Áno" #: lib/isodumper.py:674 msgid "No" msgstr "Nie" #: lib/isodumper.py:682 msgid "A tool for writing ISO images to a device" msgstr "" #: lib/isodumper.py:682 msgid "Oliver Grawert<BR />Papoteur<BR />Pictures : Timothée Giet" msgstr "" #: lib/isodumper.py:690 msgid "" "Warning\n" "No target devices were found.\n" "You need to plug in a USB Key to which the image can be written." msgstr "" #: polkit/org.mageia.isodumper.policy.in.h:1 msgid "Isodumper requesting write access" msgstr "" #: polkit/org.mageia.isodumper.policy.in.h:2 msgid "Manatools requesting write access" msgstr "" #: share/applications/format-usb.desktop.in.h:1 msgid "A GUI tool to format USB sticks" msgstr "" #: share/applications/isodumper.desktop.in.h:1 msgid "A GUI tool to write .img and .iso files to USB sticks" msgstr ""