]> git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/pakfire
DHCP und Squid-Initscripts optimiert fuer ein schnelleres starten und stoppen.
[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
7 &Pakfire::logger("### IPFire Pakfire $Conf::version started!");
8 &Pakfire::checkcryptodb;
9
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) {
20 &Pakfire::usage;
21 }
22
23 foreach (@ARGV) {
24 if ("$_" =~ "^-") {
25 $interactive = 0 if ("$_" eq "--non-interactive");
26 $interactive = 0 if ("$_" eq "-y");
27 }
28 }
29
30 if ("$ARGV[0]" eq "install") {
31 shift;
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;
41 my @deps;
42 my $pak;
43 my @paks;
44 my @temp;
45 my @templine;
46 my $found = 0;
47 my $return;
48 my @all;
49 foreach $pak (@ARGV) {
50 unless ("$pak" =~ "^-") {
51 $return = &Pakfire::isinstalled($pak);
52 if ($return eq 0) {
53 &Pakfire::message("Package $pak is already installed.");
54 next;
55 }
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 }
71 &Pakfire::message("");
72 &Pakfire::message("The pak \"$pak\" is not known. Please try running \"pakfire update\".") if ($found == 0);
73 }
74 }
75
76 unless (@paks) {
77 &Pakfire::message("No packages to install. Exiting...");
78 exit 1;
79 }
80
81 &Pakfire::message("");
82 &Pakfire::message("");
83 &Pakfire::message("### Packages to install:");
84 foreach $pak (sort @paks) {
85 my $size = &Pakfire::getsize("$pak");
86 $size = &Pakfire::beautifysize($size);
87 &Pakfire::message("# $pak \t\t - $size");
88 }
89
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");
98 $size = &Pakfire::beautifysize($size);
99 &Pakfire::message("# $dep \t\t - $size");
100 }
101
102 my $totalsize;
103 foreach $pak (@all) {
104 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
105 }
106 $totalsize = &Pakfire::beautifysize($totalsize);
107 &Pakfire::message("");
108 &Pakfire::message("### Total size: \t ~ $totalsize");
109 &Pakfire::message("");
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 }
121
122 my %sort = map{ $_, 1 } @all;
123 @all = sort keys %sort;
124
125 ### Download first
126 foreach $pak (sort @all) {
127 &Pakfire::message("# --> Downloading: $pak");
128 &Pakfire::getpak("$pak", "");
129 }
130
131 foreach $pak (sort @all) {
132 &Pakfire::setuppak("$pak") if ($pak ne "");
133 }
134
135 } elsif ("$ARGV[0]" eq "remove") {
136
137
138 } elsif ("$ARGV[0]" eq "update") {
139 my $force = "noforce";
140 &Pakfire::makeuuid();
141 &Pakfire::senduuid();
142 &Pakfire::getmirrors();
143 $force = "force" if ("$ARGV[1]" eq "--force");
144 &Pakfire::dbgetlist("$force");
145
146
147 } elsif ("$ARGV[0]" eq "upgrade") {
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 }
180
181 } elsif ("$ARGV[0]" eq "list") {
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;
192 }
193
194 exit 0;