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