ef395df94c9d6631ecc7f7f2d22ca8fe0d4e1654
[people/teissler/ipfire-2.x.git] / src / pakfire / pakfire
1 #!/usr/bin/perl
2
3 require "/opt/pakfire/lib/functions.pl";
4
5 my $interactive = 1;
6
7 &Pakfire::logger("### IPFire Pakfire $Conf::version started!");
8
9 ### Check if we are running as root
10 #
11 my $user = qx(whoami);
12 chomp($user);
13 unless ( "$user" eq "root" ) {
14 &Pakfire::message("You must run pakfire as user root!");
15 exit 1;
16 }
17
18 unless (@ARGV) {
19 &Pakfire::message("Usage: pakfire <install|remove> <pak(s)>");
20 &Pakfire::message(" <update>");
21 &Pakfire::message(" <upgrade>");
22 exit 1;
23 }
24
25 if ("$ARGV[0]" eq "install") {
26 shift;
27 my @deps;
28 my @paks;
29 my @temp;
30 foreach (@ARGV) {
31 push(@paks,$_);
32 }
33 foreach (@paks) {
34 @temp = &Pakfire::resolvedeps("$_");
35 foreach (@temp) { push(@deps,$_) if $_; }
36 }
37
38 my @all;
39 foreach (@paks) {
40 push(@all,$_);
41 }
42 foreach (@deps) {
43 push(@all,$_);
44 }
45
46 &Pakfire::message("\n\n### Packages to install:");
47 foreach (sort @paks) {
48 my $size = &Pakfire::getsize("$_");
49 $size = &Pakfire::beautifysize($size);
50 &Pakfire::message("# $_ \t\t - $size");
51 }
52
53 &Pakfire::message("\n### Packages to install for dependencies:");
54 foreach (sort @deps) {
55 my $size = &Pakfire::getsize("$_");
56 $size = &Pakfire::beautifysize($size);
57 &Pakfire::message("# $_ \t\t - $size");
58 }
59
60 my $totalsize = &Pakfire::addsizes("@all");
61 $totalsize = &Pakfire::beautifysize($totalsize);
62 &Pakfire::message("\n### Download size: \t ~ $totalsize");
63
64 if ($interactive) {
65 &Pakfire::message("Is this okay? [y/N]");
66 my $ret = <STDIN>;
67 chomp($ret);
68 &Pakfire::logger("Answer: $ret");
69 if ( $ret ne "y" ) {
70 &Pakfire::message("Installation aborted.");
71 exit 1;
72 }
73 }
74
75 &Pakfire::message("### Installing all packages:");
76 foreach (sort @all) { &Pakfire::message("# --> $_"); }
77 &Pakfire::message("");
78
79 ### Download first
80 foreach (sort @all) {
81 &Pakfire::message("# --> Downloading: $_");
82 &Pakfire::getpak("$_", "");
83 }
84
85 foreach (sort @all) {
86 &Pakfire::setuppak("$_");
87 }
88
89
90 } elsif ("$ARGV[0]" eq "remove") {
91
92
93 } elsif ("$ARGV[0]" eq "update") {
94 &Pakfire::makeuuid();
95 &Pakfire::senduuid();
96 &Pakfire::getmirrors();
97
98 } elsif ("$ARGV[0]" eq "list") {
99 &Pakfire::dblist("noweb");
100 }