Revision 669e1adb
Added by Bill Marquette about 20 years ago
etc/inc/pkg-utils.inc | ||
---|---|---|
212 | 212 |
* sync_package($pkg_name, $sync_depends = true, $show_message = false) Force a package to setup its configuration and rc.d files. |
213 | 213 |
*/ |
214 | 214 |
function sync_package($pkg_name, $sync_depends = true, $show_message = false) { |
215 |
global $config;
|
|
215 |
global $config;
|
|
216 | 216 |
|
217 |
if(!file_exists("/usr/local/pkg")) mwexec("/bin/mkdir -p /usr/local/pkg/pf"); |
|
218 |
if(!$config['installedpackages']['package']) return; |
|
219 |
if(!is_numeric($pkg_name)) { |
|
220 |
$pkg_id = get_pkg_id($pkg_name); |
|
221 |
if($pkg_id == -1) return -1; // This package doesn't really exist - exit the function. |
|
222 |
} else { |
|
223 |
$pkg_id = $pkg_name; |
|
224 |
if(!isset($config['installedpackages']['package'][$pkg_id])) |
|
225 |
return; // No package belongs to the pkg_id passed to this function. |
|
226 |
} |
|
227 |
$package = $config['installedpackages']['package'][$pkg_id]; |
|
228 |
if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) { |
|
229 |
file_notice($package['name'], "The {$package['name']} package is missing its configuration file and must be reinstalled.", "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1); |
|
230 |
} else { |
|
231 |
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui"); |
|
232 |
if(isset($pkg_config['nosync'])) continue; |
|
233 |
if($pkg['custom_php_global_functions'] <> "") |
|
234 |
eval($pkg['custom_php_global_functions']); |
|
235 |
if($pkg_config['custom_php_resync_config_command'] <> "") |
|
236 |
eval($pkg_config['custom_php_resync_config_command']); |
|
237 |
if($sync_depends == true) { |
|
238 |
$depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking. |
|
239 |
if(is_array($depends)) { |
|
240 |
foreach($depends as $item) { |
|
217 |
if(!file_exists("/usr/local/pkg")) mwexec("/bin/mkdir -p /usr/local/pkg/pf"); |
|
218 |
if(!$config['installedpackages']['package']) return; |
|
219 |
if(!is_numeric($pkg_name)) { |
|
220 |
$pkg_id = get_pkg_id($pkg_name); |
|
221 |
if($pkg_id == -1) return -1; // This package doesn't really exist - exit the function. |
|
222 |
} else { |
|
223 |
$pkg_id = $pkg_name; |
|
224 |
if(!isset($config['installedpackages']['package'][$pkg_id])) |
|
225 |
return; // No package belongs to the pkg_id passed to this function. |
|
226 |
} |
|
227 |
$package = $config['installedpackages']['package'][$pkg_id]; |
|
228 |
if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) { |
|
229 |
file_notice($package['name'], "The {$package['name']} package is missing its configuration file and must be reinstalled.", "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1); |
|
230 |
} else { |
|
231 |
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui"); |
|
232 |
/* XXX: Zend complains about the next line "Wrong break depth" |
|
233 |
* The code is obviously wrong, but I'm not sure what it's supposed to do? |
|
234 |
*/ |
|
235 |
if(isset($pkg_config['nosync'])) continue; |
|
236 |
if($pkg['custom_php_global_functions'] <> "") |
|
237 |
eval($pkg['custom_php_global_functions']); |
|
238 |
if($pkg_config['custom_php_resync_config_command'] <> "") |
|
239 |
eval($pkg_config['custom_php_resync_config_command']); |
|
240 |
if($sync_depends == true) { |
|
241 |
$depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking. |
|
242 |
if(is_array($depends)) { |
|
243 |
foreach($depends as $item) { |
|
241 | 244 |
if(!file_exists("/usr/local/pkg" . $item)) { |
242 | 245 |
file_notice($package['name'], "The {$package['name']} package is missing required dependencies and must be reinstalled.", "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1); |
243 | 246 |
} else { |
244 |
$item_config = parse_xml_config_pkg("/usr/local/pkg/" . $item, "packagegui");
|
|
245 |
if(isset($item_config['nosync'])) continue;
|
|
246 |
if($item_config['custom_php_command_before_form'] <> "") {
|
|
247 |
eval($item_config['custom_php_command_before_form']);
|
|
248 |
}
|
|
249 |
if($item_config['custom_php_resync_config_command'] <> "") {
|
|
250 |
eval($item_config['custom_php_resync_config_command']);
|
|
251 |
}
|
|
252 |
if($show_message == true) print " " . $item_config['name'];
|
|
253 |
}
|
|
254 |
}
|
|
255 |
}
|
|
256 |
}
|
|
257 |
}
|
|
247 |
$item_config = parse_xml_config_pkg("/usr/local/pkg/" . $item, "packagegui");
|
|
248 |
if(isset($item_config['nosync'])) continue;
|
|
249 |
if($item_config['custom_php_command_before_form'] <> "") {
|
|
250 |
eval($item_config['custom_php_command_before_form']);
|
|
251 |
}
|
|
252 |
if($item_config['custom_php_resync_config_command'] <> "") {
|
|
253 |
eval($item_config['custom_php_resync_config_command']);
|
|
254 |
}
|
|
255 |
if($show_message == true) print " " . $item_config['name'];
|
|
256 |
}
|
|
257 |
}
|
|
258 |
}
|
|
259 |
}
|
|
260 |
}
|
|
258 | 261 |
} |
259 | 262 |
|
260 | 263 |
/* |
... | ... | |
264 | 267 |
* XXX: This function needs to return where a pkg_add fails. Our current error messages aren't very descriptive. |
265 | 268 |
*/ |
266 | 269 |
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = 'http://ftp2.freebsd.org/pub/FreeBSD/ports/i386/packages-5.4-release/Latest') { |
267 |
global $pkgent, $static_status, $static_output, $g, $pkg_interface, $fd_log;
|
|
270 |
global $pkgent, $static_output, $g, $fd_log;
|
|
268 | 271 |
$pkg_extension = strrchr($filename, '.'); |
269 | 272 |
$static_output .= "\n" . str_repeat(" ", $dependlevel * 2) . $pkgname . " "; |
270 | 273 |
$fetchto = "/tmp/apkg_" . $pkgname . $pkg_extension; |
... | ... | |
275 | 278 |
$raw_depends_list = array_values(preg_grep("/\@pkgdep/", $slaveout)); |
276 | 279 |
if($raw_depends_list != "") { |
277 | 280 |
if($pkgent['exclude_dependency'] != "") |
278 |
$raw_depends_list = array_values(preg_grep($pkent['exclude_dependency'], PREG_GREP_INVERT)); |
|
281 |
$raw_depends_list = array_values(preg_grep($pkgent['exclude_dependency'], PREG_GREP_INVERT));
|
|
279 | 282 |
foreach($raw_depends_list as $adepend) { |
280 | 283 |
$working_depend = explode(" ", $adepend); |
281 | 284 |
//$working_depend = explode("-", $working_depend[1]); |
... | ... | |
295 | 298 |
} |
296 | 299 |
|
297 | 300 |
function download_file_with_progress_bar($url_file, $destination_file) { |
298 |
global $ch, $fout, $file_size, $downloaded, $counter, $pkg_interface;
|
|
301 |
global $ch, $fout, $file_size, $downloaded, $pkg_interface; |
|
299 | 302 |
$file_size = 1; |
300 | 303 |
$downloaded = 1; |
301 | 304 |
/* open destination file */ |
... | ... | |
320 | 323 |
} |
321 | 324 |
|
322 | 325 |
function read_header($ch, $string) { |
323 |
global $file_size, $ch, $fout;
|
|
326 |
global $file_size, $fout; |
|
324 | 327 |
$length = strlen($string); |
325 | 328 |
ereg("(Content-Length:) (.*)", $string, $regs); |
326 | 329 |
if($regs[2] <> "") { |
... | ... | |
330 | 333 |
} |
331 | 334 |
|
332 | 335 |
function read_body($ch, $string) { |
333 |
global $fout, $file_size, $downloaded, $counter, $sendto, $static_output, $lastseen, $pkg_interface;
|
|
336 |
global $fout, $file_size, $downloaded, $sendto, $static_status, $static_output, $lastseen, $pkg_interface;
|
|
334 | 337 |
$length = strlen($string); |
335 | 338 |
$downloaded += intval($length); |
336 | 339 |
$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); |
... | ... | |
354 | 357 |
global $g, $config, $pkg_interface, $fd_log, $static_output; |
355 | 358 |
/* open logfiles and begin installation */ |
356 | 359 |
if(!$fd_log) { |
357 |
if(!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$pkg}.log", "w")) {
|
|
360 |
if(!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$package}.log", "w")) {
|
|
358 | 361 |
update_output_window("Warning, could not open log for writing."); |
359 | 362 |
} |
360 | 363 |
} |
... | ... | |
801 | 804 |
$pkgdb = get_pkg_db(); |
802 | 805 |
if(!$pkg_info) $pkg_info = get_pkg_sizes($pkg); |
803 | 806 |
foreach($pkg as $apkg) { |
804 |
$size = 0; |
|
805 | 807 |
if(!$pkg_info[$apkg]) continue; |
806 | 808 |
$toreturn[$apkg] = expand_to_bytes(walk_depend(array($pkg_info[$apkg]), $pkgdb)); |
807 | 809 |
} |
Also available in: Unified diff
Various code cleanups and a few actual bugfixes courtesy of Zend