Commit ce32fb74 authored by Franco Fichtner's avatar Franco Fichtner

rc: move importer to very early spot, add timeout #1372

parent 21b84ed2
......@@ -71,7 +71,7 @@ attempts=0
while [ ${attempts} -lt 3 ]; do
fsck -C -y /
fsck -C -y /
if mount -a 2>/dev/null; then
if mount -a 2> /dev/null; then
# bail if all is well
break
fi
......@@ -99,19 +99,11 @@ fi
# set keyboard map if needed
/etc/rc.d/syscons onestart
# set up config directory structure
mkdir -p /conf/backup
mkdir -p /conf/sshd
# Bootstrap config.xml if necessary
if [ ! -f /conf/config.xml ]; then
echo -n "Bootstrapping config.xml..."
cp /usr/local/etc/config.xml /conf/config.xml
echo "done."
fi
# run the config importer during early startup
/usr/local/etc/rc.importer || exit 1
# Enable console output if its muted.
/sbin/conscontrol mute off >/dev/null
/sbin/conscontrol mute off > /dev/null
setup_mfs_link()
{
......@@ -217,7 +209,7 @@ chmod 1777 /tmp
echo -n "."
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
/etc/rc.d/ldconfig start 2>/dev/null
/etc/rc.d/ldconfig start 2> /dev/null
# Launching kbdmux(4)
if [ -f "/dev/kbdmux0" ]; then
......@@ -270,7 +262,7 @@ rm /var/run/booting
/usr/local/etc/rc.opnsense start
echo -n "Starting CRON..."
cd /tmp && /usr/sbin/cron -s 2>/dev/null
cd /tmp && /usr/sbin/cron -s 2> /dev/null
echo "done."
/usr/local/sbin/beep.sh start
......
......@@ -58,6 +58,10 @@ foreach ($inc_files as $inc_file) {
echo "done.\n";
global $config;
$config = parse_config(true);
convert_config();
/*
* Now mute console messages from kernel for this script, it
* has consequences for printing bootup info and can clobber
......@@ -65,30 +69,6 @@ echo "done.\n";
*/
system_console_mute();
/* loopback device is required early for syslog and the installer */
interfaces_loopback_configure(true);
$setup_installer = is_install_media();
if ($setup_installer) {
echo 'Press any key to start the configuration importer: ';
$key = timeout();
if ($key != "\n") {
echo "\n";
}
if (isset($key)) {
passthru('/usr/local/etc/rc.importer');
}
/* config may have changed via installer import */
OPNsense\Core\Config::getInstance()->forceReload();
}
global $config;
$config = parse_config(true);
convert_config();
system_devd_configure(true);
system_login_configure(true);
......@@ -158,7 +138,7 @@ if ($ipsec_dynamic_hosts) {
// generate configuration data for all installed templates
configd_run('template reload *');
if ($setup_installer) {
if (is_install_media()) {
/*
* Installer mode requires setting up an extra user and
* we will protect it with root's password. We can only
......
......@@ -24,8 +24,57 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
INSTALL="/.probe.for.install.media"
MNT="/tmp/hdrescue"
bootstrap_and_exit()
{
# ensure config directory structure
mkdir -p /conf/backup
mkdir -p /conf/sshd
# create initial config.xml if necessary
if [ ! -f /conf/config.xml ]; then
echo -n "Bootstrapping config.xml..."
cp /usr/local/etc/config.xml /conf/config.xml
echo "done."
fi
exit 0
}
touch ${INSTALL}
if [ -f ${INSTALL} -a -f /conf/config.xml ]; then
bootstrap_and_exit
fi
timeout_prompt()
{
OUTPUT=$(echo ${2} | sed 's/./& /g')
MESSAGE=${1}
RETURN=1
echo -n "${MESSAGE} "
stty cbreak -echo
for NEXT in ${OUTPUT}; do
echo -n ${NEXT}
if timeout 1 dd of=/dev/null count=1 status=none; then
RETURN=0
break
fi
done
stty -cbreak echo
echo
return ${RETURN}
}
if ! timeout_prompt 'Press any key to start the configuration importer:' .......; then
bootstrap_and_exit
fi
DEVS=$(camcontrol devlist)
PART=
......@@ -36,7 +85,7 @@ while [ -z "${PART}" ]; do
read -p "Select a device import from or leave blank to exit: " DEV
if [ -z "${DEV}" ]; then
exit 0
bootstrap_and_exit
elif [ -e "/dev/${DEV}s1a" ]; then
# MBR layout found
PART="/dev/${DEV}s1a"
......@@ -59,14 +108,16 @@ if [ -f "${MNT}/conf/config.xml" ]; then
rm -rf /conf/*
for FILE in config.xml dhcpleases.tgz netflow.tgz rrd.tgz; do
if [ -f "${MNT}/conf/${FILE}" ]; then
echo -n "Restoring ${FILE}..."
cp "${MNT}/conf/${FILE}" /conf
echo "Restored ${FILE}"
echo "done."
fi
done
for DIR in backup sshd; do
if [ -d "${MNT}/conf/${DIR}" ]; then
echo -n "Restoring ${DIR}..."
cp -r "${MNT}/conf/${DIR}" /conf
echo "Restored ${DIR}"
echo "done."
else
mkdir -p "/conf/${DIR}"
fi
......@@ -77,3 +128,5 @@ fi
umount ${MNT}
rm -r ${MNT}
bootstrap_and_exit
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