Revision 57a608c5
Added by Renato Botelho about 10 years ago
etc/inc/pkg-utils.inc | ||
---|---|---|
296 | 296 |
} |
297 | 297 |
} |
298 | 298 |
|
299 |
/* |
|
300 |
* pkg_fetch_recursive: Download and install a FreeBSD PBI package. This function provides output to |
|
301 |
* a progress bar and output window. |
|
302 |
*/ |
|
303 |
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = "") { |
|
304 |
global $static_output, $g, $config; |
|
305 |
|
|
306 |
// Clean up incoming filenames |
|
307 |
$filename = str_replace(" ", " ", $filename); |
|
308 |
$filename = str_replace("\n", " ", $filename); |
|
309 |
$filename = str_replace(" ", " ", $filename); |
|
310 |
|
|
311 |
$pkgs = explode(" ", $filename); |
|
312 |
foreach ($pkgs as $filename) { |
|
313 |
$filename = trim($filename); |
|
314 |
if ($g['platform'] == "nanobsd") { |
|
315 |
$pkgtmpdir = "/usr/bin/env PKG_TMPDIR=/root/ "; |
|
316 |
$pkgstagingdir = "/root/tmp"; |
|
317 |
if (!is_dir($pkgstagingdir)) { |
|
318 |
mkdir($pkgstagingdir); |
|
319 |
} |
|
320 |
$pkgstaging = "-o {$pkgstagingdir}/instmp.XXXXXX"; |
|
321 |
$fetchdir = $pkgstagingdir; |
|
322 |
} else { |
|
323 |
$fetchdir = $g['tmp_path']; |
|
324 |
} |
|
325 |
|
|
326 |
/* FreeBSD has no PBI's hosted, so fall back to our own URL for now. (Maybe fail to PC-BSD?) */ |
|
327 |
$rel = get_freebsd_version(); |
|
328 |
$priv_url = "https://files.pfsense.org/packages/{$rel}/All/"; |
|
329 |
if (empty($base_url)) { |
|
330 |
$base_url = $priv_url; |
|
331 |
} |
|
332 |
if (substr($base_url, -1) == "/") { |
|
333 |
$base_url = substr($base_url, 0, -1); |
|
334 |
} |
|
335 |
$fetchto = "{$fetchdir}/apkg_{$filename}"; |
|
336 |
$static_output .= "\n" . str_repeat(" ", $dependlevel * 2 + 1) . "Downloading {$base_url}/{$filename} ... "; |
|
337 |
if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto) !== true) { |
|
338 |
if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto) !== true) { |
|
339 |
$static_output .= " could not download from there or {$priv_url}/{$filename}.\n"; |
|
340 |
update_output_window($static_output); |
|
341 |
return false; |
|
342 |
} else if ($base_url == $priv_url) { |
|
343 |
$static_output .= " failed to download.\n"; |
|
344 |
update_output_window($static_output); |
|
345 |
return false; |
|
346 |
} else { |
|
347 |
$static_output .= " [{$osname} repository]\n"; |
|
348 |
update_output_window($static_output); |
|
349 |
} |
|
350 |
} |
|
351 |
$static_output .= " (extracting)\n"; |
|
352 |
update_output_window($static_output); |
|
353 |
|
|
354 |
$pkgaddout = ""; |
|
355 |
|
|
356 |
$no_checksig = ""; |
|
357 |
if (isset($config['system']['pkg_nochecksig'])) { |
|
358 |
$no_checksig = "--no-checksig"; |
|
359 |
} |
|
360 |
|
|
361 |
$result = exec("/usr/local/sbin/pbi_add " . $pkgstaging . " -f -v {$no_checksig} " . escapeshellarg($fetchto) . " 2>&1", $pkgaddout, $rc); |
|
362 |
pkg_debug($pkgname . " " . print_r($pkgaddout, true) . "\n"); |
|
363 |
if ($rc == 0) { |
|
364 |
$pbi_name = preg_replace('/\.pbi$/','',$filename); |
|
365 |
|
|
366 |
$gb = exec("/usr/local/sbin/pbi_info {$pbi_name} | /usr/bin/awk '/Prefix/ {print $2}'", $pbi_prefix); |
|
367 |
$pbi_prefix = $pbi_prefix[0]; |
|
368 |
|
|
369 |
$links = get_pbi_binaries(escapeshellarg($pbi_name)); |
|
370 |
foreach ($links as $link) { |
|
371 |
@unlink("/usr/local/{$link['link_name']}"); |
|
372 |
@symlink("{$link['target']}","/usr/local/{$link['link_name']}"); |
|
373 |
} |
|
374 |
|
|
375 |
$extra_links = array( |
|
376 |
array("target" => "bin", "link_name" => "sbin"), |
|
377 |
array("target" => "local/lib", "link_name" => "lib"), |
|
378 |
array("target" => "local/libexec", "link_name" => "libexec"), |
|
379 |
array("target" => "local/share", "link_name" => "share"), |
|
380 |
array("target" => "local/www", "link_name" => "www"), |
|
381 |
array("target" => "local/etc", "link_name" => "etc") |
|
382 |
); |
|
383 |
|
|
384 |
foreach ($extra_links as $link) { |
|
385 |
if (!file_exists($pbi_prefix . "/" . $link['target'])) { |
|
386 |
continue; |
|
387 |
} |
|
388 |
@rmdir("{$pbi_prefix}/{$link['link_name']}"); |
|
389 |
unlink_if_exists("{$pbi_prefix}/{$link['link_name']}"); |
|
390 |
@symlink("{$pbi_prefix}/{$link['target']}", "{$pbi_prefix}/{$link['link_name']}"); |
|
391 |
} |
|
392 |
pkg_debug("pbi_add successfully completed.\n"); |
|
393 |
} else { |
|
394 |
if (is_array($pkgaddout)) { |
|
395 |
foreach ($pkgaddout as $line) { |
|
396 |
$static_output .= " " . $line .= "\n"; |
|
397 |
} |
|
398 |
} |
|
399 |
|
|
400 |
update_output_window($static_output); |
|
401 |
pkg_debug("pbi_add failed.\n"); |
|
402 |
return false; |
|
403 |
} |
|
404 |
} |
|
405 |
return true; |
|
406 |
} |
|
407 |
|
|
408 | 299 |
function get_pbi_binaries($pbi) { |
409 | 300 |
$result = array(); |
410 | 301 |
|
Also available in: Unified diff
Remove unused function pkg_fetch_recursive()