Révision bfe9c9e7
Ajouté par jim-p il y a plus de 9 ans
etc/inc/pkg-utils.inc | ||
---|---|---|
598 | 598 |
return $result; |
599 | 599 |
} |
600 | 600 |
|
601 |
|
|
601 | 602 |
function install_package($package, $pkg_info = "", $force_install = false) { |
602 | 603 |
global $g, $config, $static_output, $pkg_interface; |
603 | 604 |
|
... | ... | |
637 | 638 |
log_error(sprintf(gettext('Beginning package installation for %s .'), $pkg_info['name'])); |
638 | 639 |
$static_output .= sprintf(gettext("Beginning package installation for %s ."), $pkg_info['name']); |
639 | 640 |
update_status($static_output); |
641 |
|
|
640 | 642 |
/* fetch the package's configuration file */ |
641 |
if($pkg_info['config_file'] != "") { |
|
642 |
$static_output .= "\n" . gettext("Downloading package configuration file... "); |
|
643 |
update_output_window($static_output); |
|
644 |
pkg_debug(gettext("Downloading package configuration file...") . "\n"); |
|
645 |
$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1); |
|
646 |
download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto); |
|
647 |
if(!file_exists('/usr/local/pkg/' . $fetchto)) { |
|
648 |
pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n"); |
|
649 |
if($pkg_interface == "console") |
|
650 |
print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n"; |
|
651 |
else { |
|
652 |
$static_output .= gettext("failed!\n\nInstallation aborted.\n"); |
|
653 |
update_output_window($static_output); |
|
654 |
echo "<br />Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>"; |
|
655 |
} |
|
656 |
conf_mount_ro(); |
|
657 |
return -1; |
|
658 |
} |
|
659 |
$static_output .= gettext("done.") . "\n"; |
|
660 |
update_output_window($static_output); |
|
661 |
} |
|
643 |
pkg_fetch_config_file($package, $pkg_info); |
|
644 |
|
|
662 | 645 |
/* add package information to config.xml */ |
663 | 646 |
$pkgid = get_pkg_id($pkg_info['name']); |
664 | 647 |
$static_output .= gettext("Saving updated package information...") . " "; |
... | ... | |
761 | 744 |
} |
762 | 745 |
} |
763 | 746 |
} |
747 |
|
|
764 | 748 |
$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1); |
765 | 749 |
if(file_exists("/usr/local/pkg/" . $configfile)) { |
766 | 750 |
$static_output .= gettext("Loading package configuration... "); |
... | ... | |
784 | 768 |
$static_output .= gettext("done.") . "\n"; |
785 | 769 |
update_output_window($static_output); |
786 | 770 |
} |
787 |
/* download additional files */ |
|
788 |
if(is_array($pkg_config['additional_files_needed'])) { |
|
789 |
$static_output .= gettext("Additional files... "); |
|
790 |
$static_orig = $static_output; |
|
791 |
update_output_window($static_output); |
|
792 |
foreach($pkg_config['additional_files_needed'] as $afn) { |
|
793 |
$filename = get_filename_from_url($afn['item'][0]); |
|
794 |
if($afn['chmod'] <> "") |
|
795 |
$pkg_chmod = $afn['chmod']; |
|
796 |
else |
|
797 |
$pkg_chmod = ""; |
|
798 | 771 |
|
799 |
if($afn['prefix'] <> "") |
|
800 |
$prefix = $afn['prefix']; |
|
801 |
else |
|
802 |
$prefix = "/usr/local/pkg/"; |
|
772 |
pkg_fetch_additional_files($pkg, $pkg_info); |
|
803 | 773 |
|
804 |
if(!is_dir($prefix)) |
|
805 |
safe_mkdir($prefix); |
|
806 |
$static_output .= $filename . " "; |
|
807 |
update_output_window($static_output); |
|
808 |
if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) { |
|
809 |
$static_output .= "failed.\n"; |
|
810 |
@unlink($prefix . $filename); |
|
811 |
update_output_window($static_output); |
|
812 |
return false; |
|
813 |
} |
|
814 |
if(stristr($filename, ".tgz") <> "") { |
|
815 |
pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n"); |
|
816 |
$tarout = ""; |
|
817 |
exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout); |
|
818 |
pkg_debug(print_r($tarout, true) . "\n"); |
|
819 |
} |
|
820 |
if($pkg_chmod <> "") { |
|
821 |
pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n")); |
|
822 |
@chmod($prefix . $filename, $pkg_chmod); |
|
823 |
system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}"); |
|
824 |
} |
|
825 |
$static_output = $static_orig; |
|
826 |
update_output_window($static_output); |
|
827 |
} |
|
828 |
$static_output .= gettext("done.") . "\n"; |
|
829 |
update_output_window($static_output); |
|
830 |
} |
|
831 | 774 |
/* if a require exists, include it. this will |
832 | 775 |
* show us where an error exists in a package |
833 | 776 |
* instead of making us blindly guess |
... | ... | |
1488 | 1431 |
. '<a href="/pkg_mgr_settings.php">' . gettext("Package Manager Settings") . '</a>'; |
1489 | 1432 |
} |
1490 | 1433 |
|
1434 |
|
|
1435 |
function pkg_fetch_config_file($package, $pkg_info = "") { |
|
1436 |
global $g, $config, $static_output, $pkg_interface; |
|
1437 |
conf_mount_rw(); |
|
1438 |
|
|
1439 |
if(empty($pkg_info) or !is_array($pkg_info[$package])) { |
|
1440 |
$pkg_info = get_pkg_info(array($package)); |
|
1441 |
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array. |
|
1442 |
if (empty($pkg_info)) { |
|
1443 |
conf_mount_ro(); |
|
1444 |
return -1; |
|
1445 |
} |
|
1446 |
} |
|
1447 |
|
|
1448 |
/* fetch the package's configuration file */ |
|
1449 |
if($pkg_info['config_file'] != "") { |
|
1450 |
$static_output .= "\n" . gettext("Downloading package configuration file... "); |
|
1451 |
update_output_window($static_output); |
|
1452 |
pkg_debug(gettext("Downloading package configuration file...") . "\n"); |
|
1453 |
$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1); |
|
1454 |
download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto); |
|
1455 |
if(!file_exists('/usr/local/pkg/' . $fetchto)) { |
|
1456 |
pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n"); |
|
1457 |
if($pkg_interface == "console") |
|
1458 |
print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n"; |
|
1459 |
else { |
|
1460 |
$static_output .= gettext("failed!\n\nInstallation aborted.\n"); |
|
1461 |
update_output_window($static_output); |
|
1462 |
echo "<br />Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>"; |
|
1463 |
} |
|
1464 |
conf_mount_ro(); |
|
1465 |
return -1; |
|
1466 |
} |
|
1467 |
$static_output .= gettext("done.") . "\n"; |
|
1468 |
update_output_window($static_output); |
|
1469 |
} |
|
1470 |
conf_mount_ro(); |
|
1471 |
return true; |
|
1472 |
} |
|
1473 |
|
|
1474 |
|
|
1475 |
function pkg_fetch_additional_files($package, $pkg_info = "") { |
|
1476 |
global $g, $config, $static_output, $pkg_interface; |
|
1477 |
conf_mount_rw(); |
|
1478 |
|
|
1479 |
if(empty($pkg_info) or !is_array($pkg_info[$package])) { |
|
1480 |
$pkg_info = get_pkg_info(array($package)); |
|
1481 |
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array. |
|
1482 |
if (empty($pkg_info)) { |
|
1483 |
conf_mount_ro(); |
|
1484 |
return -1; |
|
1485 |
} |
|
1486 |
} |
|
1487 |
|
|
1488 |
$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1); |
|
1489 |
if(file_exists("/usr/local/pkg/" . $configfile)) { |
|
1490 |
$static_output .= gettext("Loading package configuration... "); |
|
1491 |
update_output_window($static_output); |
|
1492 |
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui"); |
|
1493 |
$static_output .= gettext("done.") . "\n"; |
|
1494 |
update_output_window($static_output); |
|
1495 |
/* download additional files */ |
|
1496 |
if(is_array($pkg_config['additional_files_needed'])) { |
|
1497 |
$static_output .= gettext("Additional files... "); |
|
1498 |
$static_orig = $static_output; |
|
1499 |
update_output_window($static_output); |
|
1500 |
foreach($pkg_config['additional_files_needed'] as $afn) { |
|
1501 |
$filename = get_filename_from_url($afn['item'][0]); |
|
1502 |
if($afn['chmod'] <> "") |
|
1503 |
$pkg_chmod = $afn['chmod']; |
|
1504 |
else |
|
1505 |
$pkg_chmod = ""; |
|
1506 |
|
|
1507 |
if($afn['prefix'] <> "") |
|
1508 |
$prefix = $afn['prefix']; |
|
1509 |
else |
|
1510 |
$prefix = "/usr/local/pkg/"; |
|
1511 |
|
|
1512 |
if(!is_dir($prefix)) |
|
1513 |
safe_mkdir($prefix); |
|
1514 |
$static_output .= $filename . " "; |
|
1515 |
update_output_window($static_output); |
|
1516 |
if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) { |
|
1517 |
$static_output .= "failed.\n"; |
|
1518 |
@unlink($prefix . $filename); |
|
1519 |
update_output_window($static_output); |
|
1520 |
return false; |
|
1521 |
} |
|
1522 |
if(stristr($filename, ".tgz") <> "") { |
|
1523 |
pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n"); |
|
1524 |
$tarout = ""; |
|
1525 |
exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout); |
|
1526 |
pkg_debug(print_r($tarout, true) . "\n"); |
|
1527 |
} |
|
1528 |
if($pkg_chmod <> "") { |
|
1529 |
pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n")); |
|
1530 |
@chmod($prefix . $filename, $pkg_chmod); |
|
1531 |
system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}"); |
|
1532 |
} |
|
1533 |
$static_output = $static_orig; |
|
1534 |
update_output_window($static_output); |
|
1535 |
} |
|
1536 |
$static_output .= gettext("done.") . "\n"; |
|
1537 |
update_output_window($static_output); |
|
1538 |
} |
|
1539 |
conf_mount_ro(); |
|
1540 |
return true; |
|
1541 |
} |
|
1542 |
} |
|
1543 |
|
|
1491 | 1544 |
?> |
Formats disponibles : Unified diff
Move the fetching of a package's config file and additional files to separate functions, and then have the "xml" package button perform these so that it is not only a redundant copy of the "pkg" reinstall button. This can help ensure a package files are in a known-good state before other actions are performed, in case the deinstall would fail or behave erratically due to other files being missing.