Die Mindestgröße des Dateisystems nochmal reduziert für die Installation
[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
06209efc
MT
19 ### Check if there are running some other pakfire processes
20 #
21 #my $return = `pidof pakfire`;
22 #chomp($return);
23 #if ($return) {
24 # &Pakfire::message("There are running some other pakfire processes...");
25 # exit 1;
26 #}
27
28 ### Check if we are started by another name
29 #
30 if ( $0 =~ /pakfire-update$/ ) {
31 &Pakfire::message("Running an update started by fcron.");
32 $ARGV[0] = "update";
33 $interactive = 0;
34 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
35 &Pakfire::message("Running an upgrade started by fcron.");
36 $ARGV[0] = "upgrade";
37 $interactive = 0;
38 }
39
1bd42c89 40 unless (@ARGV) {
5b2a12ff 41 &Pakfire::usage;
1bd42c89 42 }
4b122800
MT
43
44 foreach (@ARGV) {
45 if ("$_" =~ "^-") {
46 $interactive = 0 if ("$_" eq "--non-interactive");
47 $interactive = 0 if ("$_" eq "-y");
48 }
49 }
c1ae1ad6 50
1bd42c89
MT
51 if ("$ARGV[0]" eq "install") {
52 shift;
99e6df8e
MT
53
54 ### Make sure that the list is not outdated.
55 &Pakfire::dbgetlist("noforce");
56
57 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
58 my @db = <FILE>;
59 close(FILE);
60
61 my $dep;
a08c3a2e 62 my @deps;
99e6df8e 63 my $pak;
a08c3a2e
MT
64 my @paks;
65 my @temp;
99e6df8e
MT
66 my @templine;
67 my $found = 0;
186e3d2c 68 my $return;
4b122800 69 my @all;
99e6df8e
MT
70 foreach $pak (@ARGV) {
71 unless ("$pak" =~ "^-") {
186e3d2c
MT
72 $return = &Pakfire::isinstalled($pak);
73 if ($return eq 0) {
74 &Pakfire::message("Package $pak is already installed.");
75 next;
76 }
99e6df8e
MT
77 $found = 0;
78 foreach (@db) {
79 @templine = split(/;/,$_);
80 if ("$templine[0]" eq "$pak" ) {
81 push(@paks,$pak);
82 push(@all,$pak);
83 @temp = &Pakfire::resolvedeps("$pak");
84 foreach $dep (@temp) {
85 push(@deps,$dep) if $dep;
86 push(@all,$dep) if $dep;
87 }
88 $found = 1;
89 break;
90 }
91 }
186e3d2c
MT
92 &Pakfire::message("");
93 &Pakfire::message("The pak \"$pak\" is not known. Please try running \"pakfire update\".") if ($found == 0);
5b2a12ff 94 }
a08c3a2e 95 }
186e3d2c
MT
96
97 unless (@paks) {
98 &Pakfire::message("No packages to install. Exiting...");
99 exit 1;
100 }
97520ed5 101
186e3d2c
MT
102 &Pakfire::message("");
103 &Pakfire::message("");
104 &Pakfire::message("### Packages to install:");
105 foreach $pak (sort @paks) {
106 my $size = &Pakfire::getsize("$pak");
1bd42c89 107 $size = &Pakfire::beautifysize($size);
186e3d2c 108 &Pakfire::message("# $pak \t\t - $size");
1bd42c89
MT
109 }
110
186e3d2c
MT
111 if (@deps) {
112 my %sort = map{ $_, 1 } @deps;
113 @deps = sort keys %sort;
114 &Pakfire::message("");
115 &Pakfire::message("### Packages to install for dependencies:");
116 }
117 foreach $dep (sort @deps) {
118 my $size = &Pakfire::getsize("$dep");
1bd42c89 119 $size = &Pakfire::beautifysize($size);
186e3d2c 120 &Pakfire::message("# $dep \t\t - $size");
1bd42c89 121 }
4b122800
MT
122
123 my $totalsize;
186e3d2c
MT
124 foreach $pak (@all) {
125 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
4b122800 126 }
1bd42c89 127 $totalsize = &Pakfire::beautifysize($totalsize);
186e3d2c
MT
128 &Pakfire::message("");
129 &Pakfire::message("### Total size: \t ~ $totalsize");
130 &Pakfire::message("");
1bd42c89
MT
131
132 if ($interactive) {
133 &Pakfire::message("Is this okay? [y/N]");
134 my $ret = <STDIN>;
135 chomp($ret);
136 &Pakfire::logger("Answer: $ret");
137 if ( $ret ne "y" ) {
138 &Pakfire::message("Installation aborted.");
139 exit 1;
140 }
141 }
186e3d2c
MT
142
143 my %sort = map{ $_, 1 } @all;
144 @all = sort keys %sort;
a08c3a2e
MT
145
146 ### Download first
186e3d2c
MT
147 foreach $pak (sort @all) {
148 &Pakfire::message("# --> Downloading: $pak");
149 &Pakfire::getpak("$pak", "");
a08c3a2e 150 }
c1ae1ad6 151
186e3d2c
MT
152 foreach $pak (sort @all) {
153 &Pakfire::setuppak("$pak") if ($pak ne "");
1bd42c89 154 }
1bd42c89
MT
155
156 } elsif ("$ARGV[0]" eq "remove") {
e44b26cf
MT
157 shift;
158
159 my @paks;
160 my $pak;
161
162 foreach $pak (@ARGV) {
163 unless ("$pak" =~ "^-") {
164 $return = &Pakfire::isinstalled($pak);
165 if ($return ne 0) {
166 &Pakfire::message("Package $pak is not installed.");
167 next;
168 }
169
170 push(@paks, $pak);
171
172 }
173 }
174
175 unless (@paks) {
176 &Pakfire::message("No packages to remove. Exiting...");
177 exit 1;
178 }
179
180 &Pakfire::message("");
181 &Pakfire::message("");
182 &Pakfire::message("### Packages to remove:");
183 foreach $pak (sort @paks) {
184 my $size = &Pakfire::getsize("$pak");
185 $size = &Pakfire::beautifysize($size);
186 &Pakfire::message("# $pak \t\t - $size");
187 }
188
189 if ($interactive) {
190 &Pakfire::message("Is this okay? [y/N]");
191 my $ret = <STDIN>;
192 chomp($ret);
193 &Pakfire::logger("Answer: $ret");
194 if ( $ret ne "y" ) {
195 &Pakfire::message("Installation aborted.");
196 exit 1;
197 }
198 }
199
200 foreach $pak (@paks) {
201 &Pakfire::removepak("$pak");
202 }
1bd42c89
MT
203
204
205 } elsif ("$ARGV[0]" eq "update") {
5b2a12ff 206 my $force = "noforce";
8e58bd37
MT
207 &Pakfire::makeuuid();
208 &Pakfire::senduuid();
c3df33af 209 &Pakfire::getmirrors();
5b2a12ff
MT
210 $force = "force" if ("$ARGV[1]" eq "--force");
211 &Pakfire::dbgetlist("$force");
afabe9f7 212
4b122800
MT
213
214 } elsif ("$ARGV[0]" eq "upgrade") {
99e6df8e
MT
215 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
216 my @temp;
217
218 foreach (@upgradepaks) {
219 @temp = &Pakfire::resolvedeps("$_");
220 foreach (@temp) { push(@upgradepaks,$_) if $_; }
221 }
222
223 if (@upgradepaks) {
224 &Pakfire::message("");
225 &Pakfire::message("We are going to install all packages listed above.");
226 if ($interactive) {
227 &Pakfire::message("Is this okay? [y/N]");
228 my $ret = <STDIN>;
229 chomp($ret);
230 &Pakfire::logger("Answer: $ret");
231 if ( $ret ne "y" ) {
232 &Pakfire::message("Installation aborted.");
233 exit 1;
234 }
235 }
236 }
237
238 ### Download first
239 foreach (sort @upgradepaks) {
240 &Pakfire::message("# --> Downloading: $_");
241 &Pakfire::getpak("$_", "");
242 }
243
244 foreach (sort @upgradepaks) {
245 &Pakfire::upgradepak("$_");
246 }
4b122800 247
afabe9f7 248 } elsif ("$ARGV[0]" eq "list") {
5b2a12ff
MT
249 &Pakfire::dblist("all", "noweb");
250
251 } elsif ("$ARGV[0]" eq "resolvedeps") {
252 foreach (@ARGV) {
253 next if ("$_" eq "resolvedeps");
254 &Pakfire::resolvedeps("$_");
255 }
256
257 } else {
258 &Pakfire::usage;
1bd42c89 259 }
99e6df8e
MT
260
261exit 0;