Commit 0f6cac1e authored by Franco Fichtner's avatar Franco Fichtner

rc: merge installer/importer additions

This is a preview merge as we add the new importer, but don't use it yet.
parent 6aa83df6
......@@ -90,6 +90,7 @@
/usr/local/etc/rc.firmware
/usr/local/etc/rc.firmware.subr
/usr/local/etc/rc.halt
/usr/local/etc/rc.importer
/usr/local/etc/rc.initial
/usr/local/etc/rc.initial.banner
/usr/local/etc/rc.initial.defaults
......@@ -911,6 +912,8 @@
/usr/local/sbin/ntpdate_sync_once.sh
/usr/local/sbin/openvpn.attributes.sh
/usr/local/sbin/opnsense-auth
/usr/local/sbin/opnsense-importer
/usr/local/sbin/opnsense-installer
/usr/local/sbin/ovpn-linkdown
/usr/local/sbin/ovpn-linkup
/usr/local/sbin/ovpn_auth_verify
......
#!/bin/sh
# Copyright (c) 2014-2017 Franco Fichtner <franco@opnsense.org>
# Copyright (c) 2004-2009 Scott Ullrich <sullrich@gmail.com>
#
# 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.
INSTALL="/.probe.for.install.media"
MNT="/tmp/hdrescue"
DO_BOOT=
while getopts b OPT; do
case ${OPT} in
b)
DO_BOOT="-b"
shift
;;
*)
echo "Unknown argument during import." >&2
exit 0
;;
esac
done
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
# clean up after a finished import
if [ -d ${MNT} ]; then
umount ${MNT} 2> /dev/null
rm -rf ${MNT}
fi
exit 0
}
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}
}
probe_for_part()
{
DEV=${1}
if [ -e "/dev/${DEV}s1a" ]; then
# MBR layout found
export PART="/dev/${DEV}s1a"
return 0
elif [ -e "/dev/${DEV}p3" ]; then
# GPT layout found
export PART="/dev/${DEV}p3"
return 0
fi
return 1
}
DEVS=
PART=
if [ -n "${DO_BOOT}" ]; then
touch ${INSTALL} 2> /dev/null
if [ -f ${INSTALL} -a -f /conf/config.xml ]; then
bootstrap_and_exit
fi
if ! timeout_prompt \
'Press any key to start the configuration importer:' .......; then
bootstrap_and_exit
fi
elif [ -n "${1}" ]; then
if ! probe_for_part ${1}; then
bootstrap_and_exit
fi
else
DEVS=$(camcontrol devlist)
fi
while [ -z "${PART}" ]; do
echo
echo "${DEVS}"
echo
read -p "Select device to import from (e.g. ada0) or leave blank to exit: " DEV
echo
if [ -z "${DEV}" ]; then
bootstrap_and_exit
fi
if ! probe_for_part ${DEV}; then
echo "No known partition layout was found for '${DEV}'."
fi
done
echo "Starting import for partition '${PART}'."
echo
mkdir -p ${MNT}
fsck -t ufs -y ${PART} > /dev/null
if ! mount ${PART} ${MNT} 2> /dev/null; then
echo "The device could not be mounted."
bootstrap_and_exit
# XXX redo
fi
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 "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 "done."
else
mkdir -p "/conf/${DIR}"
fi
done
else
echo "No previous configuration was found on this device."
bootstrap_and_exit
# XXX redo
fi
if [ -z "${DO_BOOT}" ]; then
echo "Please reboot."
fi
bootstrap_and_exit
#!/bin/sh
# Copyright 2004-2009 Scott Ullrich
# Copyright (c) 2014-2017 Franco Fichtner <franco@opnsense.org>
# Copyright (c) 2004-2009 Scott Ullrich <sullrich@gmail.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
......@@ -28,7 +29,6 @@ sysctl net.link.ether.inet.log_arp_wrong_iface=0 >/dev/null
rm -f /tmp/install_complete
# Start the backend in the background (must mute all the ouput)
daemon -f lua50c51 /usr/local/share/dfuibe_lua/main.lua \
/usr/local/share/dfuibe_lua/conf/BSDInstaller.lua \
/usr/local/share/dfuibe_lua/conf/FreeBSD.lua \
......@@ -36,8 +36,7 @@ daemon -f lua50c51 /usr/local/share/dfuibe_lua/main.lua \
conscontrol mute on > /dev/null
# Launch the frontend goo (must include cons25 for first boot)
TERM=cons25 dfuife_curses -b /usr/local/share/dfuife_curses/hourglass.txt
dfuife_curses -b /usr/local/share/dfuife_curses/hourglass.txt
conscontrol mute off > /dev/null
......
#!/bin/sh
# launch the real utility from here
/usr/local/etc/rc.importer "${@}"
#!/bin/sh
# launch the real utility from here
/usr/local/etc/rc.installer "${@}"
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