diff options
author | Colin Smith <colin@pfsense.org> | 2005-06-06 01:53:22 +0000 |
---|---|---|
committer | Colin Smith <colin@pfsense.org> | 2005-06-06 01:53:22 +0000 |
commit | 6751a1a35e6c46b2593afd9b5c0c3a019df86bdc (patch) | |
tree | 3c419afe6a6cb1776bef39fffdc79d976af3efae /usr/local/www/pkg_mgr_install.php | |
parent | 22b0ed55ba31be3058e425d1512831b0fdedf902 (diff) | |
download | pfsense-6751a1a35e6c46b2593afd9b5c0c3a019df86bdc.zip pfsense-6751a1a35e6c46b2593afd9b5c0c3a019df86bdc.tar.gz |
Add pkg-utils based package installer.
Diffstat (limited to 'usr/local/www/pkg_mgr_install.php')
-rwxr-xr-x | usr/local/www/pkg_mgr_install.php | 414 |
1 files changed, 3 insertions, 411 deletions
diff --git a/usr/local/www/pkg_mgr_install.php b/usr/local/www/pkg_mgr_install.php index d5d894d..67dc1a2 100755 --- a/usr/local/www/pkg_mgr_install.php +++ b/usr/local/www/pkg_mgr_install.php @@ -30,23 +30,8 @@ */ require("guiconfig.inc"); -require("xmlparse_pkg.inc"); -require_once("pkg-utils.inc"); +require("pkg-utils.inc"); -conf_mount_rw(); - -if(!file_exists("/var/db/pkg")) - mkdir("/var/db/pkg"); - -/* /usr/local/pkg/ is where xml package files are stored. */ -make_dirs("/usr/local/pkg"); -/* /usr/local/pkg/pf is where custom php hook packages live to alter the rules when needed */ -make_dirs("/usr/local/pkg/pf"); -/* /usr/local/www/ext is where package links live for the left hand pane */ -make_dirs("/usr/local/www/ext"); - -$a_out = &$pkg_config['packages']; -$packages_to_install = Array(); $static_output = ""; $static_status = ""; $sendto = "output"; @@ -69,39 +54,6 @@ include("fbegin.inc"); <?php if ($savemsg) print_info_box($savemsg); ?> <?php - -if($_GET['showlog'] <> "") { - echo "<table>"; - echo "<tr><td>"; - echo "<pre>"; - // reopen and read log in - $fd = fopen("{$g['tmp_path']}/pkg_mgr.log", "r"); - $tmp = ""; - while(!feof($fd)) { - $tmp .= fread($fd,49); - } - fclose($fd); - echo $tmp; - echo "</pre>"; - echo "</td></tr>"; - echo "</table>"; - exit; -} - -/* - * open logging facility - */ -$fd_log = fopen("{$g['tmp_path']}/pkg_mgr.log", "w"); -if(!$fd_log) log_error("Warning, could not open {$g['tmp_path']}/pkg_mgr.log for writing"); -fwrite($fd_log, "Begin of Package Manager installation session.\n"); - -fetch_latest_pkg_config(); - -$pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs"); - -if(!$pkg_config['packages']) - print_info_box_np("Could not find any packages in pkg_config.xml"); - ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td> <ul id="tabnav"> @@ -116,21 +68,7 @@ if(!$pkg_config['packages']) <td> <!-- progress bar --> <center> - - <table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'> - <tr> - - <td background="bar_left.gif" height='15' width='5'> - </td> - <td> - <table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'><td background="bar_gray.gif" valign="top" align="left"><img src='bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'></td></table> - </td> - <td background="bar_right.gif" height='15' width='5'> - </td> - </tr> - </table> - - + <table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table> <br> <!-- status box --> <textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning package installation.</textarea> @@ -150,352 +88,10 @@ if(!$pkg_config['packages']) <?php - - -if($_GET['mode'] == "reinstallall") { - /* - * Loop through installed packages and if name matches - * push the package id onto array to reinstall - */ - $instpkgs = array(); - $output_static = ""; - $counter = 0; - if(is_array($pkg_config['packages']['package'])) - if(!is_string($instpkgs[0])) foreach($config['installedpackages']['package'] as $index => $instpkg) $instpkgs[] = $instpkg['name']; - foreach($pkg_config['packages']['package'] as $index => $available_package) { - if(in_array($available_package['name'], $instpkgs)) { - $packages_to_install[] = $index; - $output_static .= "Adding " . $package['name'] . " to installation array.\n"; - update_output_window($output_static); - fwrite($fd_log, "Adding (" . $counter . ") " . $package['name'] . " to package installation array.\n" . $status); - } - } -} else { - /* - * Push the desired package id onto the install packages array - */ - fwrite($fd_log, "Single package installation started.\n"); - $packages_to_install[] = $_GET['id']; -} - /* * Loop through packages_to_install, installing needed packages */ -foreach ($packages_to_install as $id) { - - fwrite($fd_log, "Begin package ${id}\n"); - - $pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs"); - - /* - * install the package - */ - - // Ensure directories are in place for pkg_add. - safe_mkdir("{$g['www_path']}/ext/Services", 0755); - safe_mkdir("{$g['www_path']}/ext/System", 0755); - safe_mkdir("{$g['www_path']}/ext/Interfaces", 0755); - safe_mkdir("{$g['www_path']}/ext/Firewall", 0755); - safe_mkdir("{$g['www_path']}/ext/VPN", 0755); - safe_mkdir("{$g['www_path']}/ext/Status", 0755); - safe_mkdir("{$g['www_path']}/ext/Diagnostics", 0755); - safe_mkdir("/usr/local/pkg", 0755); - - $a_out = &$pkg_config['packages']['package']; - - if($pkg_config['packages']['package'][$id]['verifyinstalledpkg'] <> "") - $package_to_verify = $pkg_config['packages']['package'][$id]['verifyinstalledpkg']; - else - $package_to_verify = $pkg_config['packages']['package'][$id]['name']; - - $pkgent = array(); - $pkgent['name'] = $pkg_config['packages']['package'][$id]['name']; - $pkgent['descr'] = $pkg_config['packages']['package'][$id]['descr']; - $pkgent['category'] = $pkg_config['packages']['package'][$id]['category']; - - $pkgent['version'] = $pkg_config['packages']['package'][$id]['version']; - - $pkgent['depends_on_package'] = $a_out[$id]['depends_on_package']; - $pkgent['depends_on_package_base_url'] = $a_out[$id]['depends_on_package_base_url']; - $pkgent['pfsense_package'] = $a_out[$id]['pfsense_package']; - $pkgent['pfsense_package_base_url'] = $a_out[$id]['pfsense_package_base_url']; - $pkgent['configurationfile'] = $a_out[$id]['configurationfile']; - $pkgent['exclude_dependency'] = $a_out[$id]['exclude_dependency']; - if($pkg_config['packages']['package'][$id]['logging']) { - // logging facilities. - $pkgent['logging']['facility'] = $pkg_config['packages']['package'][$id]['logging']['facility']; - $pkgent['logging']['logfile_name'] = $pkg_config['packages']['package'][$id]['logging']['logfile_name']; - mwexec("/usr/sbin/clog -i -s 32768 {$g['varlog_path']}" . $pkgent['logging']['logfile_name']); - chmod($g['varlog_path'] . $pkgent['logging']['logfile_name'], 0600); - fwrite($fd_log, "Adding text to file /etc/syslog.conf\n"); - add_text_to_file("/etc/syslog.conf", $pkgent['logging']['facilityname'] . "\t\t\t" . $pkgent['logging']['logfilename']); - mwexec("/usr/bin/killall -HUP syslogd"); - } - $a_out = &$config['packages']['package']; // save item to installedpkgs - fwrite($fd_log, "Begining (" . $id. ") " . $pkgent['name'] . " package installation.\n" . $status); - - log_error("Begining (" . $id. ") " . $pkgent['name'] . " package installation."); - $static_status = "Beginning package installation for " . $pkgent['name'] . "..."; - update_status($static_status); - - if($pkg_config['packages']['package'][$id]['config_file'] <> "") { - $static_output .= "Downloading package configuration file... "; - download_file_with_progress_bar($pkg_config['packages']['package'][$id]['config_file'], "/usr/local/pkg/" . substr(strrchr($pkg_config['packages']['package'][$id]['config_file'], '/'), 1)); - fwrite($fd_log, "Downloading configuration file " . $pkg_config['packages']['package'][$id]['config_file'] . "...\n"); - if(!file_exists("/usr/local/pkg/" . substr(strrchr($pkg_config['packages']['package'][$id]['config_file'], '/'), 1))) { - fwrite($fd_log, "ERROR! Could not fetch " . $pkg_config['packages']['package'][$id]['config_file']); - $static_output .= "failed!\n\nInstallation aborted."; - update_output_window($static_output); - echo "<br>Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>"; - exit; - } - $static_output .= "done.\n"; - update_output_window($static_output); - } - - update_status("Downloading and installing " . $pkgent['name'] . " and its dependencies."); - fwrite($fd_log, "Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . "...\n"); - - /* - * Open a /tmp/y file which will basically tell the - * pkg_delete script to delete users and such if it asks. - */ - $fd = fopen("{$g['tmp_path']}/y", "w"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fwrite($fd, "y\n"); - fclose($fd); - - /* This directive is not yet used. - if ($pkgent['pfsense_package_base_url'] <> "") { - fwrite($fd_log, "Executing: cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package'] . "\n" . $text); - $text = exec_command_and_return_text("cd {$g['tmp_path']}/ && cat {$g['tmp_path']}/y | /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package']); - update_output_window($text); - } - */ - - if ($pkgent['depends_on_package_base_url'] <> "") { - update_status("Installing " . $pkgent['name'] . " and its dependencies."); - $static_output .= "Downloading " . $pkgent['name'] . " and its dependencies... "; - $static_orig = $static_output; - $static_output .= "\n"; - update_output_window($static_output); - exec("ls /var/db/pkg", $is_installed); - $pkg_installed = false; - if(isset($pkg_config['packages']['package'][$id]['skip_install_checks'])) $pkg_installed = true; - foreach($is_installed as $is_inst) { - if($is_inst == $pkgent['name'] . '-' . $pkgent['version']) { - $pkg_installed = true; - break; - } - } - if($pkg_installed == false) pkg_fetch_recursive($pkgent['name'] . "-" . $pkgent['version'], $pkgent['depends_on_package'], 0, $pkgent['depends_on_package_base_url']); - $static_output = $static_orig . "done.\n"; - update_output_window($static_output); - } - - if ($pkgent['depends_on_package_base_url'] <> "" or $pkgent['pfsense_package_base_url'] <> "") { - $static_output .= "Checking for successful package installation... "; - update_output_window($static_output); - if($pkg_installed == false) { - exec("ls /var/db/pkg", $is_installed); - foreach($is_installed as $is_inst) { - if($is_inst == $pkgent['name'] . '-' . $pkgent['version']) { - $pkg_installed = true; - break; - } - } - } - fwrite($fd_log, $is_installed[0] . "\n"); - if($pkg_installed == true) { - $static_output .= "done.\n"; - update_output_window($static_output); - fwrite($fd_log, "pkg_add successfully completed.\n"); - } else { - $static_output .= "failed!\n\nInstallation aborted."; - update_output_window($static_output); - fwrite($fd_log, "Package WAS NOT installed properly.\n"); - fclose($fd_log); -/* - * keep progressbar visible - - echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>"; - echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>"; - */ - sleep(1); - die; - } - } - - $config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']); - - $pkgid = get_pkg_id($pkgent['name']); - - if(!$_GET['mode'] == "reinstallall") { - $static_output .= "Saving updated package information... "; - update_output_window($static_output); - if($pkgid == -1) { - $config['installedpackages']['package'][] = $pkgent; - $changedesc = "Installed {$pkgent['name']} package."; - $to_output = "done.\n"; - } else { - $config['installedpackages']['package'][$pkgid] = $pkgent; - $changedesc = "Overwrote previous installation of {$pkgent['name']}."; - $to_output = "overwrite!\n"; - } - write_config($changedesc); - conf_mount_rw(); - $static_output .= $to_output; - update_output_window($static_output); - } - - $name = $pkgent['name']; - - update_status("Finishing package installation..."); - - /* - * parse the config file for this package and install neededtext items. - * - */ - if(file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) { - $package_conf = parse_xml_config_pkg("/usr/local/pkg/" . $pkgent['name'] . ".xml", "packagegui"); - if($package_conf['modify_system']['item'] <> "") { - $static_output .= "Modifying system files... "; - update_output_window($static_output); - foreach ($package_conf['modify_system']['item'] as $ms) { - if($ms['textneeded']) { - add_text_to_file($ms['modifyfilename'],$ms['textneeded']); - } - } - $static_output .= "done.\n"; - update_output_window($static_output); - } - - /* - * fetch additional files needed for package if defined - * and uncompress if needed. - */ - if ($package_conf['additional_files_needed'] <> "") { - $static_output .= "Downloading additional files needed for " . $pkgent['name'] . "... "; - update_output_window($static_output); - $i = 0; - $afn_count = count($package_conf['additional_files_needed']) -1; - foreach($package_conf['additional_files_needed'] as $afn) { - $filename = get_filename_from_url($afn['item'][0]); - fwrite($fd_log, "Downloading additional files needed for package " . $filename . "...\n"); - if ($i == $afn_count) { - $static_orig = $static_output . $filename . ".\n"; - } else { - $static_orig = $static_output . $filename . ", "; - } - $static_output .= $filename . " "; - update_output_window($static_output); - $prefix = "/usr/local/pkg/"; - $pkg_chmod = ""; - if($afn['chmod'] <> "") - $pkg_chmod = $afn['chmod']; - if($afn['prefix'] <> "") - $prefix = $afn['prefix']; - download_file_with_progress_bar($afn['item'][0], $prefix . $filename); - $static_output = $static_orig; - update_output_window($static_output); - if(stristr($filename, ".tgz") <> "") { - update_status("Extracting tgz archive to -C for " . $filename); - fwrite($fd_log, "Extracting tgz archive to -C for " . $filename . " ...\n"); - system("/usr/bin/tar xzvf " . $prefix . $filename . " -C / >/dev/null 2>&1"); - } - if($pkg_chmod <> "") { - fwrite($fd_log, "Changing file mode for {$pkg_chmod} {$prefix}{$filename}\n"); - chmod($prefix . $filename, $pkg_chmod); - system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}"); - } - $i++; - } - } - - /* - * loop through menu installation items - * installing multiple items if need be. - */ - if(is_array($package_conf['menu'])) { - $static_output .= "Installing menu items... "; - update_output_window($static_output); - foreach ($package_conf['menu'] as $menu) { - // install menu item into the ext folder - fwrite($fd_log, "Adding menu option to " . $menu['section'] . "/" . $menu['name'] . "\n"); - $fd = fopen("{$g['www_path']}/ext/" . $menu['section'] . "/" . $menu['name'] , "w"); - if($menu['url'] <> "") { - // override $myurl for script. - $toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n"; - $error_message = ""; - if(php_check_syntax($toeval, $error_message) == false) - eval($toeval); - // eval url so that above $myurl item can be processed if need be. - $urltmp = $menu['url']; - $toeval = "\$url = \"" . $urltmp . "\"; \n"; - if(php_check_syntax($toeval, $error_message) == false) - eval($toeval); - fwrite($fd, $url . "\n"); - } else { - $xml = ""; - if(stristr($menu['configfile'],".xml") == "") $xml = ".xml"; - fwrite($fd, "/pkg.php?xml=" . $menu['configfile'] . $xml . "\n"); - } - fclose($fd); - } - $static_output .= "done.\n"; - update_output_window($static_output); - } - } else { - update_output_window("WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n"); - fwrite($fd_log, "WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n"); - } - fwrite($fd_log, "End of Package Manager installation session.\n"); - - /* return dependency list to output later. - $command = "TODELETE=`ls /var/db/pkg | grep " . $name . "` && /usr/sbin/pkg_info -r \$TODELETE | grep Dependency: | cut -d\" \" -f2"; - $dependencies = exec_command_and_return_text($command); - if($dependencies == "") - fwrite($fd_log, "Installed package " . $name); - else - fwrite($fd_log, "Installed package " . $name . " and the following dependencies:\n" . $dependencies); - */ - - if($package_conf['custom_php_install_command'] <> "") { - $static_output .= "Executing post install commands... "; - update_output_window($static_output); - if($package_conf['custom_php_global_functions'] <> "") - if(php_check_syntax($package_conf['custom_php_global_functions'], $error_message) == false) - eval($package_conf['custom_php_global_functions']); - fwrite($fd_log, "Executing post install commands...\n"); - $error_message = ""; - if($package_conf['custom_php_command_before_form'] <> "") - if(php_check_syntax($package_conf['custom_php_command_before_form'], $error_message) == false) - eval($package_conf['custom_php_command_before_form']); - if(php_check_syntax($package_conf['custom_php_install_command'], $error_message) == false) - eval($package_conf['custom_php_install_command']); - $static_output .= "done.\n"; - update_output_window($static_output); - } - update_status("Package installation completed."); - $static_output .= "\nPackage installation successful.\n"; - update_output_window($static_output); - fwrite($fd_log, "Package installation completed.\n"); - log_error("Package " . $pkgent['name'] . " installation completed successfully.\n"); - fwrite($fd_log, "Status window output:\n" . $static_output); -} +install_package($_GET['id']); // Delete all temporary package tarballs and staging areas. unlink_if_exists("/tmp/apkg_*"); @@ -507,10 +103,6 @@ fclose($fd_log); echo "<p><center>Installation completed. Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>"; -/* - * keep progressbar visible echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>"; -*/ -conf_mount_ro(); ?> |