All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require("globals.inc"); require("guiconfig.inc"); // Handle other type of file systems if($_REQUEST['fstype']) $fstype = strtoupper($_REQUEST['fstype']); else $fstype = "UFS+S"; if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") { Header("Location: /index.php"); exit; } // Main switch dispatcher switch ($_REQUEST['state']) { case "quickeasyinstall": quickeasyinstall_gui(); break; case "update_installer_status": update_installer_status(); exit; default: installer_main(); } function write_out_pc_sysinstaller_config($disk) { global $fstype; $fd = fopen("/PCBSD/pc-sysinstall/examples/pfSense-install.cfg", "w"); if(!$fd) { return true; } $config = <</dev/null\n"); fwrite($fd, "/PCBSD/pc-sysinstall/pc-sysinstall -c /PCBSD/pc-sysinstall/examples/pfSense-install.cfg \n"); fwrite($fd, "chmod a+rx /usr/local/bin/after_installation_routines.sh\n"); fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n"); fwrite($fd, "mkdir /mnt/tmp\n"); fwrite($fd, "umount /mnt\n"); fwrite($fd, "touch /tmp/install_complete\n"); fclose($fd); exec("chmod a+rx /tmp/installer.sh"); mwexec_bg("sh /tmp/installer.sh"); } function installer_find_first_disk() { global $g, $fstype; $disk = `/PCBSD/pc-sysinstall/pc-sysinstall disk-list | head -n1 | cut -d':' -f1`; return $disk; } function update_installer_status() { global $g, $fstype; // Ensure status files exist if(!file_exists("/tmp/installer_installer_running")) touch("/tmp/installer_installer_running"); $status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`; $status = str_replace("\n", "\\n", $status); $status = str_replace("\n", "\\r", $status); echo "this.document.forms[0].installeroutput.value='$status';\n"; echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n"; // Find out installer progress $progress = "5"; if(strstr($status, "Running: dd")) $progress = "6"; if(strstr($status, "Running: gpart create -s GPT")) $progress = "7"; if(strstr($status, "Running: gpart bootcode")) $progress = "7"; if(strstr($status, "Running: newfs -U")) $progress = "8"; if(strstr($status, "Running: sync")) $progress = "9"; if(strstr($status, "/boot /mnt/boot")) $progress = "10"; if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT")) $progress = "11"; if(strstr($status, "/bin /mnt/bin")) $progress = "12"; if(strstr($status, "/conf /mnt/conf")) $progress = "15"; if(strstr($status, "/conf.default /mnt/conf.default")) $progress = "20"; if(strstr($status, "/dev /mnt/dev")) $progress = "25"; if(strstr($status, "/etc /mnt/etc")) $progress = "30"; if(strstr($status, "/home /mnt/home")) $progress = "35"; if(strstr($status, "/kernels /mnt/kernels")) $progress = "40"; if(strstr($status, "/libexec /mnt/libexec")) $progress = "50"; if(strstr($status, "/lib /mnt/lib")) $progress = "60"; if(strstr($status, "/root /mnt/root")) $progress = "70"; if(strstr($status, "/sbin /mnt/sbin")) $progress = "75"; if(strstr($status, "/sys /mnt/sys")) $progress = "80"; if(strstr($status, "/usr /mnt/usr")) $progress = "95"; if(strstr($status, "/usr /mnt/usr")) $progress = "90"; if(strstr($status, "/var /mnt/var")) $progress = "95"; if(strstr($status, "cap_mkdb /etc/login.conf")) $progress = "96"; if(strstr($status, "Setting hostname")) $progress = "97"; if(strstr($status, "umount -f /mnt")) $progress = "98"; if(strstr($status, "umount -f /mnt")) $progress = "99"; if(strstr($status, "Installation finished")) $progress = "100"; // Check for error and bail if we see one. if(stristr($status, "error")) { $error = true; echo "\$('installerrunning').innerHTML=' An error occurred. Aborting installation.'; "; echo "\$('progressbar').style.width='100%';\n"; unlink("/tmp/install_complete"); return; } $running_old = trim(file_get_contents("/tmp/installer_installer_running")); if($installer_running <> "running") { $ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'"); if($ps_running) { $running = "\$('installerrunning').innerHTML='
 Installer running ({$progress}% completed)...
'; "; if($running_old <> $running) { echo $running; file_put_contents("/tmp/installer_installer_running", "$running"); } } } if($progress) echo "\$('progressbar').style.width='{$progress}%';\n"; if(file_exists("/tmp/install_complete")) { echo "\$('installerrunning').innerHTML=' Installation completed. Please reboot to continue';\n"; unlink_if_exists("/tmp/installer.sh"); file_put_contents("/tmp/installer_installer_running", "finished"); } } function update_installer_status_win($status) { global $g, $fstype; echo ""; } function begin_quick_easy_install() { global $g, $fstype; if(file_exists("/tmp/install_complete")) return; unlink_if_exists("/tmp/install_complete"); $disk = installer_find_first_disk(); if(!$disk) { // XXX: hide progress bar $savemsg = gettext("Could not find a suitable disk for installation"); update_installer_status_win(gettext("Could not find a suitable disk for installation.")); return; } write_out_pc_sysinstaller_config($disk); update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk)); start_installation(); } function head_html() { global $g, $fstype; echo << EOF; } function body_html() { global $g, $fstype; $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; $pgtitle = "{$g['product_name']}: " . gettext("Installer"); include("head.inc"); echo << EOF; if($one_two) echo "

{$pgtitle}

"; if ($savemsg) print_info_box($savemsg); } function end_html() { global $g, $fstype; echo ""; echo ""; echo ""; } function template() { global $g, $fstype; head_html(); body_html(); echo <<
EOF; end_html(); } function quickeasyinstall_gui() { global $g, $fstype; head_html(); body_html(); echo ""; page_table_start(); echo <<
 Starting Installer... Please wait...


EOF; page_table_end(); end_html(); begin_quick_easy_install(); } function page_table_start() { global $g, $fstype; echo <<
{$g['product_name']} installer
EOF; } function page_table_end() { global $g, $fstype; echo <<
EOF; } function installer_main() { global $g, $fstype; if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) unlink("/tmp/.pc-sysinstall/pc-sysinstall.log"); head_html(); body_html(); // Only enable ZFS if this exists. The install will fail otherwise. if(file_exists("/boot/gptzfsboot")) $zfs_enabled = "or ZFS "; $disk = installer_find_first_disk(); if(!$disk) echo gettext("WARNING: Could not find any suitable disks for installation."); page_table_start(); echo <<
Welcome to the {$g['product_name']} PCSysInstaller!

This utility will install {$g['product_name']} to a hard disk, flash drive, etc.

Please select an installer option to begin:
Rescue config.xml

Install {$g['product_name']} using the UFS {$zfs_enabled} filesystem.

EOF; page_table_end(); end_html(); } ?>