Kleine Commits um ein paar Fehlermeldungen zu unterdruecken
[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") {
157
158
159 } elsif ("$ARGV[0]" eq "update") {
5b2a12ff 160 my $force = "noforce";
8e58bd37
MT
161 &Pakfire::makeuuid();
162 &Pakfire::senduuid();
c3df33af 163 &Pakfire::getmirrors();
5b2a12ff
MT
164 $force = "force" if ("$ARGV[1]" eq "--force");
165 &Pakfire::dbgetlist("$force");
afabe9f7 166
4b122800
MT
167
168 } elsif ("$ARGV[0]" eq "upgrade") {
99e6df8e
MT
169 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
170 my @temp;
171
172 foreach (@upgradepaks) {
173 @temp = &Pakfire::resolvedeps("$_");
174 foreach (@temp) { push(@upgradepaks,$_) if $_; }
175 }
176
177 if (@upgradepaks) {
178 &Pakfire::message("");
179 &Pakfire::message("We are going to install all packages listed above.");
180 if ($interactive) {
181 &Pakfire::message("Is this okay? [y/N]");
182 my $ret = <STDIN>;
183 chomp($ret);
184 &Pakfire::logger("Answer: $ret");
185 if ( $ret ne "y" ) {
186 &Pakfire::message("Installation aborted.");
187 exit 1;
188 }
189 }
190 }
191
192 ### Download first
193 foreach (sort @upgradepaks) {
194 &Pakfire::message("# --> Downloading: $_");
195 &Pakfire::getpak("$_", "");
196 }
197
198 foreach (sort @upgradepaks) {
199 &Pakfire::upgradepak("$_");
200 }
4b122800 201
afabe9f7 202 } elsif ("$ARGV[0]" eq "list") {
5b2a12ff
MT
203 &Pakfire::dblist("all", "noweb");
204
205 } elsif ("$ARGV[0]" eq "resolvedeps") {
206 foreach (@ARGV) {
207 next if ("$_" eq "resolvedeps");
208 &Pakfire::resolvedeps("$_");
209 }
210
211 } else {
212 &Pakfire::usage;
1bd42c89 213 }
99e6df8e
MT
214
215exit 0;