summaryrefslogtreecommitdiffstats
path: root/_irpm
blob: 5ea04672e5de0c879cd5dbb1a18deba6bfc6bff0 (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
#!/usr/bin/perl

# for i18n
use POSIX;
use Locale::gettext;

setlocale (LC_ALL, "");
textdomain ("urpmi");

$automatic = 0;
$timeout = 15;

$DIR = "/var/lib/urpmi";
$BASE = "$DIR/autoirpm";
$INSTALL_SCRIPT_REP = "$BASE.scripts";

$rpm = shift @ARGV;
print STDERR "autoirpm: ", gettext("installing $rpm\n");

`xtest`;
$X = ($? == 0);

my $pid;
$SIG{ALRM} = sub { $pid and kill 9, $pid; not_found(); };
alarm $timeout;

if (!$automatic) {
    $interactive_mesg = gettext("Automatic installation of packages...\nYou requested installation of package $rpm\n") . gettext("Is it OK?");
    if ($X) {
	my $ok = gettext("Ok");
	my $cancel = gettext("Cancel");
	($pid = fork) or exec "gmessage", "-default", $ok, "-buttons", "$ok:0,$cancel:2", $interactive_mesg;
	wait();
	$? and not_found();
    } else {
	if (isatty(0)) {
	    $noexpr = gettext("Nn");
	    $yesexpr = gettext("Yy");
	    print $interactive_mesg, gettext(" (Y/n) ");
	    <STDIN> =~ /[$yesexpr]/ or not_found();
	} else {
	    # Arghhh not in automatic and no way to contact the user... dying
	    not_found();
	}
    }
}
alarm 0;

$urpmi = !$automatic && $X ? "gurpmi" : "urpmi";
fork or exec $urpmi, "--comment", $ARGV[0], $rpm; wait;

# launch the initial prog
(readlink $ARGV[0]) !~ /$INSTALL_SCRIPT_REP/ and exec @ARGV;

not_found();

sub not_found {
    print STDERR gettext("$rpm: command not found\n");
    exit 127;
}