2 # Functions for slackware package management
4 $package_dir = "/var/log/packages";
5 %class_map = ( 'a', 'Base Slackware system',
6 'ap', 'Linux applications',
7 'd', 'Program development',
9 'extra', 'Extra Slackware packages',
10 'f', 'FAQs, howtos, and documentation',
11 'gnome', 'GNOME desktop and programs',
12 'k', 'Linux kernel source',
13 'kde', 'KDE desktop and programs',
14 'kdei', 'Language support of KDE',
17 'pasture', 'Software put to pasture',
19 'testing', 'Software in testing',
22 'xap', 'X applications',
23 'y', 'Classic BSD console games' );
25 chop($system_arch = `uname -m`);
27 sub validate_package_system
29 return -d &translate_filename($package_dir) ? undef :
30 &text('slack_edir', "<tt>$package_dir</tt>");
33 # list_packages([package]*)
34 # Fills the array %packages with a list of all packages
37 local ($i, $f, @list);
39 opendir(DIR, &translate_filename($package_dir));
40 local @list = @_ ? @_ : grep { !/^\./ } readdir(DIR);
43 $packages{$i,'name'} = $f;
44 $packages{$i,'class'} = $text{'slack_unclass'};
45 &open_tempfile(PKG, "$package_dir/$f");
47 if (/^PACKAGE LOCATION:\s+disk([a-z]+)\d+/i ||
48 /^PACKAGE LOCATION:\s+\S+\/([a-z]+)\/[^\/]+$/i) {
49 $packages{$i,'class'} = $class_map{$1} ||
50 $text{'slack_unclass'};
52 elsif (/^PACKAGE DESCRIPTION:/i) {
54 $desc =~ s/^\S+:\s+//;
56 $packages{$i,'desc'} = $desc;
66 # package_info(package)
67 # Returns an array of package information in the order
68 # name, class, description, arch, version, vendor, installtime
71 local @rv = ( $_[0], $text{'slack_unclass'}, $text{'slack_unknown'},
72 $system_arch, $text{'slack_unknown'}, "Slackware" );
73 local @st = stat(&translate_filename("$package_dir/$_[0]"));
74 $rv[6] = ctime($st[9]);
75 &open_readfile(PKG, "$package_dir/$_[0]");
77 if (/^PACKAGE LOCATION:\s+disk([a-z]+)\d+/i) {
78 $rv[1] = $class_map{$1};
80 elsif (/^PACKAGE DESCRIPTION:/i) {
83 last if (/^FILE LIST/i);
85 if (!$rv[2] && /([0-9][0-9\.]*)/) {
97 # check_files(package)
98 # Fills in the %files array with information about the files belonging
99 # to some package. Values in %files are path type user group mode size error
104 &open_readfile(PKG, "$package_dir/$_[0]");
106 last if (/^FILE LIST:/i);
108 while($file = <PKG>) {
110 next if ($file eq "./");
112 local $real = &translate_filename($file);
113 $files{$i,'path'} = $file;
114 local @st = stat($real);
116 $files{$i,'type'} = -l $real ? 3 :
118 $files{$i,'user'} = getpwuid($st[4]);
119 $files{$i,'group'} = getgrgid($st[5]);
120 $files{$i,'mode'} = sprintf "%o", $st[2] & 07777;
121 $files{$i,'size'} = $st[7];
122 $files{$i,'link'} = readlink($file);
125 $files{$i,'type'} = $file =~ /\// ? 1 : 0;
126 $files{$i,'user'} = $files{$i,'group'} =
127 $files{$i,'mode'} = $files{$i,'size'} = $text{'slack_unknown'};
128 $files{$i,'error'} = $text{'slack_missing'};
135 # package_files(package)
136 # Returns a list of all files in some package
141 &open_readfile(PKG, "$package_dir/$_[0]");
143 last if (/^FILE LIST:/i);
145 while(my $file = <PKG>) {
147 next if ($file eq "./");
155 # installed_file(file)
156 # Given a filename, fills %file with details of the given file and returns 1.
157 # If the file is not known to the package system, returns 0
158 # Usable values in %file are path type user group mode size packages
161 local ($f, $file, @pkgin);
162 opendir(DIR, &translate_filename($package_dir));
163 while($f = readdir(DIR)) {
164 next if ($f =~ /^\./);
165 &open_readfile(PKG, "$package_dir/$f");
167 last if (/^FILE LIST:/);
169 while($file = <PKG>) {
170 next if ($file eq "./");
171 $file =~ s/[\/\r\n]+$//;
173 if ($_[0] eq $file) {
183 local $real = &translate_filename($_[0]);
184 local @st = stat($real);
185 $file{'path'} = $_[0];
186 $file{'type'} = -l $real ? 3 :
188 $file{'user'} = getpwuid($st[4]);
189 $file{'group'} = getgrgid($st[5]);
190 $file{'mode'} = sprintf "%o", $st[2] & 07777;
191 $file{'size'} = $st[7];
192 $file{'link'} = readlink($real);
193 $file{'packages'} = join(" ", @pkgin);
205 local $qm = quotemeta($_[0]);
206 &open_execute_command(TAR, "gunzip -c $qm | tar tf - 2>&1", 1, 1);
208 $count++ if (/^[^\/\s]\S+/);
211 return $count < 2 ? 0 : 1;
214 # file_packages(file)
215 # Returns a list of all packages in the given file, in the form
216 # package description
219 if ($_[0] !~ /^(.*)\/(([^\/]+)(\.tgz|\.tar\.gz))$/) {
220 return "$_[0] $text{'slack_unknown'}";
222 local ($dir, $file, $base) = ($1, $2, $3);
224 opendir(DIR, &translate_filename($dir));
225 while($f = readdir(DIR)) {
226 if ($f =~ /^disk\S+\d+$/ || $f eq 'package_descriptions') {
227 # found the slackware disk file
228 $diskfile = "$dir/$f";
233 return "$base $text{'slack_unknown'}" if (!$diskfile);
237 &open_readfile(DISK, $diskfile);
239 if (/^$base:\s*(.*)/) {
245 return $desc ? "$base $desc" : "$base $text{'slack_unknown'}";
248 # install_options(file, package)
249 # Outputs HTML for choosing install options
252 print &ui_table_row($text{'slack_root'},
253 &ui_textbox("root", "/", 50)." ".
254 &file_chooser_button("root", 1), 3);
257 # install_package(file, package)
258 # Installs the package in the given file, with options from %in
261 local $in = $_[2] ? $_[2] : \%in;
262 return $text{'slack_eroot'} if (!-d $in->{'root'});
263 $ENV{'ROOT'} = $in->{'root'};
265 local $qm = quotemeta($_[0]);
266 if (&has_command("upgradepkg") &&
267 -r &translate_filename("$package_dir/$_[1]")) {
268 # Try to upgrade properly
269 $out = &backquote_logged("upgradepkg $qm 2>&1");
273 $out = &backquote_logged("installpkg $qm 2>&1");
276 return "<pre>$out</pre>";
281 # delete_package(package)
282 # Totally remove some package
285 local $qm = quotemeta($_[0]);
286 local $out = &backquote_logged("removepkg $qm 2>&1");
287 if ($?) { return "<pre>$out</pre>"; }
293 return $text{'slack_manager'};
298 return "installpkg removepkg";