From 7ec8b201296592a44aab87b17276b120ee9755c3 Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 18 Jul 2017 11:12:49 -0400 Subject: Prepare installer files for "Recover config.xml" option. Issue #7708 The actual script will be in the pfSense repo under tools/installer (cherry picked from commit 3413d68503fa5016f5f26a428109398ffab0372e) (cherry picked from commit c9f41f00a675b5cdf7a2864a403cb2376837ace8) --- release/rc.local | 25 ++++++++++++++++++---- usr.sbin/bsdinstall/scripts/auto | 16 ++++++++++++++ .../bsdinstall/scripts/copy_configxml_from_usb | 18 ++++++++++------ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/release/rc.local b/release/rc.local index 27b670f..d0b08c5 100755 --- a/release/rc.local +++ b/release/rc.local @@ -72,10 +72,23 @@ if [ -f /etc/installerconfig ]; then exit fi -dialog --backtitle "pfSense Installer" --title "Welcome" --yes-label "Install" --no-label "Rescue Shell" --yesno "Welcome to pfSense! Would you like to begin an installation or use the Rescue Shell?" 0 0 +IOPTS="\ +\"Install\" \"Install pfSense\" \ +\"Rescue Shell\" \"Launch a shell prompt to perform rescue operations\"" -case $? in -$DIALOG_OK) # Install +if [ -x /root/recover_configxml.sh ] ; then + IOPTS="${IOPTS} \"Recover config.xml\" \"Recover config.xml from a previous installation\"" +fi + +exec 3>&1 +IMODE=`echo ${IOPTS} | xargs dialog --backtitle "pfSense Installer" \ + --title "Welcome" \ + --menu "Welcome to pfSense!" \ + 0 0 0 2>&1 1>&3` || exit 1 +exec 3>&- + +case "$IMODE" in +"Install") # Install # If not netbooting, have the installer configure the network dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` if [ ${dlv:=0} -eq 0 -a ! -f /etc/diskless ]; then @@ -94,11 +107,15 @@ $DIALOG_OK) # Install . /etc/rc.local fi ;; -$DIALOG_CANCEL) # Rescue Shell +"Rescue Shell") # Rescue Shell clear echo "When finished, type 'exit' to return to the installer." /bin/sh . /etc/rc.local ;; +"Recover config.xml") # Recover config.xml from a target drive + /root/recover_configxml.sh + . /etc/rc.local + ;; esac diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index 459f1a4..63379f6 100755 --- a/usr.sbin/bsdinstall/scripts/auto +++ b/usr.sbin/bsdinstall/scripts/auto @@ -465,6 +465,22 @@ trap error SIGINT # SIGINT is bad again bsdinstall config || error "Failed to save config" bsdinstall copy_configxml_from_usb +# If the user recovered a config.xml from an existing disk or provided one on +# a USB disk, then copy this config.xml to the chroot +if [ -r /tmp/recovered_config/config.xml ] ; then + /bin/cp -r /tmp/recovered_config/config.xml ${BSDINSTALL_CHROOT}/cf/conf/ + # Set a flag to let the installed system know this may need extra processing + /usr/bin/touch ${BSDINSTALL_CHROOT}/cf/conf/installer_copied_config + # Only set the package sync flag if the restored config.xml contains active packages + if [ `/usr/bin/grep -c '' ${BSDINSTALL_CHROOT}/cf/conf/config.xml` -gt 0 ]; then + /usr/bin/touch ${BSDINSTALL_CHROOT}/cf/conf/needs_package_sync_after_reboot + fi + # If there is an existing configuration, then there is no need to run the wizard. + if [ -r ${BSDINSTALL_CHROOT}/cf/conf/trigger_initial_wizard ]; then + rm -f ${BSDINSTALL_CHROOT}/cf/conf/trigger_initial_wizard + fi +fi + if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then [ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \ umount "$BSDINSTALL_DISTDIR" diff --git a/usr.sbin/bsdinstall/scripts/copy_configxml_from_usb b/usr.sbin/bsdinstall/scripts/copy_configxml_from_usb index b022a0a..d682311 100755 --- a/usr.sbin/bsdinstall/scripts/copy_configxml_from_usb +++ b/usr.sbin/bsdinstall/scripts/copy_configxml_from_usb @@ -25,24 +25,28 @@ # SUCH DAMAGE. # # $FreeBSD$ +recovery_mount=/tmp/mnt_recovery +recovery_dir=/tmp/recovered_config +mkdir -p ${recovery_mount} +mkdir -p ${recovery_dir} look_for_config_xml_config_msdos() { - mkdir -p /tmp/mnt/cf + mkdir -p ${recovery_mount} echo -n "Looking for config.xml on " for try_device in `/sbin/gpart show -p | /usr/bin/egrep '(fat32|\!11|\!12|\!14)' | /usr/bin/awk '{print $3;}'`; do if [ ! -e /dev/${try_device} ]; then continue fi echo -n "${try_device}: " - if /sbin/mount -t msdosfs /dev/${try_device} /tmp/mnt/cf 2>/dev/null ; then + if /sbin/mount -t msdosfs /dev/${try_device} ${recovery_mount} 2>/dev/null ; then echo -n "[found msdos] " # look for config.xml - if [ -r /tmp/mnt/cf/conf/config.xml ]; then + if [ -r ${recovery_mount}/conf/config.xml ]; then echo -n "[config.xml on ${try_device}] " return 0 else echo -n "[no config.xml on ${try_device}, unmounting] " - /sbin/umount /tmp/mnt/cf + /sbin/umount ${recovery_mount} fi fi done @@ -51,9 +55,9 @@ look_for_config_xml_config_msdos() { # Try to locate an existing config.xml file if look_for_config_xml_config_msdos ; then - /bin/cp -r /tmp/mnt/cf/conf/config.xml $BSDINSTALL_CHROOT/cf/conf/ - /sbin/umount /tmp/mnt/cf/ 2>&1 - echo -n "[Copied config.xml file] " + /bin/cp -r ${recovery_mount}/conf/config.xml ${recovery_dir} + /sbin/umount ${recovery_mount} 2>&1 + echo -n "[Copied config.xml file to recovery area] " else echo -n "[Could not locate an existing config.xml file!] " fi -- cgit v1.1