IPSec Ctrl nochmal geƤndert damit VPN Watch ordentlich gestartet wird
[people/pmueller/ipfire-2.x.git] / src / pakfire / pakfire
CommitLineData
c3df33af 1#!/usr/bin/perl
c1ae1ad6 2
1bd42c89
MT
3 require "/opt/pakfire/lib/functions.pl";
4
5 my $interactive = 1;
6
afabe9f7 7 &Pakfire::logger("### IPFire Pakfire $Conf::version started!");
cde0e116 8 &Pakfire::checkcryptodb;
c1ae1ad6 9
1bd42c89
MT
10 ### Check if we are running as root
11 #
12 my $user = qx(whoami);
13 chomp($user);
14 unless ( "$user" eq "root" ) {
15 &Pakfire::message("You must run pakfire as user root!");
16 exit 1;
17 }
18
19 unless (@ARGV) {
5b2a12ff 20 &Pakfire::usage;
1bd42c89 21 }
4b122800
MT
22
23 foreach (@ARGV) {
24 if ("$_" =~ "^-") {
25 $interactive = 0 if ("$_" eq "--non-interactive");
26 $interactive = 0 if ("$_" eq "-y");
27 }
28 }
c1ae1ad6 29
1bd42c89
MT
30 if ("$ARGV[0]" eq "install") {
31 shift;
99e6df8e
MT
32
33 ### Make sure that the list is not outdated.
34 &Pakfire::dbgetlist("noforce");
35
36 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
37 my @db = <FILE>;
38 close(FILE);
39
40 my $dep;
a08c3a2e 41 my @deps;
99e6df8e 42 my $pak;
a08c3a2e
MT
43 my @paks;
44 my @temp;
99e6df8e
MT
45 my @templine;
46 my $found = 0;
186e3d2c 47 my $return;
4b122800 48 my @all;
99e6df8e
MT
49 foreach $pak (@ARGV) {
50 unless ("$pak" =~ "^-") {
186e3d2c
MT
51 $return = &Pakfire::isinstalled($pak);
52 if ($return eq 0) {
53 &Pakfire::message("Package $pak is already installed.");
54 next;
55 }
99e6df8e
MT
56 $found = 0;
57 foreach (@db) {
58 @templine = split(/;/,$_);
59 if ("$templine[0]" eq "$pak" ) {
60 push(@paks,$pak);
61 push(@all,$pak);
62 @temp = &Pakfire::resolvedeps("$pak");
63 foreach $dep (@temp) {
64 push(@deps,$dep) if $dep;
65 push(@all,$dep) if $dep;
66 }
67 $found = 1;
68 break;
69 }
70 }
186e3d2c
MT
71 &Pakfire::message("");
72 &Pakfire::message("The pak \"$pak\" is not known. Please try running \"pakfire update\".") if ($found == 0);
5b2a12ff 73 }
a08c3a2e 74 }
186e3d2c
MT
75
76 unless (@paks) {
77 &Pakfire::message("No packages to install. Exiting...");
78 exit 1;
79 }
97520ed5 80
186e3d2c
MT
81 &Pakfire::message("");
82 &Pakfire::message("");
83 &Pakfire::message("### Packages to install:");
84 foreach $pak (sort @paks) {
85 my $size = &Pakfire::getsize("$pak");
1bd42c89 86 $size = &Pakfire::beautifysize($size);
186e3d2c 87 &Pakfire::message("# $pak \t\t - $size");
1bd42c89
MT
88 }
89
186e3d2c
MT
90 if (@deps) {
91 my %sort = map{ $_, 1 } @deps;
92 @deps = sort keys %sort;
93 &Pakfire::message("");
94 &Pakfire::message("### Packages to install for dependencies:");
95 }
96 foreach $dep (sort @deps) {
97 my $size = &Pakfire::getsize("$dep");
1bd42c89 98 $size = &Pakfire::beautifysize($size);
186e3d2c 99 &Pakfire::message("# $dep \t\t - $size");
1bd42c89 100 }
4b122800
MT
101
102 my $totalsize;
186e3d2c
MT
103 foreach $pak (@all) {
104 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
4b122800 105 }
1bd42c89 106 $totalsize = &Pakfire::beautifysize($totalsize);
186e3d2c
MT
107 &Pakfire::message("");
108 &Pakfire::message("### Total size: \t ~ $totalsize");
109 &Pakfire::message("");
1bd42c89
MT
110
111 if ($interactive) {
112 &Pakfire::message("Is this okay? [y/N]");
113 my $ret = <STDIN>;
114 chomp($ret);
115 &Pakfire::logger("Answer: $ret");
116 if ( $ret ne "y" ) {
117 &Pakfire::message("Installation aborted.");
118 exit 1;
119 }
120 }
186e3d2c
MT
121
122 my %sort = map{ $_, 1 } @all;
123 @all = sort keys %sort;
a08c3a2e
MT
124
125 ### Download first
186e3d2c
MT
126 foreach $pak (sort @all) {
127 &Pakfire::message("# --> Downloading: $pak");
128 &Pakfire::getpak("$pak", "");
a08c3a2e 129 }
c1ae1ad6 130
186e3d2c
MT
131 foreach $pak (sort @all) {
132 &Pakfire::setuppak("$pak") if ($pak ne "");
1bd42c89 133 }
1bd42c89
MT
134
135 } elsif ("$ARGV[0]" eq "remove") {
136
137
138 } elsif ("$ARGV[0]" eq "update") {
5b2a12ff 139 my $force = "noforce";
8e58bd37
MT
140 &Pakfire::makeuuid();
141 &Pakfire::senduuid();
c3df33af 142 &Pakfire::getmirrors();
5b2a12ff
MT
143 $force = "force" if ("$ARGV[1]" eq "--force");
144 &Pakfire::dbgetlist("$force");
afabe9f7 145
4b122800
MT
146
147 } elsif ("$ARGV[0]" eq "upgrade") {
99e6df8e
MT
148 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
149 my @temp;
150
151 foreach (@upgradepaks) {
152 @temp = &Pakfire::resolvedeps("$_");
153 foreach (@temp) { push(@upgradepaks,$_) if $_; }
154 }
155
156 if (@upgradepaks) {
157 &Pakfire::message("");
158 &Pakfire::message("We are going to install all packages listed above.");
159 if ($interactive) {
160 &Pakfire::message("Is this okay? [y/N]");
161 my $ret = <STDIN>;
162 chomp($ret);
163 &Pakfire::logger("Answer: $ret");
164 if ( $ret ne "y" ) {
165 &Pakfire::message("Installation aborted.");
166 exit 1;
167 }
168 }
169 }
170
171 ### Download first
172 foreach (sort @upgradepaks) {
173 &Pakfire::message("# --> Downloading: $_");
174 &Pakfire::getpak("$_", "");
175 }
176
177 foreach (sort @upgradepaks) {
178 &Pakfire::upgradepak("$_");
179 }
4b122800 180
afabe9f7 181 } elsif ("$ARGV[0]" eq "list") {
5b2a12ff
MT
182 &Pakfire::dblist("all", "noweb");
183
184 } elsif ("$ARGV[0]" eq "resolvedeps") {
185 foreach (@ARGV) {
186 next if ("$_" eq "resolvedeps");
187 &Pakfire::resolvedeps("$_");
188 }
189
190 } else {
191 &Pakfire::usage;
1bd42c89 192 }
99e6df8e
MT
193
194exit 0;