3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Script which reads the pc-autoinstall.conf directive, and begins the install
32 # Source our functions scripts
33 . ${BACKEND}/functions.sh
34 . ${BACKEND}/functions-networking.sh
35 . ${BACKEND}/functions-parse.sh
37 # Check that the config file exists
40 echo "ERROR: Install configuration $1 does not exist!"
44 # Set our config file variable
46 INSTALL_CFG="/tmp/pc-sysinstall.cfg"
48 # Check if the config file is on disk as well
49 PCCFG=`grep "pc_config:" ${CONF} | grep -v "^#" | sed "s|pc_config: ||g" | sed "s|pc_config:||g"`
50 SHUTDOWN_CMD=`grep "shutdown_cmd:" ${CONF} | grep -v "^#" | sed "s|shutdown_cmd: ||g" | sed "s|shutdown_cmd:||g"`
51 CONFIRM_INS=`grep "confirm_install:" ${CONF} | grep -v "^#" | sed "s|confirm_install: ||g" | sed "s|confirm_install:||g"`
53 # Check that this isn't a http / ftp file we need to fetch later
54 echo "${PCCFG}" | grep -q -e "^http" -e "^ftp" 2>/dev/null
57 # Copy over the install cfg file, if not done already
58 if [ ! -e "${INSTALL_CFG}" ]
60 cp ${PCCFG} ${INSTALL_CFG}
62 # Make sure we have the file which was copied into /tmp previously
63 if [ ! -e "${INSTALL_CFG}" ]
65 echo "Error: ${INSTALL_CFG} is missing! Exiting in 10 seconds..."
70 # We need to fetch a remote file, check and set any nic options before doing so
71 NICCFG=`grep "nic_config:" ${CONF} | grep -v "^#" | sed "s|nic_config: ||g" | sed "s|nic_config:||g"`
72 if [ "${NICCFG}" = "dhcp-all" -o "${NICCFG}" = "DHCP-ALL" ]
74 # Try to auto-enable dhcp on any nics we find
77 echo "Running command \"ifconfig ${NICCFG}\""
79 WRKNIC="`echo ${NICCFG} | cut -d ' ' -f 1`"
80 NICDNS=`grep "nic_dns:" ${CONF} | grep -v "^#" | sed "s|nic_dns: ||g" | sed "s|nic_dns:||g"`
81 NICGATE=`grep "nic_gateway:" ${CONF} | grep -v "^#" | sed "s|nic_gateway: ||g" | sed "s|nic_gateway:||g"`
83 echo "nameserver ${NICDNS}" >/etc/resolv.conf
85 echo "Running command \"route add default ${NICGATE}\""
86 route add default ${NICGATE}
92 PCCFG=`echo ${PCCFG} | sed "s|%%NIC_MAC%%|${nic_mac}|g"`
94 # Now try to fetch the remove file
95 echo "Fetching cfg with: \"fetch -o ${INSTALL_CFG} ${PCCFG}\""
96 fetch -o "${INSTALL_CFG}" "${PCCFG}"
99 echo "ERROR: Failed to fetch ${PCCFG}, install aborted"
105 # If we end up with a valid config, lets proccede
106 if [ -e "${INSTALL_CFG}" ]
109 if [ "${CONFIRM_INS}" != "no" -a "${CONFIRM_INS}" != "NO" ]
111 echo "Type in 'install' to begin automated installation. Warning: Data on target disks may be destroyed!"
115 *) echo "Install canceled!" ; exit 150 ;;
119 pc-sysinstall -c ${INSTALL_CFG}
122 if [ -n "$SHUTDOWN_CMD" ]
126 echo "SUCCESS: Installation finished! Press ENTER to reboot."
131 echo "ERROR: Installation failed, press ENTER to drop to shell."
136 echo "ERROR: Failed to get /tmp/pc-sysinstall.cfg for automated install..."