2 # Functions for gentoo package management
4 chop($system_arch = `uname -m`);
5 $pkg_dir = "/var/db/pkg";
6 $portage_bin = "/usr/lib/portage/bin";
8 $package_list_binary = $package_list_command = "$portage_bin/pkglist";
9 if (!-x $package_list_binary) {
10 $package_list_binary = &has_command("qlist");
11 $package_list_command = $package_list_binary." --nocolor -Iv";
14 sub list_package_system_commands
16 return ( $package_list_binary || "pkglist" );
19 sub list_update_system_commands
24 # list_packages([package]*)
25 # Fills the array %packages with all or listed packages
30 &open_execute_command(LIST, $package_list_command, 1, 1);
32 if (/^([^\/]+)\/([^0-9]+)-(\d\S+)$/ &&
33 !@_ || &indexof($2, @_) >= 0) {
34 $packages{$i,'name'} = $2;
35 $packages{$i,'class'} = $1;
36 $packages{$i,'version'} = $3;
37 &open_readfile(BUILD, "$pkg_dir/$1/$2-$3/$2-$3.ebuild");
39 if (/DESCRIPTION="([^"]+)"/ || /DESCRIPTION='([^']+)'/) {
40 $packages{$i,'desc'} = $1;
51 # package_search(string, [allavailable])
52 # Searches the package database for packages matching some string and puts
57 local $qm = quotemeta($_[0]);
58 &open_execute_command(SEARCH, "emerge search $qm", 1, 1);
62 if (/^\*\s+([^\/]+)\/(\S+)/) {
63 $packages{$n,'name'} = $2;
64 $packages{$n,'class'} = $1;
65 $packages{$n,'missing'} = 0;
67 elsif (/version\s+Available:\s+(\S+)/i) {
68 $packages{$n,'version'} = $1;
70 elsif (/version\s+Installed:\s+\[\s+Not/i && !$_[1]) {
71 $packages{$n,'missing'} = 1;
73 elsif (/\s+Description:\s*(.*)/i) {
74 $packages{$n,'desc'} = $1;
78 $packages{$n,'desc'} .= " " if ($packages{$n,'desc'});
79 $packages{$n,'desc'} .= $nl;
81 $n++ if (!$packages{$n,'missing'} || $_[1]);
88 # package_info(package)
89 # Returns an array of package information in the order
90 # name, class, description, arch, version, vendor, installtime
94 local $n = &list_packages($_[0]);
96 local @st = stat("$pkg_dir/$packages{0,'class'}/$packages{0,'name'}-$packages{0,'version'}");
97 return ( $packages{0,'name'}, $packages{0,'class'}, $packages{0,'desc'},
98 $system_arch, $packages{0,'version'}, "Gentoo", &make_date($st[9]) );
102 # Check if some file is a package file
105 local $qm = quotemeta($_[0]);
106 local $out = &backquote_command("emerge --pretend $qm 2>&1", 1);
110 # file_packages(file)
111 # Returns a list of all packages in the given file, in the form
112 # package description
116 local $qm = quotemeta($_[0]);
117 &open_execute_command(EMERGE, "emerge --pretend $qm", 1, 1);
121 if (/\s+[NRU]\s+\]\s+([^\/]+)\/([^0-9]+)\-(\d\S+)/) {
129 # install_options(file, package)
130 # Outputs HTML for choosing install options for some package
133 print &ui_table_row($text{'emerge_noreplace'},
134 &ui_radio("noreplace", 0, [ [ 0, $text{'yes'} ], [ 1, $text{'no'} ] ]));
136 print &ui_table_row($text{'emerge_onlydeps'},
137 &ui_yesno_radio("onlydeps", 0));
140 $show_install_progress = 1;
142 # install_package(file, package, [&inputs], [show])
143 # Install the given package from the given file, using options from %in
147 local $in = $_[2] ? $_[2] : \%in;
148 local $cmd = "emerge";
149 $cmd .= " --noreplace" if ($in{'noreplace'});
150 $cmd .= " --onlydeps" if ($in{'onlydeps'});
151 $cmd .= " ".quotemeta($_[1]);
153 &open_execute_command(OUT, "$cmd 2>&1", 1);
155 print &html_escape($_);
158 return $? ? "Emerge error" : undef;
162 &open_execute_command(OUT, "$cmd 2>&1 | tail -10", 1);
167 return $? ? "<pre>$out</pre>" : undef;
171 # check_files(package)
172 # Fills in the %files array with information about the files belonging
173 # to some package. Values in %files are path type user group size error
177 local (@files, %filesmap);
179 &list_packages($_[0]);
180 &open_readfile(CONTENTS, "$pkg_dir/$packages{0,'class'}/$packages{0,'name'}-$packages{0,'version'}/CONTENTS");
183 local @l = split(/\s+/);
184 $files{$i,'path'} = $l[1];
185 $files{$i,'type'} = $l[0] eq 'dir' ? 1 :
186 $l[0] eq 'sym' ? 3 : 0;
187 local $real = &translate_filename($l[1]);
188 local @st = stat($real);
189 $files{$i,'user'} = getpwuid($st[4]);
190 $files{$i,'group'} = getgrgid($st[5]);
191 $files{$i,'size'} = $st[7];
193 $files{$i,'error'} = "Does not exist";
195 elsif ($l[0] eq 'sym') {
196 $files{$i,'link'} = $l[3];
197 local $lnk = readlink($real);
198 $files{$i,'error'} = "Incorrect link" if ($l[3] ne $lnk);
200 elsif ($l[0] eq 'obj') {
202 $filesmap{$l[1]} = $i;
203 $files{$i,'md5'} = $l[2];
208 if (&has_command("md5sum")) {
209 &open_execute_command(MD5, "md5sum ".join(" ", @files), 1, 1);
211 local ($md, $fn) = split(/\s+/);
212 local $n = $filesmap{$fn};
213 if ($md ne $files{$n,'md5'}) {
214 $files{$n,'error'} = "Checksum failed";
222 # installed_file(file)
223 # Given a filename, fills %file with details of the given file and returns 1.
224 # If the file is not known to the package system, returns 0
225 # Usable values in %file are path type user group mode size packages
228 local ($cf, $type, @packs);
229 local $real_dir = &translate_filename($pkg_dir);
230 while($cf = <$real_dir/*/*/CONTENTS>) {
233 local @l = split(/\s+/);
234 if ($l[1] eq $_[0]) {
236 $cf =~ /\/([^0-9\/]+)-(\d[^\s\/]+)\/CONTENTS$/;
238 $type = $l[0] if (!$type);
243 return 0 if (!@packs);
245 local $real = &translate_filename($_[0]);
246 local @st = stat($real);
247 $file{'packages'} = join(' ', @packs);
248 $file{'path'} = $_[0];
249 $file{'user'} = getpwuid($st[4]);
250 $file{'group'} = getgrgid($st[5]);
251 $file{'mode'} = sprintf "%o", $st[2] & 07777;
252 $file{'size'} = $st[7];
253 $file{'link'} = readlink($real);
254 $file{'type'} = $type eq 'dir' ? 1 :
255 $type eq 'sym' ? 3 : 0;
261 # delete_package(package, [&options])
262 # Attempt to remove some package
265 local $out = &backquote_logged("emerge -u ".quotemeta($_[0])." 2>&1");
266 return $? ? "<pre>$out</pre>" : undef;
271 return "Gentoo Ebuild";
279 $has_update_system = 1;
281 # update_system_input()
282 # Returns HTML for entering a package to install
283 sub update_system_input
285 return "$text{'emerge_input'} <input name=update size=20> <input type=button onClick='window.ifield = form.update; chooser = window.open(\"../$module_name/emerge_find.cgi\", \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=600,height=500\")' value=\"$text{'emerge_find'}\">";
288 # update_system_install([package])
289 # Install some package with emerge
290 sub update_system_install
292 local $update = $_[0] || $in{'update'};
293 local $cmd = "emerge ".quotemeta($update);
295 print "<b>",&text('emerge_install', "<tt>$cmd</tt>"),"</b><p>\n";
297 &additional_log('exec', undef, $cmd);
298 &open_execute_command(CMD, "$cmd 2>&1 </dev/null", 1);
300 print &html_escape($_);
301 if (/^\>\>\>\s+([^\/]+)\/([^0-9]+)-(\d\S+)\s+merged\./i) {
307 if ($?) { print "<b>$text{'emerge_failed'}</b><p>\n"; }
308 else { print "<b>$text{'emerge_ok'}</b><p>\n"; }