FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/usr/local/bin/php -f <?php /* rc.initial.upgfromcdrom part of FreeNAS (http://freenas.org) Copyright (C) 2005-2009 Olivier Cochard-Labbe <olivier@freenas.org>. 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_once("config.inc"); require_once("functions.inc"); require_once("install.inc"); require_once("util.inc"); require_once("tui.inc"); // Default size of slice/partition 1 (used for OS) $part1size = $g_install['part1size_embedded']; // Get product information $productname = get_product_name(); // Display information $text = <<<EOD This will upgrade your current installation to the latest version. EOD; $result = tui_display_message_ex("{$productname} upgrade", $text, 70, 7); if (0 != $result) exit(0); // Search where the config file is installed if (0 != install_detect_installation("embedded", $devinfo)) { tui_wait_keypress("No 'embedded' installation detected!"); exit(0); } // Check partition size $minsector = floor((($part1size * 1000 * 1000) - (256 * 63 * 512)) / 512); $devsize = floor(($devinfo['size'] * 512) / 1024 / 1024); if ($devinfo['size'] < $minsector) { tui_wait_keypress("The size '{$devsize}MB' is too small. To upgrade, you need {$part1size}MB on the disk."); exit(0); } $result = tui_display_yesno("{$productname} has been detected on device '{$devinfo['device']}{$devinfo['partition']}'.\n\nIs this is correct?", 50, 7); if (0 != $result) exit(0); // Detect hardware $cdlist = get_cdrom_list(); $disklist = get_physical_disks_list(); if (0 == count($cdlist)) { tui_wait_keypress("Failed to detect any CDROM."); exit(0); } // Display installation medias $amenuitem = array(); foreach ($cdlist as $cdromk => $cdromv) { $menuitem = array(); $menuitem['tag'] = $cdromk; $menuitem['item'] = $cdromv['desc']; $amenuitem[] = $menuitem; } $result = tui_display_menu("Choose installation media", "Select CD/DVD drive for installation.", 60, 10, 6, $amenuitem, $cdrom); if (0 != $result) exit(0); if (install_mount_cd($cdrom)) { tui_wait_keypress("There was a problem while mounting the CDROM."); exit(0); } if (install_check_version("{$devinfo['device']}{$devinfo['partition']}")) { install_unmount_cd(); tui_wait_keypress("There was a problem while checking version."); exit(0); } if (install_backup_config("{$devinfo['device']}{$devinfo['partition']}")) { install_unmount_cd(); tui_wait_keypress("There was a problem during configuration file backup."); exit(0); } // Must install on ad0s1 if installed on partition 1, but install on ad0 if installed on ad0a. if ("s1a" === $devinfo['partition']) { $slice = preg_replace('/(s\d+).$/', '\1', $devinfo['partition']); if (install_dd_image("{$devinfo['device']}{$slice}")) { install_unmount_cd(); tui_wait_keypress("There was a problem while copying files."); exit(0); } } else { if (install_dd_image($devinfo['device'])) { install_unmount_cd(); tui_wait_keypress("There was a problem while copying files."); exit(0); } } if (install_restore_config("{$devinfo['device']}{$devinfo['partition']}")) { install_unmount_cd(); tui_wait_keypress("There was a problem while restoring configuration file."); exit(0); } install_unmount_cd(); // Display final message $text = <<<EOD {$productname} installed on device {$devinfo['device']}{$devinfo['partition']} has been upgraded. You can remove the CDROM and reboot the PC now. EOD; tui_wait_keypress($text); ?>