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://www.freenas.org) Copyright (C) 2005-2007 Olivier Cochard-Labbé <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. */ /* parse the configuration and include all functions used below */ require_once("config.inc"); require_once("functions.inc"); require_once("install.inc"); /* Get product information */ $productname = get_product_name(); $fp = fopen('php://stdin', 'r'); $cdlist = get_cdrom_list(); $disklist = get_physical_disks_list(); /* Search where the config file is installed*/ $not_found=1; $disks = explode(" ", trim(preg_replace("/kern.disks: /", "", exec("/sbin/sysctl kern.disks")))); foreach ($disks as $mountdisk) { /* skip mfs mounted filesystems */ if (strstr($mountdisk, "md")) continue; /* Search on slice 1 for OS installed on disk with install script*/ if (mwexec("/sbin/mount -r /dev/{$mountdisk}s1 {$g['cf_path']}") == 0) { if (file_exists("{$g['cf_conf_path']}/config.xml")) { /* found it */ $cfgdevice = $mountdisk; $cfgpartition = $cfgdevice . "s1"; $cfgfstype = "ufs"; $slice=1; $not_found=0; } mwexec("/sbin/umount -f {$g['cf_path']}"); if ($cfgdevice) break; } /* Search on partition 'a' for OS IMG image written on disk */ if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) { if (file_exists("{$g['cf_conf_path']}/config.xml")) { /* found it */ $cfgdevice = $mountdisk; $cfgpartition = $cfgdevice . "a"; $cfgfstype = "ufs"; $slice=0; $not_found=0; } mwexec("/sbin/umount -f {$g['cf_path']}"); if ($cfgdevice) break; } } if ($not_found) { echo "No configuration found!\n"; exit(0); } echo "{$productname} upgrade from CDROM\n"; echo "\nHere is the list of detected CDROM:\n"; foreach ($cdlist as $cdromk =>$cdromv) { echo "$cdromk (desc: {$cdromv['desc']})\n"; } do { echo "\nEnter the name of the CD-ROM drive: "; $cdrom = chop(fgets($fp)); if ($cdrom === "") { exit(0); } } while (!is_validaliasname($cdrom)); echo "\nHere is the name of disk where detected FreeNAS Installation:\n"; echo "$cfgdevice\n"; do { echo "\nIs this is correct ? (y/n): "; $valid = chop(fgets($fp)); if ($valid === "n") { exit(0); } } while ($valid != "y" ); if(install_mount_cd($cdrom)) { echo "\nMeet a problem for mounting the CDROM.\n"; exit(0); } if(install_backupconfig($cfgpartition)) { echo "\nMeet a problem for backuping configuration file.\n"; exit(0); } /* Must install on ad0s1 if installed on partition 1, but install on ad0 if installed on ad0a */ if ($slice) { if(install_dd_image($cfgpartition)) { echo "\nMeet a problem during file copying.\n"; install_unmount_cd(); exit(0); } } else { if(install_dd_image($cfgdevice)) { echo "\nMeet a problem during file copying.\n"; install_unmount_cd(); exit(0); } } if(install_restoreconfig($cfgpartition)) { echo "\nMeet a problem for restoring configuration file.\n"; exit(0); } install_unmount_cd(); echo <<<EOD {$productname} installed on $cfdevice has been upgraded. You can now remove the CD-ROM and reboot the PC. Press ENTER to continue. EOD; fgets($fp); ?>