Pakfire laedt die Listen jetzt besser und hat eine veraenderte Oberflaeche bekommen.
[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         my $force = "noforce";
7         
8         &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
9         &Pakfire::checkcryptodb;
10
11         ### Check if we are running as root
12         #
13         my $user = qx(whoami);
14         chomp($user);
15         unless ( "$user" eq "root" ) {
16           &Pakfire::message("PAKFIRE ERROR: You must run pakfire as user root!");
17           exit 1;
18         }
19         
20         unless ( -e "/var/ipfire/red/active" ) {
21                 &Pakfire::message("PAKFIRE ERROR: You need to be online to run pakfire!");
22                 exit 2;
23         }
24         
25         ### Check if we are started by another name
26         #
27         if ( $0 =~ /pakfire-update$/ ) {
28                 &Pakfire::message("CRON INFO: Running an update");
29                 $ARGV[0] = "update";
30                 $interactive = 0;
31         } elsif ( $0 =~ /pakfire-upgrade$/ ) {
32                 &Pakfire::message("CRON INFO: Running an upgrade");
33                 $ARGV[0] = "upgrade";
34                 $interactive = 0;
35         }
36         
37         unless (@ARGV) {
38                 &Pakfire::usage;
39         }
40         
41         foreach (@ARGV) {
42                 if ("$_" =~ "^-") {
43                         # Turn off interactive mode
44                         $interactive = 0 if ("$_" eq "--non-interactive");
45                         $interactive = 0 if ("$_" eq "-y");
46                         
47                         # Turn off shell colors - Bad for displaying in webinterface
48                         $Pakfire::enable_colors = 0 if ("$_" eq "--no-colors");
49                         
50                         # Turn on force mode
51                         $force = "force" if ("$_" eq "-f" );
52                         $force = "force" if ("$_" eq "--force" );
53                 }
54         }
55
56         if ("$ARGV[0]" eq "install") {
57                 shift;
58                 
59                 ### Make sure that the list is not outdated. 
60                 &Pakfire::dbgetlist("noforce");
61
62                 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
63                 my @db = <FILE>;
64                 close(FILE);
65                 
66                 my $dep;
67                 my @deps;
68                 my $pak;
69                 my @paks;
70                 my @temp;
71                 my @templine;
72                 my $found = 0;
73                 my $return;
74                 my @all;
75                 foreach $pak (@ARGV) {
76                         unless ("$pak" =~ "^-") {
77                                 $return = &Pakfire::isinstalled($pak);
78                                 if ($return eq 0) {
79                                         &Pakfire::message("PAKFIRE INFO: $pak is already installed");
80                                         next; 
81                                 }
82                                 $found = 0;
83                                 foreach (@db) {
84                                         @templine = split(/;/,$_);
85                                         if ("$templine[0]" eq "$pak" ) {
86                                                 push(@paks,$pak);
87                                                 push(@all,$pak);
88                                                 @temp = &Pakfire::resolvedeps("$pak");
89                                                 foreach $dep (@temp) {
90                                                         push(@deps,$dep) if $dep;
91                                                         push(@all,$dep) if $dep;
92                                                 }
93                                                 $found = 1;
94                                                 break;
95                                         }
96                                 }
97                                 if ($found == 0) {
98                                         &Pakfire::message("");
99                                         &Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
100                                 }
101                         }
102                 }
103                 
104                 unless (@paks) {
105                         &Pakfire::message("PAKFIRE ERROR: No packages to install. Exiting...");
106                         exit 1;
107                 }
108
109                 &Pakfire::message("");
110                 &Pakfire::message("");
111                 &Pakfire::message("PAKFIRE INFO: Packages to install:");
112                 foreach $pak (sort @paks) {
113                   my $size = &Pakfire::getsize("$pak");
114                         $size = &Pakfire::beautifysize($size);
115                   &Pakfire::message("PAKFIRE INFO: $pak \t - $size");
116                 }
117                 
118                 if (@deps) {
119                         my %sort = map{ $_, 1 } @deps;
120                         @deps = sort keys %sort;
121                         &Pakfire::message("");
122                         &Pakfire::message("PAKFIRE INFO: Packages to install for dependencies:");
123                 }
124                 foreach $dep (sort @deps) {
125                   my $size = &Pakfire::getsize("$dep");
126                         $size = &Pakfire::beautifysize($size);
127                   &Pakfire::message("PAKFIRE INFO: $dep \t - $size");
128                 }
129                 
130                 my $totalsize;
131                 foreach $pak (@all) {
132                         $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
133                 }
134                 $totalsize = &Pakfire::beautifysize($totalsize);
135                 &Pakfire::message("");
136                 &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize");
137                 &Pakfire::message("");
138                 
139                 if ($interactive) {
140                   &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
141                         my $ret = <STDIN>;
142                         chomp($ret);
143                         &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
144                         if ( $ret ne "y" ) {
145                           &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
146                           exit 1;
147                         }
148                 } else {
149                         &Pakfire::logger("PAKFIRE INFO: Interaction skipped.");
150                 }
151                 
152                 my %sort = map{ $_, 1 } @all;
153                 @all = sort keys %sort;
154
155                 ### Download first
156                 foreach $pak (sort @all) {
157                         &Pakfire::getpak("$pak", "");
158                 }
159
160                 &Pakfire::message("");
161
162                 foreach $pak (sort @all) {
163                         &Pakfire::setuppak("$pak") if ($pak ne "");
164                 }
165                 
166         } elsif ("$ARGV[0]" eq "remove") {
167                 shift;
168                 
169                 my @paks;
170                 my $pak;
171                 foreach $pak (@ARGV) {
172                         unless ("$pak" =~ "^-") {
173                                 $return = &Pakfire::isinstalled($pak);
174                                 if ($return ne 0) {
175                                         &Pakfire::message("PAKFIRE WARN: $pak is not installed");
176                                         next;
177                                 }
178                                 push(@paks, $pak);
179                         }
180                 }
181                 
182                 unless (@paks) {
183                         &Pakfire::message("PAKFIRE ERROR: No packages to remove. Exiting...");
184                         exit 1;
185                 }
186                 
187                 &Pakfire::message("");
188                 &Pakfire::message("");
189                 &Pakfire::message("PAKFIRE INFO: Packages to remove:");
190                 foreach $pak (sort @paks) {
191                   my $size = &Pakfire::getsize("$pak");
192                         $size = &Pakfire::beautifysize($size);
193                   &Pakfire::message("PAKFIRE INFO: $pak \t - $size");
194                 }
195                 
196                 if ($interactive) {
197                   &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
198                         my $ret = <STDIN>;
199                         chomp($ret);
200                         &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
201                         if ( $ret ne "y" ) {
202                           &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
203                           exit 1;
204                         }
205                 }
206                 
207                 foreach $pak (@paks) {
208                         &Pakfire::removepak("$pak");
209                 }
210         
211         
212         } elsif ("$ARGV[0]" eq "update") {
213                 &Pakfire::makeuuid();
214                 &Pakfire::senduuid();
215                 &Pakfire::getmirrors("$force");
216                 &Pakfire::dbgetlist("$force");
217                 &Pakfire::getcoredb("$force");
218
219         } elsif ("$ARGV[0]" eq "upgrade") {
220                 &Pakfire::upgradecore();
221                 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
222                 my @temp;
223                 
224                 foreach (@upgradepaks) {
225                         @temp = &Pakfire::resolvedeps("$_");
226                         foreach (@temp) { push(@upgradepaks,$_) if $_; }
227                 }
228                 
229                 if (@upgradepaks) {
230                         &Pakfire::message("");
231                         &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above.");
232                         if ($interactive) {
233                           &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
234                                 my $ret = <STDIN>;
235                                 chomp($ret);
236                                 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
237                                 if ( $ret ne "y" ) {
238                                   &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
239                                   exit 1;
240                                 }
241                         }
242                 }
243                 
244                 ### Download first
245                 foreach (sort @upgradepaks) {
246                         &Pakfire::getpak("$_", "");
247                 }
248                 
249                 foreach (sort @upgradepaks) {
250                         &Pakfire::upgradepak("$_");
251                 }
252                 
253         } elsif ("$ARGV[0]" eq "list") {
254                 if ("$ARGV[1]" =~ /installed|notinstalled/) {
255                         &Pakfire::dblist("$ARGV[1]", "noweb");
256                 } else {
257                         &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); 
258                         &Pakfire::dblist("all", "noweb");
259                 }
260                 
261         } elsif ("$ARGV[0]" eq "resolvedeps") {
262                 foreach (@ARGV) {
263                         next if ("$_" eq "resolvedeps");
264                         next if ("$_" =~ "^-");
265                         &Pakfire::resolvedeps("$_");
266                 }
267         } elsif ("$ARGV[0]" eq "enable") {
268                 if ("$ARGV[1]" eq "updates") {
269                         system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
270                 elsif ("$ARGV[1]" eq "upgrades") {
271                         system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
272                 }
273         } elsif ("$ARGV[0]" eq "disable") {
274                 if ("$ARGV[1]" eq "updates") {
275                         system("rm -f /etc/fcron.daily/pakfire-update");
276                 elsif ("$ARGV[1]" eq "upgrades") {
277                         system("rm -f /etc/fcron.daily/pakfire-upgrade");
278                 }
279         } else {
280                 &Pakfire::usage;
281         }
282
283 &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing.");
284
285 exit 0;