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