Commit 511eb60e authored by Franco Fichtner's avatar Franco Fichtner

src: zap code that handled "cdrom" idiosyncrasies

We can do without those on the install media.  Instead, route
necessary code parts through is_install_media().  A lot of
stale and forgotten code got ditched in the process--e.g. when
did we ever run without an /etc/fstab?
parent c93d5dcb
...@@ -54,12 +54,13 @@ function set_networking_interfaces_ports() ...@@ -54,12 +54,13 @@ function set_networking_interfaces_ports()
$iflist = get_interface_list(); $iflist = get_interface_list();
/* Function flow is based on $key and $auto_assign or the lack thereof */ /* Function flow is based on $key and $auto_assign or the lack thereof */
$key = null; $key = null;
/* Only present auto interface option if running from LiveCD and interface mismatch*/ /* Only present auto interface option if running from LiveCD and interface mismatch*/
if ((preg_match("/cdrom/", $g['platform'])) && is_interface_mismatch()) if (is_install_media() && is_interface_mismatch()) {
$auto_assign = false; $auto_assign = false;
}
echo <<<EOD echo <<<EOD
......
...@@ -71,103 +71,19 @@ if(file_exists("/var/run/booting") && file_exists("/conf/config.xml")) { ...@@ -71,103 +71,19 @@ if(file_exists("/var/run/booting") && file_exists("/conf/config.xml")) {
} }
} }
/* if our config file exists bail out, we're already set. */
else if (file_exists("/var/run/booting") && !file_exists('/conf/config.xml')) {
/* find the device where config.xml resides and write out an fstab */
unset($cfgdevice);
/* check if there's already an fstab (NFS booting?) */
if (!file_exists('/etc/fstab')) {
if (strstr($g['platform'], "cdrom")) {
/* config is on floppy disk for CD-ROM version */
$cfgdevice = $cfgpartition = "fd0";
$_gb = exec('/sbin/dmesg -a', $dmesg);
if(preg_match("/da0/", $dmesg) == true) {
$cfgdevice = $cfgpartition = "da0" ;
if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
/* could not mount, fallback to floppy */
$cfgdevice = $cfgpartition = "fd0";
}
}
$cfgfstype = "msdosfs";
echo gettext("CDROM build") . "\n";
echo " " . gettext("CFG:") . " {$cfgpartition}\n";
echo " " . gettext("CFG:") . " {$cfgpartition}\n";
echo " " . gettext("TYPE:") . " {$cfgfstype}\n";
} else {
/* probe kernel known disks until we find one with config.xml */
$disks = explode(" ", get_single_sysctl("kern.disks"));
foreach ($disks as $mountdisk) {
/* skip mfs mounted filesystems */
if (strstr($mountdisk, "md"))
continue;
if (mwexec("/sbin/mount -r /dev/{$mountdisk}a /cf") == 0) {
if (file_exists('/conf/config.xml')) {
/* found it */
$cfgdevice = $mountdisk;
$cfgpartition = $cfgdevice . "a";
$cfgfstype = "ufs";
printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
}
mwexec("/sbin/umount -f /cf");
if ($cfgdevice)
break;
}
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d /cf") == 0) {
if (file_exists('/conf/config.xml')) {
/* found it */
$cfgdevice = $mountdisk;
$cfgpartition = $cfgdevice . "d";
$cfgfstype = "ufs";
printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
}
mwexec("/sbin/umount -f /cf");
if ($cfgdevice)
break;
}
}
}
if (!$cfgdevice) {
$last_backup = discover_last_backup();
if($last_backup) {
log_error(gettext("No config.xml found, attempting last known config restore."));
file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
restore_backup("/conf/backup/{$last_backup}");
} else {
log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
restore_backup('/usr/local/etc/config.xml');
}
}
/* write out an fstab */
$fd = fopen('/etc/fstab', 'w');
$fstab = "/dev/{$cfgpartition} /cf {$cfgfstype} ro,noatime 1 1\n";
$fstab .= "proc /proc procfs rw 0 0\n";
fwrite($fd, $fstab);
fclose($fd);
}
/* mount all filesystems */
mwexec("/sbin/mount -a");
}
$config = parse_config(); $config = parse_config();
/* set timezone */ /* set timezone */
$timezone = $config['system']['timezone']; $timezone = $config['system']['timezone'];
if (!$timezone) if (!$timezone) {
$timezone = "Etc/UTC"; $timezone = "Etc/UTC";
}
date_default_timezone_set("$timezone"); date_default_timezone_set("$timezone");
if($config_parsed == true) { if ($config_parsed == true) {
/* process packager manager custom rules */ /* process packager manager custom rules */
if(is_dir("/usr/local/pkg/parse_config")) { if(is_dir("/usr/local/pkg/parse_config")) {
run_plugins("/usr/local/pkg/parse_config/"); run_plugins("/usr/local/pkg/parse_config/");
} }
} }
?>
...@@ -205,32 +205,20 @@ function parse_config_bootup() ...@@ -205,32 +205,20 @@ function parse_config_bootup()
$lockkey = lock('config'); $lockkey = lock('config');
if (!file_exists($config_xml)) { if (!file_exists($config_xml)) {
if (file_exists("/var/run/booting")) { if (file_exists("/var/run/booting")) {
if (strstr($g['platform'], "cdrom")) { $last_backup = discover_last_backup();
/* try copying the default config. to the floppy */ if($last_backup) {
echo gettext("Resetting factory defaults...") . "\n"; log_error("No config.xml found, attempting last known config restore.");
reset_factory_defaults(true); file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
if (!file_exists($config_xml)) { restore_backup("/conf/backup/{$last_backup}");
echo gettext("No XML configuration file found - using factory defaults.\n" .
"Make sure that the configuration floppy disk with the conf/config.xml\n" .
"file is inserted. If it isn't, your configuration changes will be lost\n" .
"on reboot.\n");
}
} else {
$last_backup = discover_last_backup();
if($last_backup) {
log_error("No config.xml found, attempting last known config restore.");
file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
restore_backup("/conf/backup/{$last_backup}");
}
if (!file_exists($config_xml)) {
echo sprintf(gettext("XML configuration file not found. %s cannot continue booting."), $g['product_name']) . "\n";
unlock($lockkey);
mwexec("/sbin/halt");
exit;
}
log_error("Last known config found and restored. Please double check your configuration file for accuracy.");
file_notice("config.xml", gettext("Last known config found and restored. Please double check your configuration file for accuracy."), "pfSenseConfigurator", "");
} }
if (!file_exists($config_xml)) {
echo sprintf(gettext("XML configuration file not found. %s cannot continue booting."), $g['product_name']) . "\n";
unlock($lockkey);
mwexec("/sbin/halt");
exit;
}
log_error("Last known config found and restored. Please double check your configuration file for accuracy.");
file_notice("config.xml", gettext("Last known config found and restored. Please double check your configuration file for accuracy."), "pfSenseConfigurator", "");
} else { } else {
unlock($lockkey); unlock($lockkey);
log_error(gettext("Could not find a usable configuration file! Exiting....")); log_error(gettext("Could not find a usable configuration file! Exiting...."));
...@@ -280,12 +268,12 @@ EOD; ...@@ -280,12 +268,12 @@ EOD;
* null * null
******/ ******/
/* mount flash card read/write */ /* mount flash card read/write */
function conf_mount_rw() { function conf_mount_rw()
{
global $g, $config; global $g, $config;
/* do not mount on cdrom platform */ /* XXX do not mount (we're already set up) */
if($g['platform'] == "cdrom" or $g['platform'] == "pfSense") return;
return;
if ((refcount_reference(1000) > 1) && is_writable("/")) if ((refcount_reference(1000) > 1) && is_writable("/"))
return; return;
...@@ -318,14 +306,12 @@ function conf_mount_rw() { ...@@ -318,14 +306,12 @@ function conf_mount_rw() {
* RESULT * RESULT
* null * null
******/ ******/
function conf_mount_ro() { function conf_mount_ro()
{
global $g, $config; global $g, $config;
/* Do not trust $g['platform'] since this can be clobbered during factory reset. */ /* XXX do not mount (we're already set up) */
$platform = trim(file_get_contents("/usr/local/etc/platform")); return;
/* do not umount on cdrom or pfSense platforms */
if($platform == "cdrom" or $platform == "pfSense")
return;
if (refcount_unreference(1000) > 0) if (refcount_unreference(1000) > 0)
return; return;
......
...@@ -53,7 +53,6 @@ $g = array( ...@@ -53,7 +53,6 @@ $g = array(
"product_copyright_url" => "https://www.deciso.com/", "product_copyright_url" => "https://www.deciso.com/",
"crashreporterurl" => "https://crash.opnsense.org/", "crashreporterurl" => "https://crash.opnsense.org/",
"latest_config" => "11.1", "latest_config" => "11.1",
"nopkg_platforms" => array("cdrom"),
"minimum_ram_warning" => "101", "minimum_ram_warning" => "101",
"minimum_ram_warning_text" => "128 MB", "minimum_ram_warning_text" => "128 MB",
"wan_interface_name" => "wan", "wan_interface_name" => "wan",
...@@ -133,4 +132,22 @@ $sysctls = array( ...@@ -133,4 +132,22 @@ $sysctls = array(
"net.inet6.ip6.rfc6204w3" => 1, "net.inet6.ip6.rfc6204w3" => 1,
); );
function is_install_media()
{
/*
* Despite unionfs underneath, / is still not writeable,
* making the following the perfect test for install media.
*/
$file = '/.probe.for.install.media';
$fd = @fopen($file, 'w');
if ($fd) {
fclose($fd);
unlink($file);
return false;
}
return true;
}
$config_parsed = false; $config_parsed = false;
...@@ -843,7 +843,7 @@ function setup_serial_port($when = 'save', $path = '') ...@@ -843,7 +843,7 @@ function setup_serial_port($when = 'save', $path = '')
$boot_config = ""; $boot_config = "";
$serialspeed = (is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200'; $serialspeed = (is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200';
if ($g['platform'] != "cdrom") { if (!is_install_media()) {
$boot_config_split = explode("\n", $boot_config); $boot_config_split = explode("\n", $boot_config);
$fd = fopen($boot_config_file,"w"); $fd = fopen($boot_config_file,"w");
if($fd) { if($fd) {
...@@ -886,7 +886,7 @@ function setup_serial_port($when = 'save', $path = '') ...@@ -886,7 +886,7 @@ function setup_serial_port($when = 'save', $path = '')
} else if (is_serial_enabled()) { } else if (is_serial_enabled()) {
$new_boot_config[] = 'boot_multicons="YES"'; $new_boot_config[] = 'boot_multicons="YES"';
$new_boot_config[] = 'boot_serial="YES"'; $new_boot_config[] = 'boot_serial="YES"';
$primaryconsole = isset($g['primaryconsole_force']) ? $g['primaryconsole_force'] : $config['system']['primaryconsole']; $primaryconsole = $config['system']['primaryconsole'];
switch ($primaryconsole) { switch ($primaryconsole) {
case "video": case "video":
$new_boot_config[] = 'console="vidconsole,comconsole"'; $new_boot_config[] = 'console="vidconsole,comconsole"';
...@@ -932,14 +932,9 @@ function setup_serial_port($when = 'save', $path = '') ...@@ -932,14 +932,9 @@ function setup_serial_port($when = 'save', $path = '')
function is_serial_enabled() function is_serial_enabled()
{ {
global $g, $config; global $config;
if (!isset($g['enableserial_force']) &&
!isset($config['system']['enableserial']) &&
($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt")))
return false;
return true; return isset($config['system']['enableserial']);
} }
function reload_ttys() function reload_ttys()
......
...@@ -1856,15 +1856,10 @@ EOD; ...@@ -1856,15 +1856,10 @@ EOD;
name => platform string (e.g. 'wrap', 'alix' etc.) name => platform string (e.g. 'wrap', 'alix' etc.)
descr => human-readable description (e.g. "PC Engines WRAP") descr => human-readable description (e.g. "PC Engines WRAP")
*/ */
function system_identify_specific_platform() { function system_identify_specific_platform()
{
global $g; global $g;
if ($g['platform'] == 'generic-pc')
return array('name' => 'generic-pc', 'descr' => gettext("Generic PC"));
if ($g['platform'] == 'generic-pc-cdrom')
return array('name' => 'generic-pc-cdrom', 'descr' => gettext("Generic PC (CD-ROM)"));
/* the rest of the code only deals with 'embedded' platforms */ /* the rest of the code only deals with 'embedded' platforms */
if ($g['platform'] != 'nanobsd') if ($g['platform'] != 'nanobsd')
return array('name' => $g['platform'], 'descr' => $g['platform']); return array('name' => $g['platform'], 'descr' => $g['platform']);
......
...@@ -39,8 +39,8 @@ else ...@@ -39,8 +39,8 @@ else
# fake a writeable environment in some subdirs # fake a writeable environment in some subdirs
for i in conf etc home root usr var; do for i in conf etc home root usr var; do
/bin/mkdir -p /tmp/.cdrom/${i} /bin/mkdir -p /tmp/.install.media/${i}
/sbin/mount_unionfs /tmp/.cdrom/${i} /${i} /sbin/mount_unionfs /tmp/.install.media/${i} /${i}
done done
fi fi
......
...@@ -29,24 +29,6 @@ ...@@ -29,24 +29,6 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
function is_install_media()
{
/*
* Despite unionfs underneath, / is still not writeable,
* making the following the perfect test for install media.
*/
$file = '/.probe.for.install.media';
$fd = @fopen($file, 'w');
if ($fd) {
fclose($fd);
unlink($file);
return false;
}
return true;
}
function rescue_detect_keypress() function rescue_detect_keypress()
{ {
$timeout = 9; $timeout = 9;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require("guiconfig.inc"); require_once("guiconfig.inc");
require_once("functions.inc"); require_once("functions.inc");
require_once("filter.inc"); require_once("filter.inc");
require_once("shaper.inc"); require_once("shaper.inc");
...@@ -136,7 +136,7 @@ if ($_POST) { ...@@ -136,7 +136,7 @@ if ($_POST) {
else else
unset($config['system']['webgui']['noantilockout']); unset($config['system']['webgui']['noantilockout']);
if ($_POST['enableserial'] == "yes" || $g['enableserial_force']) if ($_POST['enableserial'] == "yes")
$config['system']['enableserial'] = true; $config['system']['enableserial'] = true;
else else
unset($config['system']['enableserial']); unset($config['system']['enableserial']);
...@@ -528,8 +528,6 @@ include("head.inc"); ...@@ -528,8 +528,6 @@ include("head.inc");
<tr> <tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Serial Communications"); ?></th> <th colspan="2" valign="top" class="listtopic"><?=gettext("Serial Communications"); ?></th>
</tr> </tr>
<?php if (!$g['enableserial_force'] && ($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt"))): ?>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Serial Terminal"); ?></td> <td width="22%" valign="top" class="vncell"><?=gettext("Serial Terminal"); ?></td>
<td width="78%" class="vtable"> <td width="78%" class="vtable">
...@@ -538,7 +536,6 @@ include("head.inc"); ...@@ -538,7 +536,6 @@ include("head.inc");
<span class="vexpl"><?=gettext("Note: This will redirect the console output and messages to the serial port. You can still access the console menu from the internal video card/keyboard. A <b>null modem</b> serial cable or adapter is required to use the serial console."); ?></span> <span class="vexpl"><?=gettext("Note: This will redirect the console output and messages to the serial port. You can still access the console menu from the internal video card/keyboard. A <b>null modem</b> serial cable or adapter is required to use the serial console."); ?></span>
</td> </td>
</tr> </tr>
<?php endif; ?>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Serial Speed")?></td> <td width="22%" valign="top" class="vncell"><?=gettext("Serial Speed")?></td>
<td width="78%" class="vtable"> <td width="78%" class="vtable">
...@@ -553,7 +550,6 @@ include("head.inc"); ...@@ -553,7 +550,6 @@ include("head.inc");
<br /><?=gettext("Allows selection of different speeds for the serial console port."); ?> <br /><?=gettext("Allows selection of different speeds for the serial console port."); ?>
</td> </td>
</tr> </tr>
<?php if (!$g['primaryconsole_force'] && ($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt"))): ?>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Primary Console")?></td> <td width="22%" valign="top" class="vncell"><?=gettext("Primary Console")?></td>
<td width="78%" class="vtable"> <td width="78%" class="vtable">
...@@ -564,7 +560,6 @@ include("head.inc"); ...@@ -564,7 +560,6 @@ include("head.inc");
<br /><?=gettext("Select the preferred console if multiple consoles are present. The preferred console will show OPNsense boot script output. All consoles display OS boot messages, console messages, and the console menu."); ?> <br /><?=gettext("Select the preferred console if multiple consoles are present. The preferred console will show OPNsense boot script output. All consoles display OS boot messages, console messages, and the console menu."); ?>
</td> </td>
</tr> </tr>
<?php endif; ?>
<tr> <tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Console Options"); ?></th> <th colspan="2" valign="top" class="listtopic"><?=gettext("Console Options"); ?></th>
</tr> </tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment