Index: head/share/examples/bhyve/vmrun.sh =================================================================== --- head/share/examples/bhyve/vmrun.sh (revision 326274) +++ head/share/examples/bhyve/vmrun.sh (revision 326275) @@ -1,376 +1,378 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2013 NetApp, Inc. # All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # LOADER=/usr/sbin/bhyveload BHYVECTL=/usr/sbin/bhyvectl FBSDRUN=/usr/sbin/bhyve DEFAULT_MEMSIZE=512M DEFAULT_CPUS=2 DEFAULT_TAPDEV=tap0 DEFAULT_CONSOLE=stdio DEFAULT_VIRTIO_DISK="./diskdev" DEFAULT_ISOFILE="./release.iso" errmsg() { echo "*** $1" } usage() { local msg=$1 echo "Usage: vmrun.sh [-aAEhiTv] [-c ] [-C ] [-d ]" echo " [-e ] [-f ] [-F ]" echo " [-g ] [-H ]" echo " [-I ] [-l ]" echo " [-L ]" echo " [-m ] [-P ] [-t ] " echo "" echo " -h: display this help message" echo " -a: force memory mapped local APIC access" echo " -A: use AHCI disk emulation instead of virtio" echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})" echo " -C: console device (default is ${DEFAULT_CONSOLE})" echo " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})" echo " -e: set FreeBSD loader environment variable" echo " -E: Use UEFI mode" echo " -f: Use a specific UEFI firmware" echo " -F: Use a custom UEFI GOP framebuffer size (default: w=1024,h=768)" echo " -g: listen for connection from kgdb at " echo " -H: host filesystem to export to the loader" echo " -i: force boot of the Installation CDROM image" echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})" echo " -l: the OS loader to use (default is /boot/userboot.so)" echo " -L: IP address for UEFI GOP VNC server (default: 127.0.0.1)" echo " -m: memory size (default is ${DEFAULT_MEMSIZE})" echo " -p: pass-through a host PCI device at bus/slot/func (e.g. 10/0/0)" echo " -P: UEFI GOP VNC port (default: 5900)" echo " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)" echo " -T: Enable tablet device (for UEFI GOP)" echo " -u: RTC keeps UTC time" echo " -v: Wait for VNC client connection before booting VM" echo " -w: ignore unimplemented MSRs" echo "" [ -n "$msg" ] && errmsg "$msg" exit 1 } if [ `id -u` -ne 0 ]; then errmsg "This script must be executed with superuser privileges" exit 1 fi kldstat -n vmm > /dev/null 2>&1 if [ $? -ne 0 ]; then errmsg "vmm.ko is not loaded" exit 1 fi force_install=0 isofile=${DEFAULT_ISOFILE} memsize=${DEFAULT_MEMSIZE} console=${DEFAULT_CONSOLE} cpus=${DEFAULT_CPUS} tap_total=0 disk_total=0 disk_emulation="virtio-blk" gdbport=0 loader_opt="" bhyverun_opt="-H -A -P" pass_total=0 # EFI-specific options efi_mode=0 efi_firmware="/usr/local/share/uefi-firmware/BHYVE_UEFI.fd" vncwait="" vnchost="127.0.0.1" vncport=5900 fbsize="w=1024,h=768" tablet="" while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:m:p:P:t:Tuvw c ; do case $c in a) bhyverun_opt="${bhyverun_opt} -a" ;; A) disk_emulation="ahci-hd" ;; c) cpus=${OPTARG} ;; C) console=${OPTARG} ;; d) disk_dev=${OPTARG%%,*} disk_opts=${OPTARG#${disk_dev}} eval "disk_dev${disk_total}=\"${disk_dev}\"" eval "disk_opts${disk_total}=\"${disk_opts}\"" disk_total=$(($disk_total + 1)) ;; e) loader_opt="${loader_opt} -e ${OPTARG}" ;; E) efi_mode=1 ;; f) efi_firmware="${OPTARG}" ;; F) fbsize="${OPTARG}" ;; g) gdbport=${OPTARG} ;; H) host_base=`realpath ${OPTARG}` ;; i) force_install=1 ;; I) isofile=${OPTARG} ;; l) loader_opt="${loader_opt} -l ${OPTARG}" ;; L) vnchost="${OPTARG}" ;; m) memsize=${OPTARG} ;; p) eval "pass_dev${pass_total}=\"${OPTARG}\"" pass_total=$(($pass_total + 1)) ;; P) vncport="${OPTARG}" ;; t) eval "tap_dev${tap_total}=\"${OPTARG}\"" tap_total=$(($tap_total + 1)) ;; T) tablet="-s 30,xhci,tablet" ;; u) bhyverun_opt="${bhyverun_opt} -u" ;; v) vncwait=",wait" ;; w) bhyverun_opt="${bhyverun_opt} -w" ;; *) usage ;; esac done if [ $tap_total -eq 0 ] ; then tap_total=1 tap_dev0="${DEFAULT_TAPDEV}" fi if [ $disk_total -eq 0 ] ; then disk_total=1 disk_dev0="${DEFAULT_VIRTIO_DISK}" fi shift $((${OPTIND} - 1)) if [ $# -ne 1 ]; then usage "virtual machine name not specified" fi vmname="$1" if [ -n "${host_base}" ]; then loader_opt="${loader_opt} -h ${host_base}" fi # If PCI passthru devices are configured then guest memory must be wired if [ ${pass_total} -gt 0 ]; then loader_opt="${loader_opt} -S" bhyverun_opt="${bhyverun_opt} -S" fi if [ ${efi_mode} -gt 0 ]; then if [ ! -f ${efi_firmware} ]; then echo "Error: EFI Firmware ${efi_firmware} doesn't exist. Try: pkg install uefi-edk2-bhyve" exit 1 fi fi make_and_check_diskdev() { local virtio_diskdev="$1" # Create the virtio diskdev file if needed if [ ! -e ${virtio_diskdev} ]; then echo "virtio disk device file \"${virtio_diskdev}\" does not exist." echo "Creating it ..." truncate -s 8G ${virtio_diskdev} > /dev/null fi if [ ! -r ${virtio_diskdev} ]; then echo "virtio disk device file \"${virtio_diskdev}\" is not readable" exit 1 fi if [ ! -w ${virtio_diskdev} ]; then echo "virtio disk device file \"${virtio_diskdev}\" is not writable" exit 1 fi } echo "Launching virtual machine \"$vmname\" ..." first_diskdev="$disk_dev0" ${BHYVECTL} --vm=${vmname} --destroy > /dev/null 2>&1 while [ 1 ]; do file -s ${first_diskdev} | grep "boot sector" > /dev/null rc=$? if [ $rc -ne 0 ]; then file -s ${first_diskdev} | grep ": Unix Fast File sys" > /dev/null rc=$? fi if [ $rc -ne 0 ]; then need_install=1 else need_install=0 fi if [ $force_install -eq 1 -o $need_install -eq 1 ]; then if [ ! -r ${isofile} ]; then echo -n "Installation CDROM image \"${isofile}\" " echo "is not readable" exit 1 fi BOOTDISKS="-d ${isofile}" installer_opt="-s 31:0,ahci-cd,${isofile}" else BOOTDISKS="" i=0 while [ $i -lt $disk_total ] ; do eval "disk=\$disk_dev${i}" if [ -r ${disk} ] ; then BOOTDISKS="$BOOTDISKS -d ${disk} " fi i=$(($i + 1)) done installer_opt="" fi if [ ${efi_mode} -eq 0 ]; then ${LOADER} -c ${console} -m ${memsize} ${BOOTDISKS} ${loader_opt} \ ${vmname} bhyve_exit=$? if [ $bhyve_exit -ne 0 ]; then break fi fi # # Build up args for additional tap and disk devices now. # nextslot=2 # slot 0 is hostbridge, slot 1 is lpc devargs="" # accumulate disk/tap args here i=0 while [ $i -lt $tap_total ] ; do eval "tapname=\$tap_dev${i}" devargs="$devargs -s $nextslot:0,virtio-net,${tapname} " nextslot=$(($nextslot + 1)) i=$(($i + 1)) done i=0 while [ $i -lt $disk_total ] ; do eval "disk=\$disk_dev${i}" eval "opts=\$disk_opts${i}" make_and_check_diskdev "${disk}" devargs="$devargs -s $nextslot:0,$disk_emulation,${disk}${opts} " nextslot=$(($nextslot + 1)) i=$(($i + 1)) done i=0 while [ $i -lt $pass_total ] ; do eval "pass=\$pass_dev${i}" devargs="$devargs -s $nextslot:0,passthru,${pass} " nextslot=$(($nextslot + 1)) i=$(($i + 1)) done efiargs="" if [ ${efi_mode} -gt 0 ]; then efiargs="-s 29,fbuf,tcp=${vnchost}:${vncport},${fbsize}${vncwait}" efiargs="${efiargs} -l bootrom,${efi_firmware}" efiargs="${efiargs} ${tablet}" fi ${FBSDRUN} -c ${cpus} -m ${memsize} ${bhyverun_opt} \ -g ${gdbport} \ -s 0:0,hostbridge \ -s 1:0,lpc \ ${efiargs} \ ${devargs} \ -l com1,${console} \ ${installer_opt} \ ${vmname} bhyve_exit=$? # bhyve returns the following status codes: # 0 - VM has been reset # 1 - VM has been powered off # 2 - VM has been halted # 3 - VM generated a triple fault # all other non-zero status codes are errors # if [ $bhyve_exit -ne 0 ]; then break fi done case $bhyve_exit in 0|1|2) # Cleanup /dev/vmm entry when bhyve did not exit # due to an error. ${BHYVECTL} --vm=${vmname} --destroy > /dev/null 2>&1 ;; esac exit $bhyve_exit Index: head/share/examples/hast/ucarp.sh =================================================================== --- head/share/examples/hast/ucarp.sh (revision 326274) +++ head/share/examples/hast/ucarp.sh (revision 326275) @@ -1,69 +1,71 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 The FreeBSD Foundation # All rights reserved. # # This software was developed by Pawel Jakub Dawidek under sponsorship from # the FreeBSD Foundation. # # 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 BY THE AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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. # # $FreeBSD$ # Shared IP address, unused for now. addr="10.99.0.3" # Password for UCARP communication. pass="password" # First node IP and interface for UCARP communication. nodea_srcip="10.99.0.1" nodea_ifnet="bge0" # Second node IP and interface for UCARP communication. nodeb_srcip="10.99.0.2" nodeb_ifnet="em3" export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin vhid="1" upscript="/root/hast/sbin/hastd/vip-up.sh" downscript="/root/hast/sbin/hastd/vip-down.sh" ifconfig "${nodea_ifnet}" 2>/dev/null | grep -q "inet ${nodea_srcip} " if [ $? -eq 0 ]; then srcip="${nodea_srcip}" ifnet="${nodea_ifnet}" node="node A" fi ifconfig "${nodeb_ifnet}" 2>/dev/null | grep -q "inet ${nodeb_srcip} " if [ $? -eq 0 ]; then if [ -n "${srcip}" -o -n "${ifnet}" ]; then echo "Unable to determine which node is this (both match)." >/dev/stderr exit 1 fi srcip="${nodeb_srcip}" ifnet="${nodeb_ifnet}" node="node B" fi if [ -z "${srcip}" -o -z "${ifnet}" ]; then echo "Unable to determine which node is this (none match)." >/dev/stderr exit 1 fi ucarp -i ${ifnet} -s ${srcip} -v ${vhid} -a ${addr} -p ${pass} -u "${upscript}" -d "${downscript}" Index: head/share/examples/hast/ucarp_down.sh =================================================================== --- head/share/examples/hast/ucarp_down.sh (revision 326274) +++ head/share/examples/hast/ucarp_down.sh (revision 326275) @@ -1,98 +1,100 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 The FreeBSD Foundation # All rights reserved. # # This software was developed by Pawel Jakub Dawidek under sponsorship from # the FreeBSD Foundation. # # 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 BY THE AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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. # # $FreeBSD$ # Resource name as defined in /etc/hast.conf. resource="test" # Supported file system types: UFS, ZFS fstype="UFS" # ZFS pool name. Required only when fstype == ZFS. pool="test" # File system mount point. Required only when fstype == UFS. mountpoint="/mnt/test" # Name of HAST provider as defined in /etc/hast.conf. # Required only when fstype == UFS. device="/dev/hast/${resource}" export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # KIll UP script if it still runs in the background. sig="TERM" for i in `jot 30`; do pgid=`pgrep -f ucarp_up.sh | head -1` [ -n "${pgid}" ] || break kill -${sig} -- -${pgid} sig="KILL" sleep 1 done if [ -n "${pgid}" ]; then logger -p local0.error -t hast "UCARP UP process for resource ${resource} is still running after 30 seconds." exit 1 fi logger -p local0.debug -t hast "UCARP UP is not running." case "${fstype}" in UFS) mount | egrep -q "^${device} on " if [ $? -eq 0 ]; then # Forcibly unmount file system. out=`umount -f "${mountpoint}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to unmount file system for resource ${resource}: ${out}." exit 1 fi logger -p local0.debug -t hast "File system for resource ${resource} unmounted." fi ;; ZFS) zpool list | egrep -q "^${pool} " if [ $? -eq 0 ]; then # Forcibly export file pool. out=`zpool export -f "${pool}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to export pool for resource ${resource}: ${out}." exit 1 fi logger -p local0.debug -t hast "ZFS pool for resource ${resource} exported." fi ;; esac # Change role to secondary for our resource. out=`hastctl role secondary "${resource}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to change to role to secondary for resource ${resource}: ${out}." exit 1 fi logger -p local0.debug -t hast "Role for resource ${resource} changed to secondary." logger -p local0.info -t hast "Successfully switched to secondary for resource ${resource}." exit 0 Index: head/share/examples/hast/ucarp_up.sh =================================================================== --- head/share/examples/hast/ucarp_up.sh (revision 326274) +++ head/share/examples/hast/ucarp_up.sh (revision 326275) @@ -1,105 +1,107 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 The FreeBSD Foundation # All rights reserved. # # This software was developed by Pawel Jakub Dawidek under sponsorship from # the FreeBSD Foundation. # # 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 BY THE AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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. # # $FreeBSD$ # Resource name as defined in /etc/hast.conf. resource="test" # Supported file system types: UFS, ZFS fstype="UFS" # ZFS pool name. Required only when fstype == ZFS. pool="test" # File system mount point. Required only when fstype == UFS. mountpoint="/mnt/test" # Name of HAST provider as defined in /etc/hast.conf. device="/dev/hast/${resource}" export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # If there is secondary worker process, it means that remote primary process is # still running. We have to wait for it to terminate. for i in `jot 30`; do pgrep -f "hastd: ${resource} \(secondary\)" >/dev/null 2>&1 || break sleep 1 done if pgrep -f "hastd: ${resource} \(secondary\)" >/dev/null 2>&1; then logger -p local0.error -t hast "Secondary process for resource ${resource} is still running after 30 seconds." exit 1 fi logger -p local0.debug -t hast "Secondary process in not running." # Change role to primary for our resource. out=`hastctl role primary "${resource}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to change to role to primary for resource ${resource}: ${out}." exit 1 fi # Wait few seconds for provider to appear. for i in `jot 50`; do [ -c "${device}" ] && break sleep 0.1 done if [ ! -c "${device}" ]; then logger -p local0.error -t hast "Device ${device} didn't appear." exit 1 fi logger -p local0.debug -t hast "Role for resource ${resource} changed to primary." case "${fstype}" in UFS) # Check the file system. fsck -y -t ufs "${device}" >/dev/null 2>&1 if [ $? -ne 0 ]; then logger -p local0.error -t hast "File system check for resource ${resource} failed." exit 1 fi logger -p local0.debug -t hast "File system check for resource ${resource} finished." # Mount the file system. out=`mount -t ufs "${device}" "${mountpoint}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "File system mount for resource ${resource} failed: ${out}." exit 1 fi logger -p local0.debug -t hast "File system for resource ${resource} mounted." ;; ZFS) # Import ZFS pool. Do it forcibly as it remembers hostid of # the other cluster node. out=`zpool import -f "${pool}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "ZFS pool import for resource ${resource} failed: ${out}." exit 1 fi logger -p local0.debug -t hast "ZFS pool for resource ${resource} imported." ;; esac logger -p local0.info -t hast "Successfully switched to primary for resource ${resource}." exit 0 Index: head/share/examples/ipfw/change_rules.sh =================================================================== --- head/share/examples/ipfw/change_rules.sh (revision 326274) +++ head/share/examples/ipfw/change_rules.sh (revision 326275) @@ -1,153 +1,155 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2000 Alexandre Peixoto # All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Change ipfw(8) rules with safety guarantees for remote operation # # Invoke this script to edit ${firewall_script}. It will call ${EDITOR}, # or vi(1) if the environment variable is not set, for you to edit # ${firewall_script}, ask for confirmation, and then run # ${firewall_script}. You can then examine the output of ipfw list and # confirm whether you want the new version or not. # # If no answer is received in 30 seconds, the previous # ${firewall_script} is run, restoring the old rules (this assumes ipfw # flush is present in it). # # If the new rules are confirmed, they'll replace ${firewall_script} and # the previous ones will be copied to ${firewall_script}.{date}. Mail # will also be sent to root with a unified diff of the rule change. # # Unapproved rules are kept in ${firewall_script}.new, and you are # offered the option of changing them instead of the present rules when # you call this script. # # This script could be improved by using version control # software. if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi EDITOR=${EDITOR:-/usr/bin/vi} PAGER=${PAGER:-/usr/bin/more} tempfoo=`basename $0` TMPFILE=`mktemp -t ${tempfoo}` || exit 1 get_yes_no() { while true do echo -n "$1 (Y/N) ? " read -t 30 a if [ $? != 0 ]; then a="No"; return; fi case $a in [Yy]) a="Yes"; return;; [Nn]) a="No"; return;; *);; esac done } restore_rules() { nohup sh ${firewall_script} /dev/null 2>&1 rm ${TMPFILE} exit 1 } case "${firewall_type}" in [Cc][Ll][Ii][Ee][Nn][Tt]|\ [Cc][Ll][Oo][Ss][Ee][Dd]|\ [Oo][Pp][Ee][Nn]|\ [Ss][Ii][Mm][Pp][Ll][Ee]|\ [Uu][Nn][Kk][Nn][Oo][Ww][Nn]) edit_file="${firewall_script}" rules_edit=no ;; *) if [ -r "${firewall_type}" ]; then edit_file="${firewall_type}" rules_edit=yes fi ;; esac if [ -f ${edit_file}.new ]; then get_yes_no "A new rules file already exists, do you want to use it" [ $a = 'No' ] && cp ${edit_file} ${edit_file}.new else cp ${edit_file} ${edit_file}.new fi trap restore_rules SIGHUP ${EDITOR} ${edit_file}.new get_yes_no "Do you want to install the new rules" [ $a = 'No' ] && exit 1 cat < ${TMPFILE} 2>&1 else nohup sh ${firewall_script}.new \ < /dev/null > ${TMPFILE} 2>&1 fi sleep 2; get_yes_no "Would you like to see the resulting new rules" [ $a = 'Yes' ] && ${PAGER} ${TMPFILE} get_yes_no "Type y to keep the new rules" [ $a != 'Yes' ] && restore_rules DATE=`date "+%Y%m%d%H%M"` cp ${edit_file} ${edit_file}.$DATE mv ${edit_file}.new ${edit_file} cat < #include #include #include #include #include #include "cdev.h" /* * This is the actual code for the system call... it can't be static because * it is exported to another part of the module... the only place it needs * to be referenced is the sysent we are interested in. * * To write your own system call using this as a template, you could strip * out this code and use the rest as a prototype module, changing only the * function names and the number of arguments to the call in the module * specific "sysent". * * You would have to use the "-R" option of "ld" to ensure a linkable file * if you were to do this, since you would need to combine multiple ".o" * files into a single ".o" file for use by "modload". */ #define CDEV_IOCTL1 _IOR('C', 1, u_int) /* Stores string recv'd by _write() */ static char buf[512+1]; static size_t len; int mydev_open(struct cdev *dev, int flag, int otyp, struct thread *td) { struct proc *procp = td->td_proc; printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n", dev2udev(dev), flag, otyp, procp); memset(&buf, '\0', 513); len = 0; return (0); } int mydev_close(struct cdev *dev, int flag, int otyp, struct thread *td) { struct proc *procp = td->td_proc; printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n", dev2udev(dev), flag, otyp, procp); return (0); } int mydev_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode, struct thread *td) { int error = 0; struct proc *procp = td->td_proc; printf("mydev_ioctl: dev_t=%d, cmd=%lx, arg=%p, mode=%x procp=%p\n", dev2udev(dev), cmd, arg, mode, procp); switch(cmd) { case CDEV_IOCTL1: printf("you called mydev_ioctl CDEV_IOCTL1\n"); break; default: printf("No such ioctl for me!\n"); error = EINVAL; break; } return (error); } /* * mydev_write takes in a character string and saves it * to buf for later accessing. */ int mydev_write(struct cdev *dev, struct uio *uio, int ioflag) { int err = 0; printf("mydev_write: dev_t=%d, uio=%p, ioflag=%d\n", dev2udev(dev), uio, ioflag); err = copyinstr(uio->uio_iov->iov_base, &buf, 512, &len); if (err != 0) { printf("Write to \"cdev\" failed.\n"); } return(err); } /* * The mydev_read function just takes the buf that was saved * via mydev_write() and returns it to userland for * accessing. */ int mydev_read(struct cdev *dev, struct uio *uio, int ioflag) { int err = 0; printf("mydev_read: dev_t=%d, uio=%p, ioflag=%d\n", dev2udev(dev), uio, ioflag); if (len <= 0) { err = -1; } else { /* copy buf to userland */ copystr(&buf, uio->uio_iov->iov_base, 513, &len); } return(err); } Index: head/share/examples/kld/cdev/module/cdev.h =================================================================== --- head/share/examples/kld/cdev/module/cdev.h (revision 326274) +++ head/share/examples/kld/cdev/module/cdev.h (revision 326275) @@ -1,81 +1,83 @@ /* 08 Nov 1998*/ -/* +/*- * cdev.h - header for sample kld module implementing a character device * driver. * * 08 Nov 1998 Rajesh Vaidheeswarran + * + * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 1998 Rajesh Vaidheeswarran * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Rajesh Vaidheeswarran. * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``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 RAJESH VAIDHEESWARRAN 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. * * Copyright (c) 1993 Terrence R. Lambert. * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Terrence R. Lambert. * 4. The name Terrence R. Lambert may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``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 TERRENCE R. LAMBERT 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. * * * $FreeBSD$ */ #ifndef __CDEV_H_ #define __CDEV_H_ d_open_t mydev_open; d_close_t mydev_close; d_ioctl_t mydev_ioctl; d_read_t mydev_read; d_write_t mydev_write; #endif Index: head/share/examples/kld/cdev/module/cdevmod.c =================================================================== --- head/share/examples/kld/cdev/module/cdevmod.c (revision 326274) +++ head/share/examples/kld/cdev/module/cdevmod.c (revision 326275) @@ -1,139 +1,141 @@ /* 08 Nov 1998*/ -/* +/*- * cdevmod.c - a sample kld module implementing a character device driver. * * 08 Nov 1998 Rajesh Vaidheeswarran + * + * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 1998 Rajesh Vaidheeswarran * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Rajesh Vaidheeswarran. * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``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 RAJESH VAIDHEESWARRAN 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. * * Copyright (c) 1993 Terrence R. Lambert. * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Terrence R. Lambert. * 4. The name Terrence R. Lambert may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``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 TERRENCE R. LAMBERT 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. * * * $FreeBSD$ */ #include #include #include #include #include #include "cdev.h" static struct cdevsw my_devsw = { /* version */ .d_version = D_VERSION, /* open */ .d_open = mydev_open, /* close */ .d_close = mydev_close, /* read */ .d_read = mydev_read, /* write */ .d_write = mydev_write, /* ioctl */ .d_ioctl = mydev_ioctl, /* name */ .d_name = "cdev" }; /* * Used as the variable that is the reference to our device * in devfs... we must keep this variable sane until we * call kldunload. */ static struct cdev *sdev; /* * This function is called each time the module is loaded or unloaded. * Since we are a miscellaneous module, we have to provide whatever * code is necessary to patch ourselves into the area we are being * loaded to change. * * The stat information is basically common to all modules, so there * is no real issue involved with stat; we will leave it lkm_nullcmd(), * since we don't have to do anything about it. */ static int cdev_load(module_t mod, int cmd, void *arg) { int err = 0; switch (cmd) { case MOD_LOAD: /* Do any initialization that you should do with the kernel */ /* if we make it to here, print copyright on console*/ printf("\nSample Loaded kld character device driver\n"); printf("Copyright (c) 1998\n"); printf("Rajesh Vaidheeswarran\n"); printf("All rights reserved\n"); sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev"); break; /* Success*/ case MOD_UNLOAD: printf("Unloaded kld character device driver\n"); destroy_dev(sdev); break; /* Success*/ default: /* we only understand load/unload*/ err = EOPNOTSUPP; break; } return(err); } /* Now declare the module to the system */ DEV_MODULE(cdev, cdev_load, NULL); Index: head/share/examples/kld/cdev/test/testcdev.c =================================================================== --- head/share/examples/kld/cdev/test/testcdev.c (revision 326274) +++ head/share/examples/kld/cdev/test/testcdev.c (revision 326275) @@ -1,125 +1,127 @@ /* 08 Nov 1998*/ -/* +/*- * testmisc.c * * Test program to call the sample loaded kld device driver. * * 05 Jun 93 Rajesh Vaidheeswarran Original * + * + * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 1993 Rajesh Vaidheeswarran. * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Rajesh Vaidheeswarran. * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``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 RAJESH VAIDHEESWARRAN 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. * * Copyright (c) 1993 Terrence R. Lambert. * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Terrence R. Lambert. * 4. The name Terrence R. Lambert may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``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 TERRENCE R. LAMBERT 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. * * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #define CDEV_IOCTL1 _IOR('C', 1, u_int) #define CDEV_DEVICE "cdev" static char writestr[] = "Hello kernel!"; static char buf[512+1]; int main(int argc __unused, char *argv[] __unused) { int kernel_fd; int one; int len; if ((kernel_fd = open("/dev/" CDEV_DEVICE, O_RDWR)) == -1) { perror("/dev/" CDEV_DEVICE); exit(1); } /* Send ioctl */ if (ioctl(kernel_fd, CDEV_IOCTL1, &one) == -1) { perror("CDEV_IOCTL1"); } else { printf( "Sent ioctl CDEV_IOCTL1 to device %s%s\n", _PATH_DEV, CDEV_DEVICE); } len = strlen(writestr) + 1; /* Write operation */ if (write(kernel_fd, writestr, len) == -1) { perror("write()"); } else { printf("Written \"%s\" string to device /dev/" CDEV_DEVICE "\n", writestr); } /* Read operation */ if (read(kernel_fd, buf, len) == -1) { perror("read()"); } else { printf("Read \"%s\" string from device /dev/" CDEV_DEVICE "\n", buf); } exit(0); } Index: head/share/examples/kld/dyn_sysctl/dyn_sysctl.c =================================================================== --- head/share/examples/kld/dyn_sysctl/dyn_sysctl.c (revision 326274) +++ head/share/examples/kld/dyn_sysctl/dyn_sysctl.c (revision 326275) @@ -1,169 +1,171 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * * Copyright (c) 2000 Andrzej Bialecki * All rights reserved. * * 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include #include #include /* Some example data */ static long a = 100; static int b = 200; static char *c = "hi there from dyn_sysctl"; static struct sysctl_oid *a_root, *a_root1, *b_root; static struct sysctl_ctx_list clist, clist1, clist2; static int sysctl_dyn_sysctl_test(SYSCTL_HANDLER_ARGS) { char *buf = "let's produce some text..."; return (sysctl_handle_string(oidp, buf, strlen(buf), req)); } /* * The function called at load/unload. */ static int load(module_t mod, int cmd, void *arg) { int error; error = 0; switch (cmd) { case MOD_LOAD: /* Initialize the contexts */ printf("Initializing contexts and creating subtrees.\n\n"); sysctl_ctx_init(&clist); sysctl_ctx_init(&clist1); sysctl_ctx_init(&clist2); /* * Create two partially overlapping subtrees, belonging * to different contexts. */ printf("TREE ROOT NAME\n"); a_root = SYSCTL_ADD_NODE(&clist, SYSCTL_STATIC_CHILDREN(/* top of sysctl tree */), OID_AUTO, "dyn_sysctl", CTLFLAG_RW, 0, "dyn_sysctl root node"); a_root = SYSCTL_ADD_NODE(&clist1, SYSCTL_STATIC_CHILDREN(/* top of sysctl tree */), OID_AUTO, "dyn_sysctl", CTLFLAG_RW, 0, "dyn_sysctl root node"); if (a_root == NULL) { printf("SYSCTL_ADD_NODE failed!\n"); return (EINVAL); } SYSCTL_ADD_LONG(&clist, SYSCTL_CHILDREN(a_root), OID_AUTO, "long_a", CTLFLAG_RW, &a, "just to try"); SYSCTL_ADD_INT(&clist, SYSCTL_CHILDREN(a_root), OID_AUTO, "int_b", CTLFLAG_RW, &b, 0, "just to try 1"); a_root1 = SYSCTL_ADD_NODE(&clist, SYSCTL_CHILDREN(a_root), OID_AUTO, "nextlevel", CTLFLAG_RD, 0, "one level down"); SYSCTL_ADD_STRING(&clist, SYSCTL_CHILDREN(a_root1), OID_AUTO, "string_c", CTLFLAG_RD, c, 0, "just to try 2"); printf("1. (%p) / dyn_sysctl\n", &clist); /* Add a subtree under already existing category */ a_root1 = SYSCTL_ADD_NODE(&clist, SYSCTL_STATIC_CHILDREN(_kern), OID_AUTO, "dyn_sysctl", CTLFLAG_RW, 0, "dyn_sysctl root node"); if (a_root1 == NULL) { printf("SYSCTL_ADD_NODE failed!\n"); return (EINVAL); } SYSCTL_ADD_PROC(&clist, SYSCTL_CHILDREN(a_root1), OID_AUTO, "procedure", CTLTYPE_STRING | CTLFLAG_RD, NULL, 0, sysctl_dyn_sysctl_test, "A", "I can be here, too"); printf(" (%p) /kern dyn_sysctl\n", &clist); /* Overlap second tree with the first. */ b_root = SYSCTL_ADD_NODE(&clist1, SYSCTL_CHILDREN(a_root), OID_AUTO, "nextlevel", CTLFLAG_RD, 0, "one level down"); SYSCTL_ADD_STRING(&clist1, SYSCTL_CHILDREN(b_root), OID_AUTO, "string_c1", CTLFLAG_RD, c, 0, "just to try 2"); printf("2. (%p) / dyn_sysctl (overlapping #1)\n", &clist1); /* * And now do something stupid. Connect another subtree to * dynamic oid. * WARNING: this is an example of WRONG use of dynamic sysctls. */ b_root=SYSCTL_ADD_NODE(&clist2, SYSCTL_CHILDREN(a_root1), OID_AUTO, "bad", CTLFLAG_RW, 0, "dependent node"); SYSCTL_ADD_STRING(&clist2, SYSCTL_CHILDREN(b_root), OID_AUTO, "string_c", CTLFLAG_RD, c, 0, "shouldn't panic"); printf("3. (%p) /kern/dyn_sysctl bad (WRONG!)\n", &clist2); break; case MOD_UNLOAD: printf("1. Try to free ctx1 (%p): ", &clist); if (sysctl_ctx_free(&clist) != 0) printf("failed: expected. Need to remove ctx3 first.\n"); else printf("HELP! sysctl_ctx_free(%p) succeeded. EXPECT PANIC!!!\n", &clist); printf("2. Try to free ctx3 (%p): ", &clist2); if (sysctl_ctx_free(&clist2) != 0) { printf("sysctl_ctx_free(%p) failed!\n", &clist2); /* Remove subtree forcefully... */ sysctl_remove_oid(b_root, 1, 1); printf("sysctl_remove_oid(%p) succeeded\n", b_root); } else printf("Ok\n"); printf("3. Try to free ctx1 (%p) again: ", &clist); if (sysctl_ctx_free(&clist) != 0) { printf("sysctl_ctx_free(%p) failed!\n", &clist); /* Remove subtree forcefully... */ sysctl_remove_oid(a_root1, 1, 1); printf("sysctl_remove_oid(%p) succeeded\n", a_root1); } else printf("Ok\n"); printf("4. Try to free ctx2 (%p): ", &clist1); if (sysctl_ctx_free(&clist1) != 0) { printf("sysctl_ctx_free(%p) failed!\n", &clist1); /* Remove subtree forcefully... */ sysctl_remove_oid(a_root, 1, 1); } else printf("Ok\n"); break; default: error = EOPNOTSUPP; break; } return (error); } static moduledata_t mod_data = { "dyn_sysctl", load, 0 }; DECLARE_MODULE(dyn_sysctl, mod_data, SI_SUB_EXEC, SI_ORDER_ANY); Index: head/share/examples/kld/firmware/fwconsumer/fw_consumer.c =================================================================== --- head/share/examples/kld/firmware/fwconsumer/fw_consumer.c (revision 326274) +++ head/share/examples/kld/firmware/fwconsumer/fw_consumer.c (revision 326275) @@ -1,78 +1,80 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * * Copyright (c) 2006, Max Laier * All rights reserved. * * 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 unmodified, 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 BY THE AUTHOR ``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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include static const struct firmware *fp; static int fw_consumer_modevent(module_t mod, int type, void *unused) { switch (type) { case MOD_LOAD: fp = firmware_get("beastie"); if (fp == NULL) return (ENOENT); if (((const char *)fp->data)[fp->datasize - 1] != '\0') { firmware_put(fp, FIRMWARE_UNLOAD); return (EINVAL); } printf("%s", (const char *)fp->data); return (0); case MOD_UNLOAD: printf("Bye!\n"); if (fp != NULL) { printf("%s", (const char *)fp->data); firmware_put(fp, FIRMWARE_UNLOAD); } return (0); } return (EINVAL); } static moduledata_t fw_consumer_mod = { "fw_consumer", fw_consumer_modevent, 0 }; DECLARE_MODULE(fw_consumer, fw_consumer_mod, SI_SUB_DRIVERS, SI_ORDER_ANY); MODULE_VERSION(fw_consumer, 1); MODULE_DEPEND(fw_consumer, firmware, 1, 1, 1); Index: head/share/examples/kld/khelp/h_example.c =================================================================== --- head/share/examples/kld/khelp/h_example.c (revision 326274) +++ head/share/examples/kld/khelp/h_example.c (revision 326275) @@ -1,154 +1,156 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 2010-2011 The FreeBSD Foundation * All rights reserved. * * This software was developed at the Centre for Advanced Internet * Architectures, Swinburne University of Technology, Melbourne, Australia by * Lawrence Stewart under sponsorship from the FreeBSD Foundation. * * 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. */ /* * This example Khelp module uses the helper hook points available in the TCP * stack to calculate a per-connection count of inbound and outbound packets * when the connection is in the established state. The code is verbosely * documented in an attempt to explain how everything fits together. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include /* * Function prototype for our helper hook (man 9 hhook) compatible hook * function. */ static int example_hook(int hhook_type, int hhook_id, void *udata, void *ctx_data, void *hdata, struct osd *hosd); /* * Our per-connection persistent data storage struct. */ struct example { uint32_t est_in_count; uint32_t est_out_count; }; /* * Fill in the required bits of our module's struct helper (defined in * ). * * - Our helper will be storing persistent state for each TCP connection, so we * request the use the Object Specific Data (OSD) feature from the framework by * setting the HELPER_NEEDS_OSD flag. * * - Our helper is related to the TCP subsystem, so tell the Khelp framework * this by setting an appropriate class for the module. When a new TCP * connection is created, the Khelp framework takes care of associating helper * modules of the appropriate class with the new connection. */ struct helper example_helper = { .h_flags = HELPER_NEEDS_OSD, .h_classes = HELPER_CLASS_TCP }; /* * Set which helper hook points our module wants to hook by creating an array of * hookinfo structs (defined in ). We hook the TCP established * inbound/outbound hook points (TCP hhook points are defined in * ) with our example_hook() function. We don't require a user * data pointer to be passed to our hook function when called, so we set it to * NULL. */ struct hookinfo example_hooks[] = { { .hook_type = HHOOK_TYPE_TCP, .hook_id = HHOOK_TCP_EST_IN, .hook_udata = NULL, .hook_func = &example_hook }, { .hook_type = HHOOK_TYPE_TCP, .hook_id = HHOOK_TCP_EST_OUT, .hook_udata = NULL, .hook_func = &example_hook } }; /* * Very simple helper hook function. Here's a quick run through the arguments: * * - hhook_type and hhook_id are useful if you use a single function with many * hook points and want to know which hook point called the function. * * - udata will be NULL, because we didn't elect to pass a pointer in either of * the hookinfo structs we instantiated above in the example_hooks array. * * - ctx_data contains context specific data from the hook point call site. The * data type passed is subsystem dependent. In the case of TCP, the hook points * pass a pointer to a "struct tcp_hhook_data" (defined in ). * * - hdata is a pointer to the persistent per-object storage for our module. The * pointer is allocated automagically by the Khelp framework when the connection * is created, and comes from a dedicated UMA zone. It will never be NULL. * * - hosd can be used with the Khelp framework's khelp_get_osd() function to * access data belonging to a different Khelp module. */ static int example_hook(int hhook_type, int hhook_id, void *udata, void *ctx_data, void *hdata, struct osd *hosd) { struct example *data; data = hdata; if (hhook_id == HHOOK_TCP_EST_IN) data->est_in_count++; else if (hhook_id == HHOOK_TCP_EST_OUT) data->est_out_count++; return (0); } /* * We use a convenient macro which handles registering our module with the Khelp * framework. Note that Khelp modules which set the HELPER_NEEDS_OSD flag (i.e. * require persistent per-object storage) must use the KHELP_DECLARE_MOD_UMA() * macro. If you don't require per-object storage, use the KHELP_DECLARE_MOD() * macro instead. */ KHELP_DECLARE_MOD_UMA(example, &example_helper, example_hooks, 1, sizeof(struct example), NULL, NULL); Index: head/share/examples/kld/random_adaptor/random_adaptor_example.c =================================================================== --- head/share/examples/kld/random_adaptor/random_adaptor_example.c (revision 326274) +++ head/share/examples/kld/random_adaptor/random_adaptor_example.c (revision 326275) @@ -1,125 +1,127 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 2013 Arthur Mesh * All rights reserved. * * 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 * in this position and unchanged. * 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 BY THE AUTHOR ``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. * */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include static void live_random_example_init(void); static void live_random_example_deinit(void); static u_int live_random_example_read(void *, u_int); struct random_adaptor live_random_example = { .les_ident = "Example RNG", .les_source = RANDOM_PURE_BOGUS, /* Make sure this is in * sys/random.h and is unique */ .les_read = live_random_example_read, }; /* * Used under the license provided @ http://xkcd.com/221/ * http://creativecommons.org/licenses/by-nc/2.5/ */ static uint8_t getRandomNumber(void) { return 4; /* chosen by fair dice roll, guaranteed to be random */ } static void live_random_example_init(void) { /* Do initialisation stuff here */ } static void live_random_example_deinit(void) { /* Do de-initialisation stuff here */ } /* get bytes of random stuff into . You may presume * that is a multiple of 2^n, with n>=3. A typical value * is c=16. */ static u_int live_random_example_read(void *buf, u_int c) { uint8_t *b; int count; b = buf; for (count = 0; count < c; count++) b[count] = getRandomNumber(); /* printf("returning %d bytes of pure randomness\n", c); */ return (c); } /* ARGSUSED */ static int live_random_example_modevent(module_t mod __unused, int type, void *unused __unused) { int error = 0; switch (type) { case MOD_LOAD: live_entropy_source_register(&live_random_example); break; case MOD_UNLOAD: live_entropy_source_deregister(&live_random_example); break; case MOD_SHUTDOWN: break; default: error = EOPNOTSUPP; break; } return (error); } DEV_MODULE(live_random_example, live_random_example_modevent, NULL); MODULE_VERSION(live_random_example, 1); MODULE_DEPEND(live_random_example, randomdev, 1, 1, 1); Index: head/share/examples/kld/syscall/module/syscall.c =================================================================== --- head/share/examples/kld/syscall/module/syscall.c (revision 326274) +++ head/share/examples/kld/syscall/module/syscall.c (revision 326275) @@ -1,83 +1,85 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 1999 Assar Westerlund * All rights reserved. * * 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include #include #include #include /* * The function for implementing the syscall. */ static int hello(struct thread *td, void *arg) { printf("hello kernel\n"); return (0); } /* * The `sysent' for the new syscall */ static struct sysent hello_sysent = { 0, /* sy_narg */ hello /* sy_call */ }; /* * The offset in sysent where the syscall is allocated. */ static int offset = NO_SYSCALL; /* * The function called at load/unload. */ static int load(struct module *module, int cmd, void *arg) { int error = 0; switch (cmd) { case MOD_LOAD : printf("syscall loaded at %d\n", offset); break; case MOD_UNLOAD : printf("syscall unloaded from %d\n", offset); break; default : error = EOPNOTSUPP; break; } return (error); } SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL); Index: head/share/examples/kld/syscall/test/call.c =================================================================== --- head/share/examples/kld/syscall/test/call.c (revision 326274) +++ head/share/examples/kld/syscall/test/call.c (revision 326275) @@ -1,51 +1,53 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 1999 Assar Westerlund * All rights reserved. * * 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include #include #include #include int main(int argc __unused, char **argv __unused) { int modid, syscall_num; struct module_stat stat; stat.version = sizeof(stat); if ((modid = modfind("sys/syscall")) == -1) err(1, "modfind"); if (modstat(modid, &stat) != 0) err(1, "modstat"); syscall_num = stat.data.intval; return syscall (syscall_num); } Index: head/share/examples/libvgl/demo.c =================================================================== --- head/share/examples/libvgl/demo.c (revision 326274) +++ head/share/examples/libvgl/demo.c (revision 326275) @@ -1,122 +1,124 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 1991-1997 Søren Schmidt * All rights reserved. * * 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 * in this position and unchanged. * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. * * $FreeBSD$ */ #include #include #include #include #include int main(int argc, char **argv) { int y, xsize, ysize, i,j; VGLBitmap *tmp; // set graphics mode, here 320x240 256 colors // supported modes are (from ): // SW_VGA_CG320: std VGA 320x200 256 colors // SW_VGA_MODEX: Modex VGA 320x240 256 colors // SW_VGA_VG640: std VGA 640x480 16 colors VGLInit(SW_VGA_MODEX); // initialize mouse and show pointer VGLMouseInit(VGL_MOUSESHOW); // VGLDisplay is a ptr to a struct Bitmap defined and initialized by // libvgl. The Bitmap points directly to screen memory etc. xsize=VGLDisplay->Xsize; ysize=VGLDisplay->Ysize; // alloc a new bitmap tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); VGLBitmapAllocateBits(tmp); VGLClear(tmp, 0); // fill the screen with colored lines for (y=0; yBitmap[i+256*j] = i%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = j%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); sleep(5); i=0; // loop around drawing and copying while (++i) { VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize); VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize, rand()%256); VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize/2, rand()%ysize/2, rand()%256); rand(); if (i > 1000) break; } // restore screen to its original mode VGLEnd(); return 0; } Index: head/share/examples/scsi_target/scsi_cmds.c =================================================================== --- head/share/examples/scsi_target/scsi_cmds.c (revision 326274) +++ head/share/examples/scsi_target/scsi_cmds.c (revision 326275) @@ -1,813 +1,815 @@ -/* +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * SCSI Disk Emulator * * Copyright (c) 2002 Nate Lawson. * All rights reserved. * * 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, * without modification, immediately at the beginning of the file. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "scsi_target.h" typedef int targ_start_func(struct ccb_accept_tio *, struct ccb_scsiio *); typedef void targ_done_func(struct ccb_accept_tio *, struct ccb_scsiio *, io_ops); #ifndef REPORT_LUNS #define REPORT_LUNS 0xa0 #endif struct targ_cdb_handlers { u_int8_t cmd; targ_start_func *start; targ_done_func *done; #define ILLEGAL_CDB 0xFF }; static targ_start_func tcmd_inquiry; static targ_start_func tcmd_req_sense; static targ_start_func tcmd_rd_cap; #ifdef READ_16 static targ_start_func tcmd_rd_cap16; #endif static targ_start_func tcmd_rdwr; static targ_start_func tcmd_rdwr_decode; static targ_done_func tcmd_rdwr_done; static targ_start_func tcmd_null_ok; static targ_start_func tcmd_illegal_req; static int start_io(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, int dir); static int init_inquiry(u_int16_t req_flags, u_int16_t sim_flags); static struct initiator_state * tcmd_get_istate(u_int init_id); static void cdb_debug(u_int8_t *cdb, const char *msg, ...); static struct targ_cdb_handlers cdb_handlers[] = { { READ_10, tcmd_rdwr, tcmd_rdwr_done }, { WRITE_10, tcmd_rdwr, tcmd_rdwr_done }, { READ_6, tcmd_rdwr, tcmd_rdwr_done }, { WRITE_6, tcmd_rdwr, tcmd_rdwr_done }, { INQUIRY, tcmd_inquiry, NULL }, { REQUEST_SENSE, tcmd_req_sense, NULL }, { READ_CAPACITY, tcmd_rd_cap, NULL }, { TEST_UNIT_READY, tcmd_null_ok, NULL }, { START_STOP_UNIT, tcmd_null_ok, NULL }, { SYNCHRONIZE_CACHE, tcmd_null_ok, NULL }, { MODE_SENSE_6, tcmd_illegal_req, NULL }, { MODE_SELECT_6, tcmd_illegal_req, NULL }, { REPORT_LUNS, tcmd_illegal_req, NULL }, #ifdef READ_16 { READ_16, tcmd_rdwr, tcmd_rdwr_done }, { WRITE_16, tcmd_rdwr, tcmd_rdwr_done }, { SERVICE_ACTION_IN, tcmd_rd_cap16, NULL }, #endif { ILLEGAL_CDB, NULL, NULL } }; static struct scsi_inquiry_data inq_data; static struct initiator_state istates[MAX_INITIATORS]; extern int debug; extern off_t volume_size; extern u_int sector_size; extern size_t buf_size; cam_status tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags) { struct initiator_state *istate; int i, ret; /* Initialize our inquiry data */ ret = init_inquiry(req_inq_flags, sim_inq_flags); if (ret != 0) return (ret); /* We start out life with a UA to indicate power-on/reset. */ for (i = 0; i < MAX_INITIATORS; i++) { istate = tcmd_get_istate(i); bzero(istate, sizeof(*istate)); istate->pending_ua = UA_POWER_ON; } return (0); } /* Caller allocates CTIO, sets its init_id return 0 if done, 1 if more processing needed on 0, caller sets SEND_STATUS */ int tcmd_handle(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, io_ops event) { static struct targ_cdb_handlers *last_cmd; struct initiator_state *istate; struct atio_descr *a_descr; int ret; if (debug) { warnx("tcmd_handle atio %p ctio %p atioflags %#x", atio, ctio, atio->ccb_h.flags); } ret = 0; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; /* Do a full lookup if one-behind cache failed */ if (last_cmd == NULL || last_cmd->cmd != a_descr->cdb[0]) { struct targ_cdb_handlers *h; for (h = cdb_handlers; h->cmd != ILLEGAL_CDB; h++) { if (a_descr->cdb[0] == h->cmd) break; } last_cmd = h; } /* call completion and exit */ if (event != ATIO_WORK) { if (last_cmd->done != NULL) last_cmd->done(atio, ctio, event); else free_ccb((union ccb *)ctio); return (1); } if (last_cmd->cmd == ILLEGAL_CDB) { if (event != ATIO_WORK) { warnx("no done func for %#x???", a_descr->cdb[0]); abort(); } /* Not found, return illegal request */ warnx("cdb %#x not handled", a_descr->cdb[0]); tcmd_illegal_req(atio, ctio); send_ccb((union ccb *)ctio, /*priority*/1); return (0); } istate = tcmd_get_istate(ctio->init_id); if (istate == NULL) { tcmd_illegal_req(atio, ctio); send_ccb((union ccb *)ctio, /*priority*/1); return (0); } if (istate->pending_ca == 0 && istate->pending_ua != 0 && a_descr->cdb[0] != INQUIRY) { tcmd_sense(ctio->init_id, ctio, SSD_KEY_UNIT_ATTENTION, 0x29, istate->pending_ua == UA_POWER_ON ? 1 : 2); istate->pending_ca = CA_UNIT_ATTN; if (debug) { cdb_debug(a_descr->cdb, "UA active for %u: ", atio->init_id); } send_ccb((union ccb *)ctio, /*priority*/1); return (0); } /* Store current CA and UA for later */ istate->orig_ua = istate->pending_ua; istate->orig_ca = istate->pending_ca; /* * As per SAM2, any command that occurs * after a CA is reported, clears the CA. We must * also clear the UA condition, if any, that caused * the CA to occur assuming the UA is not for a * persistent condition. */ istate->pending_ca = CA_NONE; if (istate->orig_ca == CA_UNIT_ATTN) istate->pending_ua = UA_NONE; /* If we have a valid handler, call start or completion function */ if (last_cmd->cmd != ILLEGAL_CDB) { ret = last_cmd->start(atio, ctio); /* XXX hack */ if (last_cmd->start != tcmd_rdwr) { a_descr->init_req += ctio->dxfer_len; send_ccb((union ccb *)ctio, /*priority*/1); } } return (ret); } static struct initiator_state * tcmd_get_istate(u_int init_id) { if (init_id >= MAX_INITIATORS) { warnx("illegal init_id %d, max %d", init_id, MAX_INITIATORS - 1); return (NULL); } else { return (&istates[init_id]); } } void tcmd_sense(u_int init_id, struct ccb_scsiio *ctio, u_int8_t flags, u_int8_t asc, u_int8_t ascq) { struct initiator_state *istate; struct scsi_sense_data_fixed *sense; /* Set our initiator's istate */ istate = tcmd_get_istate(init_id); if (istate == NULL) return; istate->pending_ca |= CA_CMD_SENSE; /* XXX set instead of or? */ sense = (struct scsi_sense_data_fixed *)&istate->sense_data; bzero(sense, sizeof(*sense)); sense->error_code = SSD_CURRENT_ERROR; sense->flags = flags; sense->add_sense_code = asc; sense->add_sense_code_qual = ascq; sense->extra_len = offsetof(struct scsi_sense_data_fixed, sense_key_spec[2]) - offsetof(struct scsi_sense_data_fixed, extra_len); /* Fill out the supplied CTIO */ if (ctio != NULL) { bcopy(sense, &ctio->sense_data, sizeof(*sense)); ctio->sense_len = sizeof(*sense); /* XXX */ ctio->ccb_h.flags &= ~CAM_DIR_MASK; ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_SENSE | CAM_SEND_STATUS; ctio->dxfer_len = 0; ctio->scsi_status = SCSI_STATUS_CHECK_COND; } } void tcmd_ua(u_int init_id, ua_types new_ua) { struct initiator_state *istate; u_int start, end; if (init_id == CAM_TARGET_WILDCARD) { start = 0; end = MAX_INITIATORS - 1; } else { start = end = init_id; } for (; start <= end; start++) { istate = tcmd_get_istate(start); if (istate == NULL) break; istate->pending_ua = new_ua; } } static int tcmd_inquiry(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { struct scsi_inquiry *inq; struct atio_descr *a_descr; struct initiator_state *istate; struct scsi_sense_data_fixed *sense; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; inq = (struct scsi_inquiry *)a_descr->cdb; if (debug) cdb_debug(a_descr->cdb, "INQUIRY from %u: ", atio->init_id); /* * Validate the command. We don't support any VPD pages, so * complain if EVPD or CMDDT is set. */ istate = tcmd_get_istate(ctio->init_id); sense = (struct scsi_sense_data_fixed *)&istate->sense_data; if ((inq->byte2 & SI_EVPD) != 0) { tcmd_illegal_req(atio, ctio); sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD | SSD_BITPTR_VALID | /*bit value*/1; sense->sense_key_spec[1] = 0; sense->sense_key_spec[2] = offsetof(struct scsi_inquiry, byte2); } else if (inq->page_code != 0) { tcmd_illegal_req(atio, ctio); sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD; sense->sense_key_spec[1] = 0; sense->sense_key_spec[2] = offsetof(struct scsi_inquiry, page_code); } else { bcopy(&inq_data, ctio->data_ptr, sizeof(inq_data)); ctio->dxfer_len = inq_data.additional_length + 4; ctio->dxfer_len = min(ctio->dxfer_len, scsi_2btoul(inq->length)); ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; } return (0); } /* Initialize the inquiry response structure with the requested flags */ static int init_inquiry(u_int16_t req_flags, u_int16_t sim_flags) { struct scsi_inquiry_data *inq; inq = &inq_data; bzero(inq, sizeof(*inq)); inq->device = T_DIRECT | (SID_QUAL_LU_CONNECTED << 5); #ifdef SCSI_REV_SPC inq->version = SCSI_REV_SPC; /* was 2 */ #else inq->version = SCSI_REV_3; /* was 2 */ #endif /* * XXX cpi.hba_inquiry doesn't support Addr16 so we give the * user what they want if they ask for it. */ if ((req_flags & SID_Addr16) != 0) { sim_flags |= SID_Addr16; warnx("Not sure SIM supports Addr16 but enabling it anyway"); } /* Advertise only what the SIM can actually support */ req_flags &= sim_flags; scsi_ulto2b(req_flags, &inq->spc2_flags); inq->response_format = 2; /* SCSI2 Inquiry Format */ inq->additional_length = SHORT_INQUIRY_LENGTH - offsetof(struct scsi_inquiry_data, additional_length); bcopy("FreeBSD ", inq->vendor, SID_VENDOR_SIZE); bcopy("Emulated Disk ", inq->product, SID_PRODUCT_SIZE); bcopy("0.1 ", inq->revision, SID_REVISION_SIZE); return (0); } static int tcmd_req_sense(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { struct scsi_request_sense *rsense; struct scsi_sense_data_fixed *sense; struct initiator_state *istate; size_t dlen; struct atio_descr *a_descr; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; rsense = (struct scsi_request_sense *)a_descr->cdb; istate = tcmd_get_istate(ctio->init_id); sense = (struct scsi_sense_data_fixed *)&istate->sense_data; if (debug) { cdb_debug(a_descr->cdb, "REQ SENSE from %u: ", atio->init_id); warnx("Sending sense: %#x %#x %#x", sense->flags, sense->add_sense_code, sense->add_sense_code_qual); } if (istate->orig_ca == 0) { tcmd_sense(ctio->init_id, NULL, SSD_KEY_NO_SENSE, 0, 0); warnx("REQUEST SENSE from %u but no pending CA!", ctio->init_id); } bcopy(sense, ctio->data_ptr, sizeof(struct scsi_sense_data)); dlen = offsetof(struct scsi_sense_data_fixed, extra_len) + sense->extra_len + 1; ctio->dxfer_len = min(dlen, SCSI_CDB6_LEN(rsense->length)); ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; return (0); } static int tcmd_rd_cap(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { struct scsi_read_capacity_data *srp; struct atio_descr *a_descr; uint32_t vsize; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; srp = (struct scsi_read_capacity_data *)ctio->data_ptr; if (volume_size > 0xffffffff) vsize = 0xffffffff; else vsize = (uint32_t)(volume_size - 1); if (debug) { cdb_debug(a_descr->cdb, "READ CAP from %u (%u, %u): ", atio->init_id, vsize, sector_size); } bzero(srp, sizeof(*srp)); scsi_ulto4b(vsize, srp->addr); scsi_ulto4b(sector_size, srp->length); ctio->dxfer_len = sizeof(*srp); ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; return (0); } #ifdef READ_16 static int tcmd_rd_cap16(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { struct scsi_read_capacity_16 *scsi_cmd; struct scsi_read_capacity_data_long *srp; struct atio_descr *a_descr; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; scsi_cmd = (struct scsi_read_capacity_16 *)a_descr->cdb; srp = (struct scsi_read_capacity_data_long *)ctio->data_ptr; if (scsi_cmd->service_action != SRC16_SERVICE_ACTION) { tcmd_illegal_req(atio, ctio); return (0); } if (debug) { cdb_debug(a_descr->cdb, "READ CAP16 from %u (%u, %u): ", atio->init_id, volume_size - 1, sector_size); } bzero(srp, sizeof(*srp)); scsi_u64to8b(volume_size - 1, srp->addr); scsi_ulto4b(sector_size, srp->length); ctio->dxfer_len = sizeof(*srp); ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; return (0); } #endif static int tcmd_rdwr(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { struct atio_descr *a_descr; struct ctio_descr *c_descr; int ret; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; /* Command needs to be decoded */ if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_BOTH) { if (debug) warnx("Calling rdwr_decode"); ret = tcmd_rdwr_decode(atio, ctio); if (ret == 0) { send_ccb((union ccb *)ctio, /*priority*/1); return (0); } } ctio->ccb_h.flags |= a_descr->flags; /* Call appropriate work function */ if ((a_descr->flags & CAM_DIR_IN) != 0) { ret = start_io(atio, ctio, CAM_DIR_IN); if (debug) warnx("Starting %p DIR_IN @" OFF_FMT ":%u", a_descr, c_descr->offset, a_descr->targ_req); } else { ret = start_io(atio, ctio, CAM_DIR_OUT); if (debug) warnx("Starting %p DIR_OUT @" OFF_FMT ":%u", a_descr, c_descr->offset, a_descr->init_req); } return (ret); } static int tcmd_rdwr_decode(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { uint64_t blkno; uint32_t count; struct atio_descr *a_descr; u_int8_t *cdb; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; cdb = a_descr->cdb; if (debug) cdb_debug(cdb, "R/W from %u: ", atio->init_id); switch (cdb[0]) { case READ_6: case WRITE_6: { struct scsi_rw_6 *rw_6 = (struct scsi_rw_6 *)cdb; blkno = scsi_3btoul(rw_6->addr); count = rw_6->length; break; } case READ_10: case WRITE_10: { struct scsi_rw_10 *rw_10 = (struct scsi_rw_10 *)cdb; blkno = scsi_4btoul(rw_10->addr); count = scsi_2btoul(rw_10->length); break; } #ifdef READ_16 case READ_16: case WRITE_16: { struct scsi_rw_16 *rw_16 = (struct scsi_rw_16 *)cdb; blkno = scsi_8btou64(rw_16->addr); count = scsi_4btoul(rw_16->length); break; } #endif default: tcmd_illegal_req(atio, ctio); return (0); } if (blkno + count > volume_size) { warnx("Attempt to access past end of volume"); tcmd_sense(ctio->init_id, ctio, SSD_KEY_ILLEGAL_REQUEST, 0x21, 0); return (0); } /* Get an (overall) data length and set direction */ a_descr->base_off = ((off_t)blkno) * sector_size; a_descr->total_len = count * sector_size; if (a_descr->total_len == 0) { if (debug) warnx("r/w 0 blocks @ blkno " OFF_FMT, blkno); tcmd_null_ok(atio, ctio); return (0); } else if (cdb[0] == WRITE_6 || cdb[0] == WRITE_10) { a_descr->flags |= CAM_DIR_OUT; if (debug) warnx("write %u blocks @ blkno " OFF_FMT, count, blkno); } else { a_descr->flags |= CAM_DIR_IN; if (debug) warnx("read %u blocks @ blkno " OFF_FMT, count, blkno); } return (1); } static int start_io(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, int dir) { struct atio_descr *a_descr; struct ctio_descr *c_descr; int ret; /* Set up common structures */ a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; if (dir == CAM_DIR_IN) { c_descr->offset = a_descr->base_off + a_descr->targ_req; ctio->dxfer_len = a_descr->total_len - a_descr->targ_req; } else { c_descr->offset = a_descr->base_off + a_descr->init_req; ctio->dxfer_len = a_descr->total_len - a_descr->init_req; } ctio->dxfer_len = min(ctio->dxfer_len, buf_size); assert(ctio->dxfer_len >= 0); c_descr->aiocb.aio_offset = c_descr->offset; c_descr->aiocb.aio_nbytes = ctio->dxfer_len; /* If DIR_IN, start read from target, otherwise begin CTIO xfer. */ ret = 1; if (dir == CAM_DIR_IN) { if (notaio) { if (debug) warnx("read sync %lu @ block " OFF_FMT, (unsigned long) (ctio->dxfer_len / sector_size), c_descr->offset / sector_size); if (lseek(c_descr->aiocb.aio_fildes, c_descr->aiocb.aio_offset, SEEK_SET) < 0) { perror("lseek"); err(1, "lseek"); } if (read(c_descr->aiocb.aio_fildes, (void *)c_descr->aiocb.aio_buf, ctio->dxfer_len) != ctio->dxfer_len) { err(1, "read"); } } else { if (debug) warnx("read async %lu @ block " OFF_FMT, (unsigned long) (ctio->dxfer_len / sector_size), c_descr->offset / sector_size); if (aio_read(&c_descr->aiocb) < 0) { err(1, "aio_read"); /* XXX */ } } a_descr->targ_req += ctio->dxfer_len; /* if we're done, we can mark the CCB as to send status */ if (a_descr->targ_req == a_descr->total_len) { ctio->ccb_h.flags |= CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; ret = 0; } if (notaio) tcmd_rdwr_done(atio, ctio, AIO_DONE); } else { if (a_descr->targ_ack == a_descr->total_len) tcmd_null_ok(atio, ctio); a_descr->init_req += ctio->dxfer_len; if (a_descr->init_req == a_descr->total_len && ctio->dxfer_len > 0) { /* * If data phase done, remove atio from workq. * The completion handler will call work_atio to * send the final status. */ ret = 0; } send_ccb((union ccb *)ctio, /*priority*/1); } return (ret); } static void tcmd_rdwr_done(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, io_ops event) { struct atio_descr *a_descr; struct ctio_descr *c_descr; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; switch (event) { case AIO_DONE: if (!notaio && aio_return(&c_descr->aiocb) < 0) { warn("aio_return error"); /* XXX */ tcmd_sense(ctio->init_id, ctio, SSD_KEY_MEDIUM_ERROR, 0, 0); send_ccb((union ccb *)ctio, /*priority*/1); break; } a_descr->targ_ack += ctio->dxfer_len; if ((a_descr->flags & CAM_DIR_IN) != 0) { if (debug) { if (notaio) warnx("sending CTIO for AIO read"); else warnx("sending CTIO for sync read"); } a_descr->init_req += ctio->dxfer_len; send_ccb((union ccb *)ctio, /*priority*/1); } else { /* Use work function to send final status */ if (a_descr->init_req == a_descr->total_len) work_atio(atio); if (debug) warnx("AIO done freeing CTIO"); free_ccb((union ccb *)ctio); } break; case CTIO_DONE: switch (ctio->ccb_h.status & CAM_STATUS_MASK) { case CAM_REQ_CMP: break; case CAM_REQUEUE_REQ: warnx("requeueing request"); if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) { if (aio_write(&c_descr->aiocb) < 0) { err(1, "aio_write"); /* XXX */ } } else { if (aio_read(&c_descr->aiocb) < 0) { err(1, "aio_read"); /* XXX */ } } return; default: errx(1, "CTIO failed, status %#x", ctio->ccb_h.status); } a_descr->init_ack += ctio->dxfer_len; if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT && ctio->dxfer_len > 0) { a_descr->targ_req += ctio->dxfer_len; if (notaio) { if (debug) warnx("write sync %lu @ block " OFF_FMT, (unsigned long) (ctio->dxfer_len / sector_size), c_descr->offset / sector_size); if (lseek(c_descr->aiocb.aio_fildes, c_descr->aiocb.aio_offset, SEEK_SET) < 0) { perror("lseek"); err(1, "lseek"); } if (write(c_descr->aiocb.aio_fildes, (void *) c_descr->aiocb.aio_buf, ctio->dxfer_len) != ctio->dxfer_len) { err(1, "write"); } tcmd_rdwr_done(atio, ctio, AIO_DONE); } else { if (debug) warnx("write async %lu @ block " OFF_FMT, (unsigned long) (ctio->dxfer_len / sector_size), c_descr->offset / sector_size); if (aio_write(&c_descr->aiocb) < 0) { err(1, "aio_write"); /* XXX */ } } } else { if (debug) warnx("CTIO done freeing CTIO"); free_ccb((union ccb *)ctio); } break; default: warnx("Unknown completion code %d", event); abort(); /* NOTREACHED */ } } /* Simple ok message used by TUR, SYNC_CACHE, etc. */ static int tcmd_null_ok(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { if (debug) { struct atio_descr *a_descr; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; cdb_debug(a_descr->cdb, "Sending null ok to %u : ", atio->init_id); } ctio->dxfer_len = 0; ctio->ccb_h.flags &= ~CAM_DIR_MASK; ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_STATUS; ctio->scsi_status = SCSI_STATUS_OK; return (0); } /* Simple illegal request message used by MODE SENSE, etc. */ static int tcmd_illegal_req(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio) { if (debug) { struct atio_descr *a_descr; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; cdb_debug(a_descr->cdb, "Sending ill req to %u: ", atio->init_id); } tcmd_sense(atio->init_id, ctio, SSD_KEY_ILLEGAL_REQUEST, /*asc*/0x24, /*ascq*/0); return (0); } static void cdb_debug(u_int8_t *cdb, const char *msg, ...) { char msg_buf[512]; int len; va_list ap; va_start(ap, msg); vsnprintf(msg_buf, sizeof(msg_buf), msg, ap); va_end(ap); len = strlen(msg_buf); scsi_cdb_string(cdb, msg_buf + len, sizeof(msg_buf) - len); warnx("%s", msg_buf); } Index: head/share/examples/scsi_target/scsi_target.c =================================================================== --- head/share/examples/scsi_target/scsi_target.c (revision 326274) +++ head/share/examples/scsi_target/scsi_target.c (revision 326275) @@ -1,986 +1,988 @@ -/* +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * SCSI Disk Emulator * * Copyright (c) 2002 Nate Lawson. * All rights reserved. * * 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, * without modification, immediately at the beginning of the file. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "scsi_target.h" /* Maximum amount to transfer per CTIO */ #define MAX_XFER MAXPHYS /* Maximum number of allocated CTIOs */ #define MAX_CTIOS 64 /* Maximum sector size for emulated volume */ #define MAX_SECTOR 32768 /* Global variables */ int debug; int notaio = 0; off_t volume_size; u_int sector_size; size_t buf_size; /* Local variables */ static int targ_fd; static int kq_fd; static int file_fd; static int num_ctios; static struct ccb_queue pending_queue; static struct ccb_queue work_queue; static struct ioc_enable_lun ioc_enlun = { CAM_BUS_WILDCARD, CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD }; /* Local functions */ static void cleanup(void); static int init_ccbs(void); static void request_loop(void); static void handle_read(void); /* static int work_atio(struct ccb_accept_tio *); */ static void queue_io(struct ccb_scsiio *); static int run_queue(struct ccb_accept_tio *); static int work_inot(struct ccb_immediate_notify *); static struct ccb_scsiio * get_ctio(void); /* static void free_ccb(union ccb *); */ static cam_status get_sim_flags(u_int16_t *); static void rel_simq(void); static void abort_all_pending(void); static void usage(void); int main(int argc, char *argv[]) { int ch; char *file_name; u_int16_t req_flags, sim_flags; off_t user_size; /* Initialize */ debug = 0; req_flags = sim_flags = 0; user_size = 0; targ_fd = file_fd = kq_fd = -1; num_ctios = 0; sector_size = SECTOR_SIZE; buf_size = DFLTPHYS; /* Prepare resource pools */ TAILQ_INIT(&pending_queue); TAILQ_INIT(&work_queue); while ((ch = getopt(argc, argv, "AdSTYb:c:s:W:")) != -1) { switch(ch) { case 'A': req_flags |= SID_Addr16; break; case 'd': debug = 1; break; case 'S': req_flags |= SID_Sync; break; case 'T': req_flags |= SID_CmdQue; break; case 'b': buf_size = atoi(optarg); if (buf_size < 256 || buf_size > MAX_XFER) errx(1, "Unreasonable buf size: %s", optarg); break; case 'c': sector_size = atoi(optarg); if (sector_size < 512 || sector_size > MAX_SECTOR) errx(1, "Unreasonable sector size: %s", optarg); break; case 's': { int last, shift = 0; last = strlen(optarg) - 1; if (last > 0) { switch (tolower(optarg[last])) { case 'e': shift += 10; /* FALLTHROUGH */ case 'p': shift += 10; /* FALLTHROUGH */ case 't': shift += 10; /* FALLTHROUGH */ case 'g': shift += 10; /* FALLTHROUGH */ case 'm': shift += 10; /* FALLTHROUGH */ case 'k': shift += 10; optarg[last] = 0; break; } } user_size = strtoll(optarg, (char **)NULL, /*base*/10); user_size <<= shift; if (user_size < 0) errx(1, "Unreasonable volume size: %s", optarg); break; } case 'W': req_flags &= ~(SID_WBus16 | SID_WBus32); switch (atoi(optarg)) { case 8: /* Leave req_flags zeroed */ break; case 16: req_flags |= SID_WBus16; break; case 32: req_flags |= SID_WBus32; break; default: warnx("Width %s not supported", optarg); usage(); /* NOTREACHED */ } break; case 'Y': notaio = 1; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 2) usage(); sscanf(argv[0], "%u:%u:%u", &ioc_enlun.path_id, &ioc_enlun.target_id, &ioc_enlun.lun_id); file_name = argv[1]; if (ioc_enlun.path_id == CAM_BUS_WILDCARD || ioc_enlun.target_id == CAM_TARGET_WILDCARD || ioc_enlun.lun_id == CAM_LUN_WILDCARD) { warnx("Incomplete target path specified"); usage(); /* NOTREACHED */ } /* We don't support any vendor-specific commands */ ioc_enlun.grp6_len = 0; ioc_enlun.grp7_len = 0; /* Open backing store for IO */ file_fd = open(file_name, O_RDWR); if (file_fd < 0) errx(EX_NOINPUT, "open backing store file"); /* Check backing store size or use the size user gave us */ if (user_size == 0) { struct stat st; if (fstat(file_fd, &st) < 0) err(1, "fstat file"); #if __FreeBSD_version >= 500000 if ((st.st_mode & S_IFCHR) != 0) { /* raw device */ off_t mediasize; if (ioctl(file_fd, DIOCGMEDIASIZE, &mediasize) < 0) err(1, "DIOCGMEDIASIZE"); /* XXX get sector size by ioctl()?? */ volume_size = mediasize / sector_size; } else #endif volume_size = st.st_size / sector_size; } else { volume_size = user_size / sector_size; } if (debug) warnx("volume_size: %d bytes x " OFF_FMT " sectors", sector_size, volume_size); if (volume_size <= 0) errx(1, "volume must be larger than %d", sector_size); if (notaio == 0) { struct aiocb aio, *aiop; /* See if we have we have working AIO support */ memset(&aio, 0, sizeof(aio)); aio.aio_buf = malloc(sector_size); if (aio.aio_buf == NULL) err(1, "malloc"); aio.aio_fildes = file_fd; aio.aio_offset = 0; aio.aio_nbytes = sector_size; signal(SIGSYS, SIG_IGN); if (aio_read(&aio) != 0) { printf("AIO support is not available- switchin to" " single-threaded mode.\n"); notaio = 1; } else { if (aio_waitcomplete(&aiop, NULL) != sector_size) err(1, "aio_waitcomplete"); assert(aiop == &aio); signal(SIGSYS, SIG_DFL); } free((void *)aio.aio_buf); if (debug && notaio == 0) warnx("aio support tested ok"); } targ_fd = open("/dev/targ", O_RDWR); if (targ_fd < 0) err(1, "/dev/targ"); else warnx("opened /dev/targ"); /* The first three are handled by kevent() later */ signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGPROF, SIG_IGN); signal(SIGALRM, SIG_IGN); signal(SIGSTOP, SIG_IGN); signal(SIGTSTP, SIG_IGN); /* Register a cleanup handler to run when exiting */ atexit(cleanup); /* Enable listening on the specified LUN */ if (ioctl(targ_fd, TARGIOCENABLE, &ioc_enlun) != 0) err(1, "TARGIOCENABLE"); /* Enable debugging if requested */ if (debug) { if (ioctl(targ_fd, TARGIOCDEBUG, &debug) != 0) warnx("TARGIOCDEBUG"); } /* Set up inquiry data according to what SIM supports */ if (get_sim_flags(&sim_flags) != CAM_REQ_CMP) errx(1, "get_sim_flags"); if (tcmd_init(req_flags, sim_flags) != 0) errx(1, "Initializing tcmd subsystem failed"); /* Queue ATIOs and INOTs on descriptor */ if (init_ccbs() != 0) errx(1, "init_ccbs failed"); if (debug) warnx("main loop beginning"); request_loop(); exit(0); } static void cleanup() { struct ccb_hdr *ccb_h; if (debug) { warnx("cleanup called"); debug = 0; ioctl(targ_fd, TARGIOCDEBUG, &debug); } ioctl(targ_fd, TARGIOCDISABLE, NULL); close(targ_fd); while ((ccb_h = TAILQ_FIRST(&pending_queue)) != NULL) { TAILQ_REMOVE(&pending_queue, ccb_h, periph_links.tqe); free_ccb((union ccb *)ccb_h); } while ((ccb_h = TAILQ_FIRST(&work_queue)) != NULL) { TAILQ_REMOVE(&work_queue, ccb_h, periph_links.tqe); free_ccb((union ccb *)ccb_h); } if (kq_fd != -1) close(kq_fd); } /* Allocate ATIOs/INOTs and queue on HBA */ static int init_ccbs() { int i; for (i = 0; i < MAX_INITIATORS; i++) { struct ccb_accept_tio *atio; struct atio_descr *a_descr; struct ccb_immediate_notify *inot; atio = (struct ccb_accept_tio *)malloc(sizeof(*atio)); if (atio == NULL) { warn("malloc ATIO"); return (-1); } a_descr = (struct atio_descr *)malloc(sizeof(*a_descr)); if (a_descr == NULL) { free(atio); warn("malloc atio_descr"); return (-1); } atio->ccb_h.func_code = XPT_ACCEPT_TARGET_IO; atio->ccb_h.targ_descr = a_descr; send_ccb((union ccb *)atio, /*priority*/1); inot = (struct ccb_immediate_notify *)malloc(sizeof(*inot)); if (inot == NULL) { warn("malloc INOT"); return (-1); } inot->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY; send_ccb((union ccb *)inot, /*priority*/1); } return (0); } static void request_loop() { struct kevent events[MAX_EVENTS]; struct timespec ts, *tptr; int quit; /* Register kqueue for event notification */ if ((kq_fd = kqueue()) < 0) err(1, "init kqueue"); /* Set up some default events */ EV_SET(&events[0], SIGHUP, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0); EV_SET(&events[1], SIGINT, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0); EV_SET(&events[2], SIGTERM, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0); EV_SET(&events[3], targ_fd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0); if (kevent(kq_fd, events, 4, NULL, 0, NULL) < 0) err(1, "kevent signal registration"); ts.tv_sec = 0; ts.tv_nsec = 0; tptr = NULL; quit = 0; /* Loop until user signal */ while (quit == 0) { int retval, i, oo; struct ccb_hdr *ccb_h; /* Check for the next signal, read ready, or AIO completion */ retval = kevent(kq_fd, NULL, 0, events, MAX_EVENTS, tptr); if (retval < 0) { if (errno == EINTR) { if (debug) warnx("EINTR, looping"); continue; } else { err(1, "kevent failed"); } } else if (retval > MAX_EVENTS) { errx(1, "kevent returned more events than allocated?"); } /* Process all received events. */ for (oo = i = 0; i < retval; i++) { if ((events[i].flags & EV_ERROR) != 0) errx(1, "kevent registration failed"); switch (events[i].filter) { case EVFILT_READ: if (debug) warnx("read ready"); handle_read(); break; case EVFILT_AIO: { struct ccb_scsiio *ctio; struct ctio_descr *c_descr; if (debug) warnx("aio ready"); ctio = (struct ccb_scsiio *)events[i].udata; c_descr = (struct ctio_descr *) ctio->ccb_h.targ_descr; c_descr->event = AIO_DONE; /* Queue on the appropriate ATIO */ queue_io(ctio); /* Process any queued completions. */ oo += run_queue(c_descr->atio); break; } case EVFILT_SIGNAL: if (debug) warnx("signal ready, setting quit"); quit = 1; break; default: warnx("unknown event %d", events[i].filter); break; } if (debug) warnx("event %d done", events[i].filter); } if (oo) { tptr = &ts; continue; } /* Grab the first CCB and perform one work unit. */ if ((ccb_h = TAILQ_FIRST(&work_queue)) != NULL) { union ccb *ccb; ccb = (union ccb *)ccb_h; switch (ccb_h->func_code) { case XPT_ACCEPT_TARGET_IO: /* Start one more transfer. */ retval = work_atio(&ccb->atio); break; case XPT_IMMEDIATE_NOTIFY: retval = work_inot(&ccb->cin1); break; default: warnx("Unhandled ccb type %#x on workq", ccb_h->func_code); abort(); /* NOTREACHED */ } /* Assume work function handled the exception */ if ((ccb_h->status & CAM_DEV_QFRZN) != 0) { if (debug) { warnx("Queue frozen receiving CCB, " "releasing"); } rel_simq(); } /* No more work needed for this command. */ if (retval == 0) { TAILQ_REMOVE(&work_queue, ccb_h, periph_links.tqe); } } /* * Poll for new events (i.e. completions) while we * are processing CCBs on the work_queue. Once it's * empty, use an infinite wait. */ if (!TAILQ_EMPTY(&work_queue)) tptr = &ts; else tptr = NULL; } } /* CCBs are ready from the kernel */ static void handle_read() { union ccb *ccb_array[MAX_INITIATORS], *ccb; int ccb_count, i, oo; ccb_count = read(targ_fd, ccb_array, sizeof(ccb_array)); if (ccb_count <= 0) { warn("read ccb ptrs"); return; } ccb_count /= sizeof(union ccb *); if (ccb_count < 1) { warnx("truncated read ccb ptr?"); return; } for (i = 0; i < ccb_count; i++) { ccb = ccb_array[i]; TAILQ_REMOVE(&pending_queue, &ccb->ccb_h, periph_links.tqe); switch (ccb->ccb_h.func_code) { case XPT_ACCEPT_TARGET_IO: { struct ccb_accept_tio *atio; struct atio_descr *a_descr; /* Initialize ATIO descr for this transaction */ atio = &ccb->atio; a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; bzero(a_descr, sizeof(*a_descr)); TAILQ_INIT(&a_descr->cmplt_io); a_descr->flags = atio->ccb_h.flags & (CAM_DIS_DISCONNECT | CAM_TAG_ACTION_VALID); /* XXX add a_descr->priority */ if ((atio->ccb_h.flags & CAM_CDB_POINTER) == 0) a_descr->cdb = atio->cdb_io.cdb_bytes; else a_descr->cdb = atio->cdb_io.cdb_ptr; /* ATIOs are processed in FIFO order */ TAILQ_INSERT_TAIL(&work_queue, &ccb->ccb_h, periph_links.tqe); break; } case XPT_CONT_TARGET_IO: { struct ccb_scsiio *ctio; struct ctio_descr *c_descr; ctio = &ccb->ctio; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; c_descr->event = CTIO_DONE; /* Queue on the appropriate ATIO */ queue_io(ctio); /* Process any queued completions. */ oo += run_queue(c_descr->atio); break; } case XPT_IMMEDIATE_NOTIFY: /* INOTs are handled with priority */ TAILQ_INSERT_HEAD(&work_queue, &ccb->ccb_h, periph_links.tqe); break; default: warnx("Unhandled ccb type %#x in handle_read", ccb->ccb_h.func_code); break; } } } /* Process an ATIO CCB from the kernel */ int work_atio(struct ccb_accept_tio *atio) { struct ccb_scsiio *ctio; struct atio_descr *a_descr; struct ctio_descr *c_descr; cam_status status; int ret; if (debug) warnx("Working on ATIO %p", atio); a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; /* Get a CTIO and initialize it according to our known parameters */ ctio = get_ctio(); if (ctio == NULL) { return (1); } ret = 0; ctio->ccb_h.flags = a_descr->flags; ctio->tag_id = atio->tag_id; ctio->init_id = atio->init_id; /* XXX priority needs to be added to a_descr */ c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; c_descr->atio = atio; if ((a_descr->flags & CAM_DIR_IN) != 0) c_descr->offset = a_descr->base_off + a_descr->targ_req; else if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) c_descr->offset = a_descr->base_off + a_descr->init_req; else c_descr->offset = a_descr->base_off; /* * Return a check condition if there was an error while * receiving this ATIO. */ if (atio->sense_len != 0) { struct scsi_sense_data_fixed *sense; if (debug) { warnx("ATIO with %u bytes sense received", atio->sense_len); } sense = (struct scsi_sense_data_fixed *)&atio->sense_data; tcmd_sense(ctio->init_id, ctio, sense->flags, sense->add_sense_code, sense->add_sense_code_qual); send_ccb((union ccb *)ctio, /*priority*/1); return (0); } status = atio->ccb_h.status & CAM_STATUS_MASK; switch (status) { case CAM_CDB_RECVD: ret = tcmd_handle(atio, ctio, ATIO_WORK); break; case CAM_REQ_ABORTED: warn("ATIO %p aborted", a_descr); /* Requeue on HBA */ TAILQ_REMOVE(&work_queue, &atio->ccb_h, periph_links.tqe); send_ccb((union ccb *)atio, /*priority*/1); ret = 1; break; default: warnx("ATIO completed with unhandled status %#x", status); abort(); /* NOTREACHED */ break; } return (ret); } static void queue_io(struct ccb_scsiio *ctio) { struct ccb_hdr *ccb_h; struct io_queue *ioq; struct ctio_descr *c_descr; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; if (c_descr->atio == NULL) { errx(1, "CTIO %p has NULL ATIO", ctio); } ioq = &((struct atio_descr *)c_descr->atio->ccb_h.targ_descr)->cmplt_io; if (TAILQ_EMPTY(ioq)) { TAILQ_INSERT_HEAD(ioq, &ctio->ccb_h, periph_links.tqe); return; } TAILQ_FOREACH_REVERSE(ccb_h, ioq, io_queue, periph_links.tqe) { struct ctio_descr *curr_descr = (struct ctio_descr *)ccb_h->targ_descr; if (curr_descr->offset <= c_descr->offset) { break; } } if (ccb_h) { TAILQ_INSERT_AFTER(ioq, ccb_h, &ctio->ccb_h, periph_links.tqe); } else { TAILQ_INSERT_HEAD(ioq, &ctio->ccb_h, periph_links.tqe); } } /* * Go through all completed AIO/CTIOs for a given ATIO and advance data * counts, start continuation IO, etc. */ static int run_queue(struct ccb_accept_tio *atio) { struct atio_descr *a_descr; struct ccb_hdr *ccb_h; int sent_status, event; if (atio == NULL) return (0); a_descr = (struct atio_descr *)atio->ccb_h.targ_descr; while ((ccb_h = TAILQ_FIRST(&a_descr->cmplt_io)) != NULL) { struct ccb_scsiio *ctio; struct ctio_descr *c_descr; ctio = (struct ccb_scsiio *)ccb_h; c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; if (ctio->ccb_h.status == CAM_REQ_ABORTED) { TAILQ_REMOVE(&a_descr->cmplt_io, ccb_h, periph_links.tqe); free_ccb((union ccb *)ctio); send_ccb((union ccb *)atio, /*priority*/1); continue; } /* If completed item is in range, call handler */ if ((c_descr->event == AIO_DONE && c_descr->offset == a_descr->base_off + a_descr->targ_ack) || (c_descr->event == CTIO_DONE && c_descr->offset == a_descr->base_off + a_descr->init_ack)) { sent_status = (ccb_h->flags & CAM_SEND_STATUS) != 0; event = c_descr->event; TAILQ_REMOVE(&a_descr->cmplt_io, ccb_h, periph_links.tqe); tcmd_handle(atio, ctio, c_descr->event); /* If entire transfer complete, send back ATIO */ if (sent_status != 0 && event == CTIO_DONE) send_ccb((union ccb *)atio, /*priority*/1); } else { /* Gap in offsets so wait until later callback */ if (/* debug */ 1) warnx("IO %p:%p out of order %s", ccb_h, a_descr, c_descr->event == AIO_DONE? "aio" : "ctio"); return (1); } } return (0); } static int work_inot(struct ccb_immediate_notify *inot) { cam_status status; if (debug) warnx("Working on INOT %p", inot); status = inot->ccb_h.status; status &= CAM_STATUS_MASK; switch (status) { case CAM_SCSI_BUS_RESET: tcmd_ua(CAM_TARGET_WILDCARD, UA_BUS_RESET); abort_all_pending(); break; case CAM_BDR_SENT: tcmd_ua(CAM_TARGET_WILDCARD, UA_BDR); abort_all_pending(); break; case CAM_MESSAGE_RECV: switch (inot->arg) { case MSG_TASK_COMPLETE: case MSG_INITIATOR_DET_ERR: case MSG_ABORT_TASK_SET: case MSG_MESSAGE_REJECT: case MSG_NOOP: case MSG_PARITY_ERROR: case MSG_TARGET_RESET: case MSG_ABORT_TASK: case MSG_CLEAR_TASK_SET: default: warnx("INOT message %#x", inot->arg); break; } break; case CAM_REQ_ABORTED: warnx("INOT %p aborted", inot); break; default: warnx("Unhandled INOT status %#x", status); break; } /* Requeue on SIM */ TAILQ_REMOVE(&work_queue, &inot->ccb_h, periph_links.tqe); send_ccb((union ccb *)inot, /*priority*/1); return (1); } void send_ccb(union ccb *ccb, int priority) { if (debug) warnx("sending ccb (%#x)", ccb->ccb_h.func_code); ccb->ccb_h.pinfo.priority = priority; if (XPT_FC_IS_QUEUED(ccb)) { TAILQ_INSERT_TAIL(&pending_queue, &ccb->ccb_h, periph_links.tqe); } if (write(targ_fd, &ccb, sizeof(ccb)) != sizeof(ccb)) { warn("write ccb"); ccb->ccb_h.status = CAM_PROVIDE_FAIL; } } /* Return a CTIO/descr/buf combo from the freelist or malloc one */ static struct ccb_scsiio * get_ctio() { struct ccb_scsiio *ctio; struct ctio_descr *c_descr; struct sigevent *se; if (num_ctios == MAX_CTIOS) { warnx("at CTIO max"); return (NULL); } ctio = (struct ccb_scsiio *)malloc(sizeof(*ctio)); if (ctio == NULL) { warn("malloc CTIO"); return (NULL); } c_descr = (struct ctio_descr *)malloc(sizeof(*c_descr)); if (c_descr == NULL) { free(ctio); warn("malloc ctio_descr"); return (NULL); } c_descr->buf = malloc(buf_size); if (c_descr->buf == NULL) { free(c_descr); free(ctio); warn("malloc backing store"); return (NULL); } num_ctios++; /* Initialize CTIO, CTIO descr, and AIO */ ctio->ccb_h.func_code = XPT_CONT_TARGET_IO; ctio->ccb_h.retry_count = 2; ctio->ccb_h.timeout = CAM_TIME_INFINITY; ctio->data_ptr = c_descr->buf; ctio->ccb_h.targ_descr = c_descr; c_descr->aiocb.aio_buf = c_descr->buf; c_descr->aiocb.aio_fildes = file_fd; se = &c_descr->aiocb.aio_sigevent; se->sigev_notify = SIGEV_KEVENT; se->sigev_notify_kqueue = kq_fd; se->sigev_value.sival_ptr = ctio; return (ctio); } void free_ccb(union ccb *ccb) { switch (ccb->ccb_h.func_code) { case XPT_CONT_TARGET_IO: { struct ctio_descr *c_descr; c_descr = (struct ctio_descr *)ccb->ccb_h.targ_descr; free(c_descr->buf); num_ctios--; /* FALLTHROUGH */ } case XPT_ACCEPT_TARGET_IO: free(ccb->ccb_h.targ_descr); /* FALLTHROUGH */ case XPT_IMMEDIATE_NOTIFY: default: free(ccb); break; } } static cam_status get_sim_flags(u_int16_t *flags) { struct ccb_pathinq cpi; cam_status status; /* Find SIM capabilities */ bzero(&cpi, sizeof(cpi)); cpi.ccb_h.func_code = XPT_PATH_INQ; send_ccb((union ccb *)&cpi, /*priority*/1); status = cpi.ccb_h.status & CAM_STATUS_MASK; if (status != CAM_REQ_CMP) { fprintf(stderr, "CPI failed, status %#x\n", status); return (status); } /* Can only enable on controllers that support target mode */ if ((cpi.target_sprt & PIT_PROCESSOR) == 0) { fprintf(stderr, "HBA does not support target mode\n"); status = CAM_PATH_INVALID; return (status); } *flags = cpi.hba_inquiry; return (status); } static void rel_simq() { struct ccb_relsim crs; bzero(&crs, sizeof(crs)); crs.ccb_h.func_code = XPT_REL_SIMQ; crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY; crs.openings = 0; crs.release_timeout = 0; crs.qfrozen_cnt = 0; send_ccb((union ccb *)&crs, /*priority*/0); } /* Cancel all pending CCBs. */ static void abort_all_pending() { struct ccb_abort cab; struct ccb_hdr *ccb_h; if (debug) warnx("abort_all_pending"); bzero(&cab, sizeof(cab)); cab.ccb_h.func_code = XPT_ABORT; TAILQ_FOREACH(ccb_h, &pending_queue, periph_links.tqe) { if (debug) warnx("Aborting pending CCB %p\n", ccb_h); cab.abort_ccb = (union ccb *)ccb_h; send_ccb((union ccb *)&cab, /*priority*/1); if (cab.ccb_h.status != CAM_REQ_CMP) { warnx("Unable to abort CCB, status %#x\n", cab.ccb_h.status); } } } static void usage() { fprintf(stderr, "Usage: scsi_target [-AdSTY] [-b bufsize] [-c sectorsize]\n" "\t\t[-r numbufs] [-s volsize] [-W 8,16,32]\n" "\t\tbus:target:lun filename\n"); exit(1); } Index: head/share/examples/scsi_target/scsi_target.h =================================================================== --- head/share/examples/scsi_target/scsi_target.h (revision 326274) +++ head/share/examples/scsi_target/scsi_target.h (revision 326275) @@ -1,129 +1,131 @@ -/* +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * SCSI Target Emulator * * Copyright (c) 2002 Nate Lawson. * All rights reserved. * * 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, * without modification, immediately at the beginning of the file. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef _SCSI_TARGET_H #define _SCSI_TARGET_H /* * Maximum number of parallel commands to accept, * 1024 for Fibre Channel (SPI is 16). */ #define MAX_INITIATORS 8 #define SECTOR_SIZE 512 #define MAX_EVENTS (MAX_INITIATORS + 5) /* kqueue for AIO, signals */ /* Additional SCSI 3 defines for inquiry response */ #define SID_Addr16 0x0100 TAILQ_HEAD(io_queue, ccb_hdr); /* Offset into the private CCB area for storing our descriptor */ #define targ_descr periph_priv.entries[1].ptr /* Descriptor attached to each ATIO */ struct atio_descr { off_t base_off; /* Base offset for ATIO */ uint total_len; /* Total xfer len for this ATIO */ uint init_req; /* Transfer count requested to/from init */ uint init_ack; /* Data transferred ok to/from init */ uint targ_req; /* Transfer count requested to/from target */ uint targ_ack; /* Data transferred ok to/from target */ int flags; /* Flags for CTIOs */ u_int8_t *cdb; /* Pointer to received CDB */ /* List of completed AIO/CTIOs */ struct io_queue cmplt_io; }; typedef enum { ATIO_WORK, AIO_DONE, CTIO_DONE } io_ops; /* Descriptor attached to each CTIO */ struct ctio_descr { void *buf; /* Backing store */ off_t offset; /* Position in transfer (for file, */ /* doesn't start at 0) */ struct aiocb aiocb; /* AIO descriptor for this CTIO */ struct ccb_accept_tio *atio; /* ATIO we are satisfying */ io_ops event; /* Event that queued this CTIO */ }; typedef enum { UA_NONE = 0x00, UA_POWER_ON = 0x01, UA_BUS_RESET = 0x02, UA_BDR = 0x04 } ua_types; typedef enum { CA_NONE = 0x00, CA_UNIT_ATTN = 0x01, CA_CMD_SENSE = 0x02 } ca_types; struct initiator_state { ua_types orig_ua; ca_types orig_ca; ua_types pending_ua; ca_types pending_ca; struct scsi_sense_data sense_data; }; /* Global functions */ extern cam_status tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags); extern int tcmd_handle(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, io_ops event); extern void tcmd_sense(u_int init_id, struct ccb_scsiio *ctio, u_int8_t flags, u_int8_t asc, u_int8_t ascq); extern void tcmd_ua(u_int init_id, ua_types new_ua); extern int work_atio(struct ccb_accept_tio *atio); extern void send_ccb(union ccb *ccb, int priority); extern void free_ccb(union ccb *ccb); static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } /* Global Data */ extern int notaio; /* * Compat Defines */ #if __FreeBSD_version >= 500000 #define OFF_FMT "%ju" #else #define OFF_FMT "%llu" #endif #endif /* _SCSI_TARGET_H */ Index: head/share/mk/version_gen.awk =================================================================== --- head/share/mk/version_gen.awk (revision 326274) +++ head/share/mk/version_gen.awk (revision 326275) @@ -1,249 +1,251 @@ # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (C) 2006 Daniel M. Eischen. All rights reserved. # # 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 BY AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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. # # $FreeBSD$ # # # Make a list of all the library versions listed in the master file. # # versions[] - array indexed by version name, contains number # of symbols (+ 1) found for each version. # successors[] - array index by version name, contains successor # version name. # symbols[][] - array index by [version name, symbol index], contains # names of symbols defined for each version. # names[] - array index is symbol name and value is its first version seen, # used to check for duplicate symbols and warn about them. # BEGIN { brackets = 0; errors = warns = 0; version_count = 0; current_version = ""; stderr = "/dev/stderr"; while (getline < vfile) { # Strip comments. sub("#.*$", "", $0); # Strip leading and trailing whitespace. sub("^[ \t]+", "", $0); sub("[ \t]+$", "", $0); if (/^[a-zA-Z0-9._]+[ \t]*{$/) { # Strip brace. sub("{", "", $1); brackets++; symver = $1; versions[symver] = 1; successors[symver] = ""; generated[symver] = 0; version_count++; } else if (/^}[ \t]*[a-zA-Z0-9._]+[ \t]*;$/) { v = $1 != "}" ? $1 : $2; # Strip brace. sub("}", "", v); # Strip semicolon. sub(";", "", v); if (symver == "") { printf("File %s: Unmatched bracket.\n", vfile) > stderr; errors++; } else if (versions[v] != 1) { printf("File %s: `%s' has unknown " \ "successor `%s'.\n", vfile, symver, v) > stderr; errors++; } else successors[symver] = v; brackets--; } else if (/^}[ \t]*;$/) { if (symver == "") { printf("File %s: Unmatched bracket.\n", vfile) > stderr; errors++; } # No successor brackets--; } else if (/^}$/) { printf("File %s: Missing final semicolon.\n", vfile) > stderr; errors++; } else if (/^$/) ; # Ignore blank lines. else { printf("File %s: Unknown directive: `%s'.\n", vfile, $0) > stderr; errors++; } } brackets = 0; } { # Set meaningful filename for diagnostics. filename = FILENAME != "" ? FILENAME : ""; # Delete comments, preceding and trailing whitespace, then # consume blank lines. sub("#.*$", "", $0); sub("^[ \t]+", "", $0); sub("[ \t]+$", "", $0); if ($0 == "") next; } /^[a-zA-Z0-9._]+[ \t]*{$/ { # Strip bracket from version name. sub("{", "", $1); if (current_version != "") { printf("File %s, line %d: Illegal nesting detected.\n", filename, FNR) > stderr; errors++; } else if (versions[$1] == 0) { printf("File %s, line %d: Undefined " \ "library version `%s'.\n", filename, FNR, $1) > stderr; errors++; # Remove this entry from the versions. delete versions[$1]; } else current_version = $1; brackets++; next; } /^[a-zA-Z0-9._]+[ \t]*;$/ { # Strip semicolon. sub(";", "", $1); if (current_version != "") { count = versions[current_version]; versions[current_version]++; symbols[current_version, count] = $1; if ($1 in names && names[$1] != current_version) { # # A graver case when a dup symbol appears under # different versions in the map. That can result # in subtle problems with the library later. # printf("File %s, line %d: Duplicated symbol `%s' " \ "in version `%s', first seen in `%s'. " \ "Did you forget to move it to ObsoleteVersions?\n", filename, FNR, $1, current_version, names[$1]) > stderr; errors++; } else if (names[$1] == current_version) { # # A harmless case: a dup symbol with the same version. # printf("File %s, line %d: warning: " \ "Duplicated symbol `%s' in version `%s'.\n", filename, FNR, $1, current_version) > stderr; warns++; } else names[$1] = current_version; } else { printf("File %s, line %d: Symbol `%s' outside version scope.\n", filename, FNR, $1) > stderr; errors++; } next; } /^}[ \t]*;$/ { brackets--; if (brackets < 0) { printf("File %s, line %d: Unmatched bracket.\n", filename, FNR, $1) > stderr; errors++; brackets = 0; # Reset } current_version = ""; next; } { printf("File %s, line %d: Unknown directive: `%s'.\n", filename, FNR, $0) > stderr; errors++; } function print_version(v) { # This function is recursive, so return if this version # has already been printed. Otherwise, if there is an # ancestral version, recursively print its symbols before # printing the symbols for this version. # if (generated[v] == 1) return; if (successors[v] != "") print_version(successors[v]); printf("%s {\n", v); # The version count is always one more that actual, # so the loop ranges from 1 to n-1. # for (i = 1; i < versions[v]; i++) { if (i == 1) printf("global:\n"); printf("\t%s;\n", symbols[v, i]); } version_count--; if (version_count == 0) { printf("local:\n"); printf("\t*;\n"); } if (successors[v] == "") printf("};\n"); else printf("} %s;\n", successors[v]); printf("\n"); generated[v] = 1; } END { if (errors) { printf("%d error(s) total.\n", errors) > stderr; exit(1); } # OK, no errors. for (v in versions) { print_version(v); } } Index: head/share/syscons/scrnmaps/mkscrfil.c =================================================================== --- head/share/syscons/scrnmaps/mkscrfil.c (revision 326274) +++ head/share/syscons/scrnmaps/mkscrfil.c (revision 326275) @@ -1,52 +1,54 @@ -/* +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (C) 1994 by Andrew A. Chernov, Moscow, Russia. * All rights reserved. * * 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 BY THE AUTHOR ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #include #include #include #include FIL int main(int argc, char **argv) { FILE *fd; if (argc == 2) { if ((fd = fopen(argv[1], "w")) == NULL) { perror(argv[1]); return 1; } fwrite(&scrmap, sizeof(scrmap_t), 1, fd); fclose(fd); return 0; } else { fprintf(stderr, "usage: %s \n", argv[0]); return 1; } } Index: head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh (revision 326275) @@ -1,782 +1,784 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions related to disk operations using bsdlabel # Check if we are are provided a geli password on the nextline of the config check_for_enc_pass() { CURLINE="${1}" get_next_cfg_line "${CFGF}" "${CURLINE}" echo ${VAL} | grep -q "^encpass=" 2>/dev/null if [ $? -eq 0 ] ; then # Found a password, return it get_value_from_string "${VAL}" return fi export VAL="" return }; # On check on the disk-label line if we have any extra vars for this device get_fs_line_xvars() { ACTIVEDEV="${1}" LINE="${2}" echo $LINE | cut -d ' ' -f 4 | grep -q '(' 2>/dev/null if [ $? -ne 0 ] ; then return ; fi # See if we are looking for ZFS specific options echo $LINE | grep -q '^ZFS' 2>/dev/null if [ $? -eq 0 ] ; then ZTYPE="NONE" ZFSVARS="`echo $LINE | cut -d ' ' -f 4-20 |cut -d '(' -f 2- | cut -d ')' -f 1 | xargs`" echo $ZFSVARS | grep -qE "^(disk|file|mirror|raidz(1|2|3)?|spare|log|cache):" 2>/dev/null if [ $? -eq 0 ] ; then ZTYPE=`echo $ZFSVARS | cut -f1 -d:` tmpVars=`echo $ZFSVARS | sed "s|$ZTYPE: ||g" | sed "s|$ZTYPE:||g"` ZFSVARS="" # make sure we have a '/dev' in front of the extra devices for i in $tmpVars do echo $i | grep -q '/dev/' if [ $? -ne 0 ] ; then ZFSVARS="$ZFSVARS /dev/${i}" else ZFSVARS="$ZFSVARS $i" fi done fi # Return the ZFS options if [ "${ZTYPE}" = "NONE" ] ; then VAR="${ACTIVEDEV} ${ZFSVARS}" else VAR="${ZTYPE} ${ACTIVEDEV} ${ZFSVARS}" fi export VAR return fi # End of ZFS block # See if we are looking for UFS specific newfs options echo $LINE | grep -q '^UFS' 2>/dev/null if [ $? -eq 0 ] ; then FSVARS="`echo $LINE | cut -d '(' -f 2- | cut -d ')' -f 1 | xargs`" VAR="${FSVARS}" export VAR return fi # If we got here, set VAR to empty and export export VAR="" return }; # Init each zfs mirror disk with a boot sector so we can failover setup_zfs_mirror_parts() { _nZFS="" ZTYPE="`echo ${1} | awk '{print $1}'`" # Using mirroring, setup boot partitions on each disk _mirrline="`echo ${1} | sed 's|mirror ||g' | sed 's|raidz1 ||g' | sed 's|raidz2 ||g' | sed 's|raidz3 ||g' | sed 's|raidz ||g'`" for _zvars in $_mirrline do echo "Looping through _zvars: $_zvars" >>${LOGOUT} echo "$_zvars" | grep -q "${2}" 2>/dev/null if [ $? -eq 0 ] ; then continue ; fi if [ -z "$_zvars" ] ; then continue ; fi is_disk "$_zvars" >/dev/null 2>/dev/null if [ $? -eq 0 ] ; then echo "Setting up ZFS disk $_zvars" >>${LOGOUT} init_gpt_full_disk "$_zvars" >/dev/null 2>/dev/null rc_halt "gpart add -a 4k -t freebsd-zfs ${_zvars}" >/dev/null 2>/dev/null rc_halt "gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${_zvars}" >/dev/null 2>/dev/null _nZFS="$_nZFS ${_zvars}p2" else _nZFS="$_nZFS ${_zvars}" fi done echo "$ZTYPE $2 `echo $_nZFS | tr -s ' '`" } ; # Function which creates a unique label name for the specified mount gen_glabel_name() { MOUNT="$1" TYPE="$2" NUM="0" MAXNUM="20" if [ "$TYPE" = "ZFS" ] ; then NAME="zpool" elif [ "$MOUNT" = "/" ] ; then NAME="rootfs" else # If doing a swap partition, also rename it if [ "${TYPE}" = "SWAP" ] then NAME="swap" else NAME="`echo $MOUNT | sed 's|/||g' | sed 's| ||g'`" fi fi # Loop through and break when we find our first available label while Z=1 do glabel status | grep -q "${NAME}${NUM}" 2>/dev/null if [ $? -ne 0 ] then break else NUM=$((NUM+1)) fi if [ $NUM -gt $MAXNUM ] then exit_err "Cannot allocate additional glabel name for $NAME" break fi done export VAL="${NAME}${NUM}" }; # Function to determine the size we can safely use when 0 is specified get_autosize() { # Disk tag to look for dTag="$1" # Total MB Avail get_disk_mediasize_mb "$2" local _aSize=$VAL while read line do # Check for data on this slice echo $line | grep -q "^${_dTag}-part=" 2>/dev/null if [ $? -ne 0 ] ; then continue ; fi get_value_from_string "${line}" STRING="$VAL" # Get the size of this partition SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` if [ $SIZE -eq 0 ] ; then continue ; fi _aSize=`expr $_aSize - $SIZE` done <${CFGF} # Pad the size a bit _aSize=`expr $_aSize - 2` VAL="$_aSize" export VAL }; # Function to setup partitions using gpart setup_gpart_partitions() { local _dTag="$1" local _pDisk="$2" local _wSlice="$3" local _sNum="$4" local _pType="$5" FOUNDPARTS="1" USEDAUTOSIZE=0 # Lets read in the config file now and setup our partitions if [ "${_pType}" = "gpt" ] ; then CURPART="2" elif [ "${_pType}" = "apm" ] ; then CURPART="3" else PARTLETTER="a" CURPART="1" if [ "${_pType}" = "mbr" ] ; then rc_halt "gpart create -s BSD ${_wSlice}" fi fi while read line do # Check for data on this slice echo $line | grep -q "^${_dTag}-part=" 2>/dev/null if [ $? -eq 0 ] then FOUNDPARTS="0" # Found a slice- entry, lets get the slice info get_value_from_string "${line}" STRING="$VAL" # We need to split up the string now, and pick out the variables FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1` SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` # Check if we have a .eli extension on this FS echo ${FS} | grep -q ".eli" 2>/dev/null if [ $? -eq 0 ] then FS="`echo ${FS} | cut -d '.' -f 1`" ENC="ON" check_for_enc_pass "${line}" if [ "${VAL}" != "" ] ; then # We have a user supplied password, save it for later ENCPASS="${VAL}" fi else ENC="OFF" fi # Check if the user tried to setup / as an encrypted partition check_for_mount "${MNT}" "/" if [ $? -eq 0 -a "${ENC}" = "ON" ] then export USINGENCROOT="0" fi # Now check that these values are sane case $FS in UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP) ;; *) exit_err "ERROR: Invalid file system specified on $line" ;; esac # Check that we have a valid size number expr $SIZE + 1 >/dev/null 2>/dev/null if [ $? -ne 0 ]; then exit_err "ERROR: The size specified on $line is invalid" fi # Check that the mount-point starts with / echo "$MNT" | grep -qe "^/" -e "^none" 2>/dev/null if [ $? -ne 0 ]; then exit_err "ERROR: The mount-point specified on $line is invalid" fi if [ "$SIZE" = "0" ] then if [ $USEDAUTOSIZE -eq 1 ] ; then exit_err "ERROR: You can not have two partitions with a size of 0 specified!" fi case ${_pType} in gpt|apm) get_autosize "${_dTag}" "$_pDisk" ;; *) get_autosize "${_dTag}" "$_wSlice" ;; esac SOUT="-s ${VAL}M" USEDAUTOSIZE=1 else SOUT="-s ${SIZE}M" fi # Check if we found a valid root partition check_for_mount "${MNT}" "/" if [ $? -eq 0 ] ; then export FOUNDROOT="1" if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then export FOUNDROOT="0" fi if [ "${CURPART}" = "3" -a "$_pType" = "apm" ] ; then export FOUNDROOT="0" fi if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then export FOUNDROOT="0" fi if [ "${CURPART}" = "1" -a "$_pType" = "gptslice" ] ; then export FOUNDROOT="0" fi fi check_for_mount "${MNT}" "/boot" if [ $? -eq 0 ] ; then export USINGBOOTPART="0" if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then exit_err "/boot partition must be first partition" fi if [ "${CURPART}" != "3" -a "${_pType}" = "apm" ] ; then exit_err "/boot partition must be first partition" fi if [ "${CURPART}" != "1" -a "${_pType}" = "mbr" ] ; then exit_err "/boot partition must be first partition" fi if [ "${CURPART}" != "1" -a "${_pType}" = "gptslice" ] ; then exit_err "/boot partition must be first partition" fi if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ] ; then exit_err "/boot partition must be formatted with UFS" fi fi # Generate a unique label name for this mount gen_glabel_name "${MNT}" "${FS}" PLABEL="${VAL}" # Get any extra options for this fs / line if [ "${_pType}" = "gpt" ] ; then get_fs_line_xvars "${_pDisk}p${CURPART}" "${STRING}" elif [ "${_pType}" = "apm" ] ; then get_fs_line_xvars "${_pDisk}s${CURPART}" "${STRING}" else get_fs_line_xvars "${_wSlice}${PARTLETTER}" "${STRING}" fi XTRAOPTS="$VAR" # Check if using zfs mirror echo ${XTRAOPTS} | grep -q -e "mirror" -e "raidz" if [ $? -eq 0 -a "$FS" = "ZFS" ] ; then if [ "${_pType}" = "gpt" -o "${_pType}" = "gptslice" ] ; then XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}") elif [ "${_pType}" = "apm" ] ; then XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}s${CURPART}") else XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}${PARTLETTER}") fi fi # Figure out the gpart type to use case ${FS} in ZFS) PARTYPE="freebsd-zfs" ;; SWAP) PARTYPE="freebsd-swap" ;; *) PARTYPE="freebsd-ufs" ;; esac # Create the partition if [ "${_pType}" = "gpt" ] ; then if [ "$CURPART" = "2" ] ; then # If this is GPT, make sure first partition is aligned to 4k sleep 2 rc_halt "gpart add -a 4k ${SOUT} -t ${PARTYPE} ${_pDisk}" else sleep 2 rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}" fi elif [ "${_pType}" = "gptslice" ]; then sleep 2 rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_wSlice}" elif [ "${_pType}" = "apm" ]; then sleep 2 rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}" else sleep 2 rc_halt "gpart add ${SOUT} -t ${PARTYPE} -i ${CURPART} ${_wSlice}" fi # Check if this is a root / boot partition, and stamp the right loader for TESTMNT in `echo ${MNT} | sed 's|,| |g'` do if [ "${TESTMNT}" = "/" -a -z "${BOOTTYPE}" ] ; then BOOTTYPE="${PARTYPE}" fi if [ "${TESTMNT}" = "/boot" ] ; then BOOTTYPE="${PARTYPE}" fi done # Save this data to our partition config dir if [ "${_pType}" = "gpt" ] ; then _dFile="`echo $_pDisk | sed 's|/|-|g'`" echo "${FS}#${MNT}#${ENC}#${PLABEL}#GPT#${XTRAOPTS}" >${PARTDIR}/${_dFile}p${CURPART} # Clear out any headers sleep 2 dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 2>/dev/null # If we have a enc password, save it as well if [ -n "${ENCPASS}" ] ; then echo "${ENCPASS}" >${PARTDIR}-enc/${_dFile}p${CURPART}-encpass fi elif [ "${_pType}" = "apm" ] ; then _dFile="`echo $_pDisk | sed 's|/|-|g'`" echo "${FS}#${MNT}#${ENC}#${PLABEL}#GPT#${XTRAOPTS}" >${PARTDIR}/${_dFile}s${CURPART} # Clear out any headers sleep 2 dd if=/dev/zero of=${_pDisk}s${CURPART} count=2048 2>/dev/null # If we have a enc password, save it as well if [ -n "${ENCPASS}" ] ; then echo "${ENCPASS}" >${PARTDIR}-enc/${_dFile}s${CURPART}-encpass fi else # MBR Partition or GPT slice _dFile="`echo $_wSlice | sed 's|/|-|g'`" echo "${FS}#${MNT}#${ENC}#${PLABEL}#MBR#${XTRAOPTS}#${IMAGE}" >${PARTDIR}/${_dFile}${PARTLETTER} # Clear out any headers sleep 2 dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 2>/dev/null # If we have a enc password, save it as well if [ -n "${ENCPASS}" ] ; then echo "${ENCPASS}" >${PARTDIR}-enc/${_dFile}${PARTLETTER}-encpass fi fi # Increment our parts counter if [ "$_pType" = "gpt" -o "$_pType" = "apm" ] ; then CURPART=$((CURPART+1)) # If this is a gpt/apm partition, # we can continue and skip the MBR part letter stuff continue else CURPART=$((CURPART+1)) if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi fi # This partition letter is used, get the next one case ${PARTLETTER} in a) PARTLETTER="b" ;; b) PARTLETTER="d" ;; d) PARTLETTER="e" ;; e) PARTLETTER="f" ;; f) PARTLETTER="g" ;; g) PARTLETTER="h" ;; h) PARTLETTER="ERR" ;; *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;; esac fi # End of subsection locating a slice in config echo $line | grep -q "^commitDiskLabel" 2>/dev/null if [ $? -eq 0 -a "${FOUNDPARTS}" = "0" ] then # If this is the boot disk, stamp the right gptboot if [ ! -z "${BOOTTYPE}" -a "$_pType" = "gpt" ] ; then case ${BOOTTYPE} in freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${_pDisk}" ;; freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_pDisk}" ;; esac fi # Make sure to stamp the MBR loader if [ "$_pType" = "mbr" ] ; then rc_halt "gpart bootcode -b /boot/boot ${_wSlice}" fi # Found our flag to commit this label setup, check that we found at least 1 partition if [ "${CURPART}" = "1" ] ; then exit_err "ERROR: commitDiskLabel was called without any partition entries for it!" fi break fi done <${CFGF} }; # Reads through the config and sets up a BSDLabel for the given slice populate_disk_label() { if [ -z "${1}" ] then exit_err "ERROR: populate_disk_label() called without argument!" fi # Set some vars from the given working slice diskid="`echo $1 | cut -d ':' -f 1`" disk="`echo $1 | cut -d ':' -f 1 | sed 's|-|/|g'`" slicenum="`echo $1 | cut -d ':' -f 2`" type="`echo $1 | cut -d ':' -f 3`" # Set WRKSLICE based upon format we are using if [ "$type" = "mbr" ] ; then wrkslice="${diskid}s${slicenum}" fi if [ "$type" = "apm" ] ; then wrkslice="${diskid}s${slicenum}" fi if [ "$type" = "gpt" -o "$type" = "gptslice" ] ; then wrkslice="${diskid}p${slicenum}" fi if [ ! -e "${SLICECFGDIR}/${wrkslice}" ] ; then exit_err "ERROR: Missing SLICETAG data. This shouldn't happen - please let the developers know" fi disktag="`cat ${SLICECFGDIR}/${wrkslice}`" slicedev="`echo $wrkslice | sed 's|-|/|g'`" # Setup the partitions with gpart setup_gpart_partitions "${disktag}" "${disk}" "${slicedev}" "${slicenum}" "${type}" }; # Function which reads in the disk slice config, and performs it setup_disk_label() { # We are ready to start setting up the label, lets read the config and do the actions # First confirm that we have a valid WORKINGSLICES if [ -z "${WORKINGSLICES}" ]; then exit_err "ERROR: No slices were setup! Please report this to the maintainers" fi # Check that the slices we have did indeed get setup and gpart worked for i in $WORKINGSLICES do disk="`echo $i | cut -d '-' -f 1`" pnum="`echo $i | cut -d '-' -f 2`" type="`echo $i | cut -d '-' -f 3`" if [ "$type" = "mbr" -a ! -e "${disk}s${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi if [ "$type" = "gpt" -a ! -e "${disk}p${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi if [ "$type" = "apm" -a ! -e "${disk}s${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi if [ "$type" = "gptslice" -a ! -e "${disk}p${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi done # Setup some files which we'll be referring to export LABELLIST="${TMPDIR}/workingLabels" rm $LABELLIST >/dev/null 2>/dev/null # Set our flag to determine if we've got a valid root partition in this setup export FOUNDROOT="-1" # Check if we are using a /boot partition export USINGBOOTPART="1" # Set encryption on root check export USINGENCROOT="1" # Make the tmp directory where we'll store FS info & mount-points rm -rf ${PARTDIR} >/dev/null 2>/dev/null mkdir -p ${PARTDIR} >/dev/null 2>/dev/null rm -rf ${PARTDIR}-enc >/dev/null 2>/dev/null mkdir -p ${PARTDIR}-enc >/dev/null 2>/dev/null for i in $WORKINGSLICES do populate_disk_label "${i}" done # Check if we made a root partition if [ "$FOUNDROOT" = "-1" ] then exit_err "ERROR: No root (/) partition specified!!" fi # Check if we made a root partition if [ "$FOUNDROOT" = "1" -a "${USINGBOOTPART}" != "0" ] then exit_err "ERROR: (/) partition isn't first partition on disk!" fi if [ "${USINGENCROOT}" = "0" -a "${USINGBOOTPART}" != "0" ] then exit_err "ERROR: Can't encrypt (/) with no (/boot) partition!" fi }; check_fstab_mbr() { local SLICE local FSTAB if [ -z "$2" ] then return 1 fi SLICE="$1" FSTAB="$2/etc/fstab" if [ -f "${FSTAB}" ] then PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'` cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTLETTER}" = "a" ] then FOUNDROOT="0" else FOUNDROOT="1" fi ROOTIMAGE="1" export FOUNDROOT export ROOTIMAGE fi cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTLETTER}" = "a" ] then USINGBOOTPART="0" else exit_err "/boot partition must be first partition" fi export USINGBOOTPART fi return 0 fi return 1 }; check_fstab_gpt() { local SLICE local FSTAB if [ -z "$2" ] then return 1 fi SLICE="$1" FSTAB="$2/etc/fstab" if [ -f "${FSTAB}" ] then PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'` cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTNUMBER}" = "2" ] then FOUNDROOT="0" else FOUNDROOT="1" fi ROOTIMAGE="1" export FOUNDROOT export ROOTIMAGE fi cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTNUMBER}" = "2" ] then USINGBOOTPART="0" else exit_err "/boot partition must be first partition" fi export USINGBOOTPART fi return 0 fi return 1 }; check_disk_layout() { local SLICES local TYPE local DISK local RES local F DISK="$1" TYPE="MBR" if [ -z "${DISK}" ] then return 1 fi SLICES_MBR=`ls /dev/${DISK}s[1-4]*[a-h]* 2>/dev/null` SLICES_GPT=`ls /dev/${DISK}p[0-9]* 2>/dev/null` SLICES_SLICE=`ls /dev/${DISK}[a-h]* 2>/dev/null` if [ -n "${SLICES_MBR}" ] then SLICES="${SLICES_MBR}" TYPE="MBR" RES=0 fi if [ -n "${SLICES_GPT}" ] then SLICES="${SLICES_GPT}" TYPE="GPT" RES=0 fi if [ -n "${SLICES_SLICE}" ] then SLICES="${SLICES_SLICE}" TYPE="MBR" RES=0 fi for slice in ${SLICES} do F=1 mount ${slice} /mnt 2>/dev/null if [ $? -ne 0 ] then continue fi if [ "${TYPE}" = "MBR" ] then check_fstab_mbr "${slice}" "/mnt" F="$?" elif [ "${TYPE}" = "GPT" ] then check_fstab_gpt "${slice}" "/mnt" F="$?" fi if [ ${F} -eq 0 ] then umount /mnt break fi umount /mnt done return ${RES} }; Index: head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh (revision 326275) @@ -1,411 +1,413 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which perform the final cleanup after an install # Finishes up with ZFS setup before unmounting zfs_cleanup_unmount() { # Loop through our FS and see if we have any ZFS partitions to cleanup for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" ZPOOLNAME=$(get_zpool_name "${PARTDEV}") if [ "$PARTFS" = "ZFS" ] then # Check if we have multiple zfs mounts specified for ZMNT in `echo ${PARTMNT} | sed 's|,| |g'` do if [ "${ZMNT}" = "/" ] then # Make sure we haven't already added the zfs boot line when # Creating a dedicated "/boot" partition cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q "vfs.root.mountfrom=" 2>/dev/null if [ $? -ne 0 ] ; then echo "vfs.root.mountfrom=\"zfs:${ZPOOLNAME}/ROOT/default\"" >> ${FSMNT}/boot/loader.conf fi export FOUNDZFSROOT="${ZPOOLNAME}" fi done FOUNDZFS="1" fi done if [ -n "${FOUNDZFS}" ] then # Check if we need to add our ZFS flags to rc.conf, src.conf and loader.conf cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'zfs_load="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'zfs_load="YES"' >>${FSMNT}/boot/loader.conf fi cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'zfs_enable="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'zfs_enable="YES"' >>${FSMNT}/etc/rc.conf fi sleep 2 # Copy over any ZFS cache data cp /boot/zfs/* ${FSMNT}/boot/zfs/ # Copy the hostid so that our zfs cache works cp /etc/hostid ${FSMNT}/etc/hostid fi # Loop through our FS and see if we have any ZFS partitions to cleanup for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" ZPOOLNAME=$(get_zpool_name "${PARTDEV}") if [ "$PARTFS" = "ZFS" ] then # Create a list of zpool names we can export echo $ZPOOLEXPORTS | grep -q "$ZPOOLNAME " if [ $? -ne 0 ] ; then export ZPOOLEXPORTS="$ZPOOLNAME $ZPOOLEXPORTS" fi # Check if we have multiple zfs mounts specified for ZMNT in `echo ${PARTMNT} | sed 's|,| |g'` do ZMNT="`echo $ZMNT | cut -d '(' -f 1`" PARTMNTREV="${ZMNT} ${PARTMNTREV}" done for ZMNT in ${PARTMNTREV} do if [ "${ZMNT}" = "/" ] ; then continue ; fi # Some ZFS like /swap aren't mounted, and dont need unmounting mount | grep -q "${FSMNT}${ZMNT}" if [ $? -eq 0 ] ; then rc_halt "zfs unmount ${ZPOOLNAME}${ZMNT}" rc_halt "zfs set mountpoint=${ZMNT} ${ZPOOLNAME}${ZMNT}" fi sleep 2 done fi done }; # Function which performs the specific setup for using a /boot partition setup_dedicated_boot_part() { ROOTFS="${1}" ROOTFSTYPE="${2}" BOOTFS="${3}" BOOTMNT="${4}" # Set the root mount in loader.conf echo "vfs.root.mountfrom=\"${ROOTFSTYPE}:${ROOTFS}\"" >> ${FSMNT}/boot/loader.conf rc_halt "mkdir -p ${FSMNT}/${BOOTMNT}/boot" rc_halt "mv ${FSMNT}/boot/* ${FSMNT}${BOOTMNT}/boot/" rc_halt "mv ${FSMNT}${BOOTMNT}/boot ${FSMNT}/boot/" rc_halt "umount ${BOOTFS}" rc_halt "mount ${BOOTFS} ${FSMNT}${BOOTMNT}" rc_halt "rmdir ${FSMNT}/boot" # Strip the '/' from BOOTMNT before making symlink BOOTMNTNS="`echo ${BOOTMNT} | sed 's|/||g'`" rc_halt "chroot ${FSMNT} ln -s ${BOOTMNTNS}/boot /boot" }; # Function which creates the /etc/fstab for the installed system setup_fstab() { FSTAB="${FSMNT}/etc/fstab" rm ${FSTAB} >/dev/null 2>/dev/null # Create the header echo "# Device Mountpoint FStype Options Dump Pass" >> ${FSTAB} # Loop through the partitions, and start creating /etc/fstab for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`" # Unset EXT EXT="" # Set mount options for file-systems case $PARTFS in UFS+J) MNTOPTS="rw,noatime,async" ;; SWAP) MNTOPTS="sw" ;; *) MNTOPTS="rw,noatime" ;; esac # Figure out if we are using a glabel, or the raw name for this entry if [ -n "${PARTLABEL}" ] then DEVICE="label/${PARTLABEL}" else # Check if using encryption if [ "${PARTENC}" = "ON" ] ; then EXT=".eli" fi if [ "${PARTFS}" = "UFS+J" ] ; then EXT="${EXT}.journal" fi DEVICE="${PARTDEV}${EXT}" fi # Set our ROOTFSTYPE for loader.conf if necessary check_for_mount "${PARTMNT}" "/" if [ $? -eq 0 ] ; then if [ "${PARTFS}" = "ZFS" ] ; then ROOTFSTYPE="zfs" ZPOOLNAME=$(get_zpool_name "${PARTDEV}") ROOTFS="${ZPOOLNAME}/ROOT/default" else ROOTFS="${DEVICE}" ROOTFSTYPE="ufs" fi fi # Only create non-zfs partitions if [ "${PARTFS}" != "ZFS" ] then # Make sure geom_journal is loaded if [ "${PARTFS}" = "UFS+J" ] ; then setup_gjournal fi # Save the BOOTFS for call at the end if [ "${PARTMNT}" = "/boot" ] ; then BOOTFS="${PARTDEV}${EXT}" BOOTMNT="${BOOT_PART_MOUNT}" PARTMNT="${BOOTMNT}" fi # Echo out the fstab entry now if [ "${PARTFS}" = "SWAP" ] then echo "/dev/${DEVICE} none swap ${MNTOPTS} 0 0" >> ${FSTAB} else echo "/dev/${DEVICE} ${PARTMNT} ufs ${MNTOPTS} 1 1" >> ${FSTAB} fi fi # End of ZFS Check done # Setup some specific PC-BSD fstab options if [ "$INSTALLTYPE" != "FreeBSD" ] then echo "procfs /proc procfs rw 0 0" >> ${FSTAB} echo "linprocfs /compat/linux/proc linprocfs rw 0 0" >> ${FSTAB} fi # If we have a dedicated /boot, run the post-install setup of it now if [ ! -z "${BOOTMNT}" ] ; then setup_dedicated_boot_part "${ROOTFS}" "${ROOTFSTYPE}" "${BOOTFS}" "${BOOTMNT}" fi }; # Setup our disk mirroring with gmirror setup_gmirror() { cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_mirror_load="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'geom_mirror_load="YES"' >>${FSMNT}/boot/loader.conf fi }; # Function which saves geli keys and sets up loading of them at boot setup_geli_loading() { # Make our keys dir mkdir -p ${FSMNT}/boot/keys >/dev/null 2>/dev/null cd ${GELIKEYDIR} for KEYFILE in `ls` do # Figure out the partition name based on keyfile name removing .key PART="`echo ${KEYFILE} | cut -d '.' -f 1`" PARTDEV="`echo ${PART} | sed 's|-|/|g'`" PARTNAME="`echo ${PART} | sed 's|-dev-||g'`" rc_halt "geli configure -b ${PARTDEV}" # If no passphrase, setup key files if [ ! -e "${PARTDIR}-enc/${PART}-encpass" ] ; then echo "geli_${PARTNAME}_keyfile0_load=\"YES\"" >> ${FSMNT}/boot/loader.conf echo "geli_${PARTNAME}_keyfile0_type=\"${PARTNAME}:geli_keyfile0\"" >> ${FSMNT}/boot/loader.conf echo "geli_${PARTNAME}_keyfile0_name=\"/boot/keys/${PARTNAME}.key\"" >> ${FSMNT}/boot/loader.conf # Copy the key to the disk rc_halt "cp ${GELIKEYDIR}/${KEYFILE} ${FSMNT}/boot/keys/${PARTNAME}.key" fi done # Make sure we have geom_eli set to load at boot cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_eli_load="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'geom_eli_load="YES"' >>${FSMNT}/boot/loader.conf fi }; # Function to generate a random hostname if none was specified gen_hostname() { RAND="`jot -r 1 1 9000`" if [ "$INSTALLTYPE" = "FreeBSD" ] then VAL="freebsd-${RAND}" else VAL="pcbsd-${RAND}" fi export VAL }; # Function which sets up the hostname for the system setup_hostname() { get_value_from_cfg hostname HOSTNAME="${VAL}" # If we don't have a hostname, make one up if [ -z "${HOSTNAME}" ] then gen_hostname HOSTNAME="${VAL}" fi # Clean up any saved hostname cat ${FSMNT}/etc/rc.conf | grep -v "hostname=" >${FSMNT}/etc/rc.conf.new mv ${FSMNT}/etc/rc.conf.new ${FSMNT}/etc/rc.conf # Set the hostname now echo_log "Setting hostname: ${HOSTNAME}" echo "hostname=\"${HOSTNAME}\"" >> ${FSMNT}/etc/rc.conf sed -i -e "s|my.domain|${HOSTNAME} ${HOSTNAME}|g" ${FSMNT}/etc/hosts }; # Check and make sure geom_journal is enabled on the system setup_gjournal() { # Make sure we have geom_journal set to load at boot cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_journal_load="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'geom_journal_load="YES"' >>${FSMNT}/boot/loader.conf fi }; # Function which sets the root password from the install config set_root_pw() { # Get the plaintext string get_value_from_cfg_with_spaces rootPass local PW="${VAL}" # Get the encrypted string get_value_from_cfg_with_spaces rootEncPass local ENCPW="${VAL}" # If we don't have a root pass, return if [ -z "${PW}" -a -z "${ENCPW}" ] ; then return 0 ; fi echo_log "Setting root password" # Check if setting plaintext password if [ -n "${PW}" ] ; then echo "${PW}" > ${FSMNT}/.rootpw run_chroot_cmd "cat /.rootpw | pw usermod root -h 0" rc_halt "rm ${FSMNT}/.rootpw" fi # Check if setting encrypted password if [ -n "${ENCPW}" ] ; then echo "${ENCPW}" > ${FSMNT}/.rootpw run_chroot_cmd "cat /.rootpw | pw usermod root -H 0" rc_halt "rm ${FSMNT}/.rootpw" fi }; run_final_cleanup() { # Check if we need to run any gmirror setup ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null if [ $? -eq 0 ] then # Lets setup gmirror now setup_gmirror fi # Check if we need to save any geli keys ls ${GELIKEYDIR}/* >/dev/null 2>/dev/null if [ $? -eq 0 ] then # Lets setup geli loading setup_geli_loading fi # Set a hostname on the install system setup_hostname # Set the root_pw if it is specified set_root_pw # Generate the fstab for the installed system setup_fstab }; Index: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh (revision 326275) @@ -1,908 +1,910 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions related to disk operations using gpart # See if device is a full disk or partition/slice is_disk() { for _dsk in `sysctl -n kern.disks` do [ "$_dsk" = "${1}" ] && return 0 [ "/dev/$_dsk" = "${1}" ] && return 0 done return 1 } # Get a MBR partitions sysid get_partition_sysid_mbr() { INPART="0" DISK="$1" PARTNUM=`echo ${2} | sed "s|${DISK}s||g"` fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null while read i do echo "$i" | grep -q "The data for partition" 2>/dev/null if [ $? -eq 0 ] ; then INPART="0" PART="`echo ${i} | cut -d ' ' -f 5`" if [ "$PART" = "$PARTNUM" ] ; then INPART="1" fi fi # In the partition section if [ "$INPART" = "1" ] ; then echo "$i" | grep -q "^sysid" 2>/dev/null if [ $? -eq 0 ] ; then SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`" break fi fi done < ${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${SYSID}" }; # Get the partitions MBR label get_partition_label_mbr() { INPART="0" DISK="$1" PARTNUM=`echo ${2} | sed "s|${DISK}s||g"` fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null while read i do echo "$i" | grep -q "The data for partition" 2>/dev/null if [ $? -eq 0 ] ; then INPART="0" PART="`echo ${i} | cut -d ' ' -f 5`" if [ "$PART" = "$PARTNUM" ] ; then INPART="1" fi fi # In the partition section if [ "$INPART" = "1" ] ; then echo "$i" | grep -q "^sysid" 2>/dev/null if [ $? -eq 0 ] ; then LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`" break fi fi done < ${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${LABEL}" }; # Get a GPT partitions label get_partition_label_gpt() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "${SLICE}" = "${PARTNUM}" ] ; then LABEL="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${LABEL}" }; # Get a partitions startblock get_partition_startblock() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "$SLICE" = "${PARTNUM}" ] ; then SB="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 1`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${SB}" }; # Get a partitions blocksize get_partition_blocksize() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "$SLICE" = "${PARTNUM}" ] ; then BS="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 2`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${BS}" }; # Function which returns the partitions on a target disk get_disk_partitions() { gpart show ${1} >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then export VAL="" return fi type=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'` SLICES="`gpart show ${1} | grep -v ${1} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d'`" for i in ${SLICES} do case $type in MBR) name="${1}s${i}" ;; GPT) name="${1}p${i}";; *) name="${1}s${i}";; esac if [ -z "${RSLICES}" ] then RSLICES="${name}" else RSLICES="${RSLICES} ${name}" fi done export VAL="${RSLICES}" }; # Function which returns a target disks cylinders get_disk_cyl() { cyl=`diskinfo -v ${1} | grep "# Cylinders" | tr -s ' ' | cut -f 2` export VAL="${cyl}" }; # Function which returns a target disks sectors get_disk_sectors() { sec=`diskinfo -v ${1} | grep "# Sectors" | tr -s ' ' | cut -f 2` export VAL="${sec}" }; # Function which returns a target disks heads get_disk_heads() { head=`diskinfo -v ${1} | grep "# Heads" | tr -s ' ' | cut -f 2` export VAL="${head}" }; # Function which returns a target disks mediasize in sectors get_disk_mediasize() { mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2` export VAL="${mediasize}" }; # Function which returns a target disks mediasize in megabytes get_disk_mediasize_mb() { mediasize=`diskinfo -v ${1} | grep "# mediasize in bytes" | tr -s ' ' | cut -f 2` mediasize=`expr $mediasize / 1024` mediasize=`expr $mediasize / 1024` export VAL="${mediasize}" }; # Function to delete all gparts before starting an install delete_all_gpart() { echo_log "Deleting all gparts" local DISK="$1" # Check for any swaps to stop for i in `swapctl -l | grep "$DISK" | awk '{print $1}'` do swapoff ${i} >/dev/null 2>/dev/null done # Delete the gparts now for i in `gpart show ${DISK} 2>/dev/null | tr -s ' ' | cut -d ' ' -f 4` do if [ "/dev/${i}" != "${DISK}" -a "${i}" != "-" ] ; then rc_nohalt "gpart delete -i ${i} ${DISK}" fi done # Destroy the disk geom rc_nohalt "gpart destroy ${DISK}" wipe_metadata "${DISK}" }; # Function to export all zpools before starting an install stop_all_zfs() { if [ ! -c /dev/zfs ]; then return; fi local DISK="`echo ${1} | sed 's|/dev/||g'`" # Export any zpools using this device so we can overwrite for i in `zpool list -H -o name` do ztst=`zpool status ${i} | grep "ONLINE" | awk '{print $1}' | grep -q ${DISK}` if [ "$ztst" = "$DISK" ] ; then zpool export -f ${i} fi done }; # Function which stops all gmirrors before doing any disk manipulation stop_all_gmirror() { if [ ! -d /dev/mirror ]; then return; fi local DISK="`echo ${1} | sed 's|/dev/||g'`" GPROV="`gmirror list | grep ". Name: mirror/" | cut -d '/' -f 2`" for gprov in $GPROV do gmirror list | grep -q "Name: ${DISK}" 2>/dev/null if [ $? -eq 0 ] then echo_log "Stopping mirror $gprov $DISK" rc_nohalt "gmirror remove $gprov $DISK" wipe_metadata "${DISK}" fi done }; # Make sure we don't have any geli providers active on this disk stop_all_geli() { local _geld="`echo ${1} | sed 's|/dev/||g'`" cd /dev for i in `ls ${_geld}*` do echo $i | grep -q '.eli' 2>/dev/null if [ $? -eq 0 ] then echo_log "Detaching GELI on ${i}" rc_halt "geli detach ${i}" fi done }; # Function which reads in the disk slice config, and performs it setup_disk_slice() { # Cleanup any slice / mirror dirs rm -rf ${SLICECFGDIR} >/dev/null 2>/dev/null mkdir ${SLICECFGDIR} rm -rf ${MIRRORCFGDIR} >/dev/null 2>/dev/null mkdir ${MIRRORCFGDIR} # Start with disk0 and gm0 disknum="0" gmnum="0" # We are ready to start setting up the disks, lets read the config and do the actions while read line do echo $line | grep -q "^disk${disknum}=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" DISK="$VAL" echo "${DISK}" | grep -q '^/dev/' if [ $? -ne 0 ] ; then DISK="/dev/$DISK" ; fi # Before we go further, lets confirm this disk really exists if [ ! -e "${DISK}" ] ; then exit_err "ERROR: The disk ${DISK} does not exist!" fi # Make sure we stop any gmirrors on this disk stop_all_gmirror ${DISK} # Make sure we stop any geli stuff on this disk stop_all_geli ${DISK} # Make sure we don't have any zpools loaded stop_all_zfs ${DISK} fi # Lets look if this device will be mirrored on another disk echo $line | grep -q "^mirror=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" MIRRORDISK="$VAL" echo "${MIRRORDISK}" | grep -q '^/dev/' if [ $? -ne 0 ] ; then MIRRORDISK="/dev/$MIRRORDISK" ; fi # Before we go further, lets confirm this disk really exists if [ ! -e "${MIRRORDISK}" ] then exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!" fi # Make sure we stop any gmirrors on this mirror disk stop_all_gmirror ${MIRRORDISK} # Make sure we stop any geli stuff on this mirror disk stop_all_geli ${MIRRORDISK} # Make sure we don't have any zpools mirror loaded stop_all_zfs ${MIRRORDISK} fi # Lets see if we have been given a mirror balance choice echo $line | grep -q "^mirrorbal=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" MIRRORBAL="$VAL" fi echo $line | grep -q "^partition=" 2>/dev/null if [ $? -eq 0 ] then # Found a partition= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" PTYPE=`echo $VAL|tr A-Z a-z` # We are using free space, figure out the slice number if [ "${PTYPE}" = "free" ] then # Lets figure out what number this slice will be LASTSLICE="`gpart show ${DISK} \ | grep -v ${DISK} \ | grep -v ' free' \ | tr -s '\t' ' ' \ | cut -d ' ' -f 4 \ | sed '/^$/d' \ | tail -n 1`" if [ -z "${LASTSLICE}" ] then LASTSLICE="1" else LASTSLICE=$((LASTSLICE+1)) fi if [ $LASTSLICE -gt 4 ] then exit_err "ERROR: BSD only supports primary partitions, and there are none available on $DISK" fi fi fi # Check if we have an image file defined echo $line | grep -q "^image=" 2>/dev/null if [ $? -eq 0 ] ; then # Found an image= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" IMAGE="$VAL" if [ ! -f "$IMAGE" ] ; then exit_err "$IMAGE file does not exist" fi fi # Check if we have a partscheme specified echo $line | grep -q "^partscheme=" 2>/dev/null if [ $? -eq 0 ] ; then # Found a partscheme= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" PSCHEME="$VAL" if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then exit_err "Unknown partition scheme: $PSCHEME" fi fi echo $line | grep -q "^bootManager=" 2>/dev/null if [ $? -eq 0 ] then # Found a bootManager= entry, lets read /set it get_value_from_string "${line}" strip_white_space "$VAL" BMANAGER="$VAL" fi echo $line | grep -q "^commitDiskPart" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this disk setup / lets do sanity check and do it if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ] then # Make sure we are only installing ppc to full disk if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ]; then if [ "$PTYPE" != "all" ] ; then exit_err "powerpc can only be installed to a full disk" fi fi case ${PTYPE} in all) # If we have a gmirror, lets set it up if [ -n "$MIRRORDISK" ]; then # Default to round-robin if the user didn't specify if [ -z "$MIRRORBAL" ]; then MIRRORBAL="round-robin" ; fi _mFile=`echo $DISK | sed 's|/|%|g'` echo "$MIRRORDISK:$MIRRORBAL:gm${gmnum}" >${MIRRORCFGDIR}/$_mFile init_gmirror "$gmnum" "$MIRRORBAL" "$DISK" "$MIRRORDISK" # Reset DISK to the gmirror device DISK="/dev/mirror/gm${gmnum}" gmnum=$((gmknum+1)) fi if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then PSCHEME="MBR" tmpSLICE="${DISK}s1" else tmpSLICE="${DISK}p1" fi if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ] then PSCHEME="APM" tmpSLICE="${DISK}s1" fi run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}" ;; s1|s2|s3|s4) tmpSLICE="${DISK}${PTYPE}" # Get the number of the slice we are working on s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" run_gpart_slice "${DISK}" "${BMANAGER}" "${s}" ;; p1|p2|p3|p4|p5|p6|p7|p8|p9|p10|p11|p12|p13|p14|p15|p16|p17|p18|p19|p20) tmpSLICE="${DISK}${PTYPE}" # Get the number of the gpt partition we are working on s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" run_gpart_gpt_part "${DISK}" "${BMANAGER}" "${s}" ;; free) tmpSLICE="${DISK}s${LASTSLICE}" run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}" ;; image) if [ -z "${IMAGE}" ] then exit_err "ERROR: partition type image specified with no image!" fi ;; *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;; esac if [ -n "${IMAGE}" ] then local DEST if [ -n "${tmpSLICE}" ] then DEST="${tmpSLICE}" else DEST="${DISK}" fi write_image "${IMAGE}" "${DEST}" check_disk_layout "${DEST}" fi # Now save which disk this is, so we can parse it later during slice partition setup if [ -z "${IMAGE}" ] then _sFile=`echo $tmpSLICE | sed 's|/|-|g'` echo "disk${disknum}" >${SLICECFGDIR}/$_sFile fi # Increment our disk counter to look for next disk and unset unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE disknum=$((disknum+1)) else exit_err "ERROR: commitDiskPart was called without procceding disk= and partition= entries!!!" fi fi done <${CFGF} }; # Init the gmirror device init_gmirror() { local _mNum=$1 local _mBal=$2 local _mDisk=$3 # Create this mirror device rc_halt "gmirror label -vb ${_mBal} gm${_mNum} ${_mDisk}" sleep 3 } # Stop all gjournals on disk / slice stop_gjournal() { _gdsk="`echo $1 | sed 's|/dev/||g'`" # Check if we need to shutdown any journals on this drive ls /dev/${_gdsk}*.journal >/dev/null 2>/dev/null if [ $? -eq 0 ] then cd /dev for i in `ls ${_gdsk}*.journal` do rawjournal="`echo ${i} | cut -d '.' -f 1`" gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} done fi } ; # Function to wipe the potential metadata from a disk wipe_metadata() { echo_log "Wiping possible metadata on ${1}" local SIZE="`diskinfo ${1} | awk '{print int($3/(1024*1024)) }'`" if [ "$SIZE" -gt "5" ] ; then rc_halt "dd if=/dev/zero of=${1} bs=1m count=1" rc_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=$((SIZE-4))" else rc_nohalt "dd if=/dev/zero of=${1} bs=128k" fi } ; # Function which runs gpart and creates a single large APM partition scheme init_apm_full_disk() { _intDISK=$1 # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Stop any journaling stop_gjournal "${_intDISK}" # Remove any existing partitions delete_all_gpart "${_intDISK}" sleep 2 echo_log "Running gpart on ${_intDISK}" rc_halt "gpart create -s APM ${_intDISK}" rc_halt "gpart add -s 800k -t freebsd-boot ${_intDISK}" echo_log "Stamping boot sector on ${_intDISK}" rc_halt "gpart bootcode -p /boot/boot1.hfs -i 1 ${_intDISK}" } # Function which runs gpart and creates a single large GPT partition scheme init_gpt_full_disk() { _intDISK=$1 # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Stop any journaling stop_gjournal "${_intDISK}" # Remove any existing partitions delete_all_gpart "${_intDISK}" sleep 2 echo_log "Running gpart on ${_intDISK}" rc_halt "gpart create -s GPT ${_intDISK}" rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}" echo_log "Stamping boot sector on ${_intDISK}" rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}" } # Function which runs gpart and creates a single large MBR partition scheme init_mbr_full_disk() { _intDISK=$1 _intBOOT=$2 startblock="2016" # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Stop any journaling stop_gjournal "${_intDISK}" # Remove any existing partitions delete_all_gpart "${_intDISK}" sleep 2 echo_log "Running gpart on ${_intDISK}" rc_halt "gpart create -s mbr -f active ${_intDISK}" # Install new partition setup echo_log "Running gpart add on ${_intDISK}" rc_halt "gpart add -a 4k -t freebsd -i 1 ${_intDISK}" sleep 2 wipe_metadata "${_intDISK}s1" # Make the partition active rc_halt "gpart set -a active -i 1 ${_intDISK}" if [ "$_intBOOT" = "bsd" ] ; then echo_log "Stamping boot0 on ${_intDISK}" rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}" else echo_log "Stamping boot1 on ${_intDISK}" rc_halt "gpart bootcode -b /boot/boot1 ${_intDISK}" fi } # Function which runs gpart and creates a single large slice run_gpart_full() { DISK=$1 BOOT=$2 SCHEME=$3 if [ "$SCHEME" = "APM" ] ; then init_apm_full_disk "$DISK" slice=`echo "${DISK}:1:apm" | sed 's|/|-|g'` elif [ "$SCHEME" = "MBR" ] ; then init_mbr_full_disk "$DISK" "$BOOT" slice=`echo "${DISK}:1:mbr" | sed 's|/|-|g'` else init_gpt_full_disk "$DISK" slice=`echo "${DISK}:1:gpt" | sed 's|/|-|g'` fi # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; # Function which runs gpart on a specified gpt partition run_gpart_gpt_part() { DISK=$1 # Set the slice we will use later slice="${1}p${3}" # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Get the number of the slice we are working on slicenum="$3" # Stop any journaling stop_gjournal "${slice}" # Make sure we have disabled swap on this drive if [ -e "${slice}b" ] then swapoff ${slice}b >/dev/null 2>/dev/null swapoff ${slice}b.eli >/dev/null 2>/dev/null fi # Modify partition type echo_log "Running gpart modify on ${DISK}" rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}" sleep 2 wipe_metadata "${slice}" sleep 4 # Init the MBR partition rc_halt "gpart create -s BSD ${DISK}p${slicenum}" # Stamp the bootloader sleep 4 rc_halt "gpart bootcode -b /boot/boot ${DISK}p${slicenum}" # Set the slice to the format we'll be using for gpart later slice=`echo "${1}:${3}:gptslice" | sed 's|/|-|g'` # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; # Function which runs gpart on a specified s1-4 slice run_gpart_slice() { DISK=$1 if [ -n "$2" ] then BMANAGER="$2" fi # Set the slice we will use later slice="${1}s${3}" # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Get the number of the slice we are working on slicenum="$3" # Stop any journaling stop_gjournal "${slice}" # Make sure we have disabled swap on this drive if [ -e "${slice}b" ] then swapoff ${slice}b >/dev/null 2>/dev/null swapoff ${slice}b.eli >/dev/null 2>/dev/null fi # Modify partition type echo_log "Running gpart modify on ${DISK}" rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}" sleep 2 wipe_metadata "${slice}" sleep 1 if [ "${BMANAGER}" = "bsd" ] then echo_log "Stamping boot sector on ${DISK}" rc_halt "gpart bootcode -b /boot/boot0 ${DISK}" fi # Set the slice to the format we'll be using for gpart later slice=`echo "${1}:${3}:mbr" | sed 's|/|-|g'` # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; # Function which runs gpart and creates a new slice from free disk space run_gpart_free() { DISK=$1 SLICENUM=$2 if [ -n "$3" ] then BMANAGER="$3" fi # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} slice="${DISK}s${SLICENUM}" slicenum="${SLICENUM}" # Working on the first slice, make sure we have MBR setup gpart show ${DISK} >/dev/null 2>/dev/null if [ $? -ne 0 -a "$SLICENUM" = "1" ] ; then echo_log "Initializing disk, no existing MBR setup" rc_halt "gpart create -s mbr ${DISK}" fi # Install new partition setup echo_log "Running gpart on ${DISK}" rc_halt "gpart add -a 4k -t freebsd -i ${slicenum} ${DISK}" sleep 2 wipe_metadata "${slice}" sleep 1 if [ "${BMANAGER}" = "bsd" ] then echo_log "Stamping boot sector on ${DISK}" rc_halt "gpart bootcode -b /boot/boot0 ${DISK}" fi slice=`echo "${DISK}:${SLICENUM}:mbr" | sed 's|/|-|g'` # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; Index: head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh (revision 326275) @@ -1,552 +1,554 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which perform the extraction / installation of system to disk . ${BACKEND}/functions-mountoptical.sh # Performs the extraction of data to disk from FreeBSD dist files start_extract_dist() { if [ -z "$1" ] ; then exit_err "Called dist extraction with no directory set!"; fi if [ -z "$INSFILE" ]; then exit_err "Called extraction with no install file set!"; fi local DDIR="$1" # Check if we are doing an upgrade, and if so use our exclude list if [ "${INSTALLMODE}" = "upgrade" ]; then TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade" else TAROPTS="" fi # Loop though and extract dist files for di in $INSFILE do # Check the MANIFEST see if we have an archive size / count if [ -e "${DDIR}/MANIFEST" ]; then count=`grep "^${di}.txz" ${DDIR}/MANIFEST | awk '{print $3}'` if [ ! -z "$count" ] ; then echo "INSTALLCOUNT: $count" fi fi echo_log "pc-sysinstall: Starting Extraction (${di})" tar -xpv -C ${FSMNT} -f ${DDIR}/${di}.txz ${TAROPTS} >&1 2>&1 if [ $? -ne 0 ]; then exit_err "ERROR: Failed extracting the dist file: $di" fi done # Check if this was a FTP download and clean it up now if [ "${INSTALLMEDIUM}" = "ftp" ]; then echo_log "Cleaning up downloaded archives" rm -rf ${DDIR} fi echo_log "pc-sysinstall: Extraction Finished" } # Performs the extraction of data to disk from a uzip or tar archive start_extract_uzip_tar() { if [ -z "$INSFILE" ]; then exit_err "ERROR: Called extraction with no install file set!" fi # Check if we have a .count file, and echo it out for a front-end to use in progress bars if [ -e "${INSFILE}.count" ]; then echo "INSTALLCOUNT: `cat ${INSFILE}.count`" fi # Check if we are doing an upgrade, and if so use our exclude list if [ "${INSTALLMODE}" = "upgrade" ]; then TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade" else TAROPTS="" fi echo_log "pc-sysinstall: Starting Extraction" case ${PACKAGETYPE} in uzip) if ! kldstat -v | grep -q "geom_uzip" ; then exit_err "Kernel module geom_uzip not loaded" fi # Start by mounting the uzip image MDDEVICE=`mdconfig -a -t vnode -o readonly -f ${INSFILE}` mkdir -p ${FSMNT}.uzip mount -r /dev/${MDDEVICE}.uzip ${FSMNT}.uzip if [ $? -ne 0 ] then exit_err "ERROR: Failed mounting the ${INSFILE}" fi cd ${FSMNT}.uzip # Copy over all the files now! tar cvf - . 2>/dev/null | tar -xpv -C ${FSMNT} ${TAROPTS} -f - 2>&1 | tee -a ${FSMNT}/.tar-extract.log if [ $? -ne 0 ] then cd / echo "TAR failure occurred:" >>${LOGOUT} cat ${FSMNT}/.tar-extract.log | grep "tar:" >>${LOGOUT} umount ${FSMNT}.uzip mdconfig -d -u ${MDDEVICE} exit_err "ERROR: Failed extracting the tar image" fi # All finished, now lets umount and cleanup cd / umount ${FSMNT}.uzip mdconfig -d -u ${MDDEVICE} ;; tar) tar -xpv -C ${FSMNT} -f ${INSFILE} ${TAROPTS} >&1 2>&1 if [ $? -ne 0 ]; then exit_err "ERROR: Failed extracting the tar image" fi ;; esac # Check if this was a FTP download and clean it up now if [ "${INSTALLMEDIUM}" = "ftp" ] then echo_log "Cleaning up downloaded archive" rm ${INSFILE} rm ${INSFILE}.count >/dev/null 2>/dev/null rm ${INSFILE}.md5 >/dev/null 2>/dev/null fi echo_log "pc-sysinstall: Extraction Finished" }; # Performs the extraction of data to disk from a directory with split files start_extract_split() { if [ -z "${INSDIR}" ] then exit_err "ERROR: Called extraction with no install directory set!" fi echo_log "pc-sysinstall: Starting Extraction" # Used by install.sh DESTDIR="${FSMNT}" export DESTDIR HERE=`pwd` DIRS=`ls -d ${INSDIR}/*|grep -Ev '(uzip|kernels|src)'` for dir in ${DIRS} do cd "${dir}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${dir}` echo "y" | sh install.sh >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${dir}" fi else exit_err "ERROR: ${dir}/install.sh does not exist" fi done cd "${HERE}" KERNELS=`ls -d ${INSDIR}/*|grep kernels` cd "${KERNELS}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${KERNELS}` echo "y" | sh install.sh generic >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${KERNELS}" fi rm -rf "${FSMNT}/boot/kernel" mv "${FSMNT}/boot/GENERIC" "${FSMNT}/boot/kernel" else exit_err "ERROR: ${KERNELS}/install.sh does not exist" fi cd "${HERE}" SOURCE=`ls -d ${INSDIR}/*|grep src` cd "${SOURCE}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${SOURCE}` echo "y" | sh install.sh all >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${SOURCE}" fi else exit_err "ERROR: ${SOURCE}/install.sh does not exist" fi cd "${HERE}" echo_log "pc-sysinstall: Extraction Finished" }; # Function which will attempt to fetch the dist file(s) before we start fetch_dist_file() { get_value_from_cfg ftpPath if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" fi FTPPATH="${VAL}" # Check if we have a /usr partition to save the download if [ -d "${FSMNT}/usr" ] then DLDIR="${FSMNT}/usr/.fetch.$$" else DLDIR="${FSMNT}/.fetch.$$" fi mkdir -p ${DLDIR} # Do the fetch of the dist archive(s) now for di in $INSFILE do fetch_file "${FTPPATH}/${di}.txz" "${DLDIR}/${di}.txz" "1" done # Check to see if there is a MANIFEST file for this install fetch_file "${FTPPATH}/MANIFEST" "${DLDIR}/MANIFEST" "0" export DLDIR }; # Function which will attempt to fetch the install file before we start # the install fetch_install_file() { get_value_from_cfg ftpPath if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" fi FTPPATH="${VAL}" # Check if we have a /usr partition to save the download if [ -d "${FSMNT}/usr" ] then OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}" else OUTFILE="${FSMNT}/.fetch-${INSFILE}" fi # Do the fetch of the archive now fetch_file "${FTPPATH}/${INSFILE}" "${OUTFILE}" "1" # Check to see if there is a .count file for this install fetch_file "${FTPPATH}/${INSFILE}.count" "${OUTFILE}.count" "0" # Check to see if there is a .md5 file for this install fetch_file "${FTPPATH}/${INSFILE}.md5" "${OUTFILE}.md5" "0" # Done fetching, now reset the INSFILE to our downloaded archived export INSFILE="${OUTFILE}" }; # Function which will download freebsd install files fetch_split_files() { get_ftpHost if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" fi FTPHOST="${VAL}" get_ftpDir if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" fi FTPDIR="${VAL}" # Check if we have a /usr partition to save the download if [ -d "${FSMNT}/usr" ] then OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}" else OUTFILE="${FSMNT}/.fetch-${INSFILE}" fi DIRS="base catpages dict doc info manpages proflibs kernels src" if [ "${FBSD_ARCH}" = "amd64" ] then DIRS="${DIRS} lib32" fi for d in ${DIRS} do mkdir -p "${OUTFILE}/${d}" done NETRC="${OUTFILE}/.netrc" cat <"${NETRC}" machine ${FTPHOST} login anonymous password anonymous macdef INSTALL bin prompt EOF for d in ${DIRS} do cat <>"${NETRC}" cd ${FTPDIR}/${d} lcd ${OUTFILE}/${d} mreget * EOF done cat <>"${NETRC}" bye EOF # Fetch the files via ftp echo "$ INSTALL" | ftp -N "${NETRC}" "${FTPHOST}" # Done fetching, now reset the INSFILE to our downloaded archived export INSFILE="${OUTFILE}" } # Function which does the rsync download from the server specified in cfg start_rsync_copy() { # Load our rsync config values get_value_from_cfg rsyncPath if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncPath is unset! Please check your config and try again." fi export RSYNCPATH="${VAL}" get_value_from_cfg rsyncHost if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncHost is unset! Please check your config and try again." fi export RSYNCHOST="${VAL}" get_value_from_cfg rsyncUser if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncUser is unset! Please check your config and try again." fi export RSYNCUSER="${VAL}" get_value_from_cfg rsyncPort if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncPort is unset! Please check your config and try again." fi export RSYNCPORT="${VAL}" COUNT=1 while z=1 do if [ ${COUNT} -gt ${RSYNCTRIES} ] then exit_err "ERROR: Failed rsync command!" break fi rsync -avvzHsR \ --rsync-path="rsync --fake-super" \ -e "ssh -p ${RSYNCPORT}" \ ${RSYNCUSER}@${RSYNCHOST}:${RSYNCPATH}/./ ${FSMNT} if [ $? -ne 0 ] then echo "Rsync failed! Tries: ${COUNT}" else break fi COUNT=$((COUNT+1)) done }; start_image_install() { if [ -z "${IMAGE_FILE}" ] then exit_err "ERROR: installMedium set to image but no image file specified!" fi # We are ready to start mounting, lets read the config and do it while read line do echo $line | grep -q "^disk0=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" DISK="$VAL" fi echo $line | grep -q "^commitDiskPart" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this disk setup / lets do sanity check and do it if [ -n "${DISK}" ] then # Write the image write_image "${IMAGE_FILE}" "${DISK}" # Increment our disk counter to look for next disk and unset unset DISK break else exit_err "ERROR: commitDiskPart was called without procceding disk= and partition= entries!!!" fi fi done <${CFGF} }; # Entrance function, which starts the installation process init_extraction() { # Figure out what file we are using to install from via the config get_value_from_cfg installFile if [ -n "${VAL}" ] then export INSFILE="${VAL}" else # If no installFile specified, try our defaults if [ "$INSTALLTYPE" = "FreeBSD" ] then case $PACKAGETYPE in uzip) INSFILE="${FBSD_UZIP_FILE}" ;; tar) INSFILE="${FBSD_TAR_FILE}" ;; dist) get_value_from_cfg_with_spaces distFiles if [ -z "$VAL" ] ; then exit_err "No dist files specified!" fi INSFILE="${VAL}" ;; split) INSDIR="${FBSD_BRANCH_DIR}" # This is to trick opt_mount into not failing INSFILE="${INSDIR}" ;; esac else case $PACKAGETYPE in uzip) INSFILE="${UZIP_FILE}" ;; tar) INSFILE="${TAR_FILE}" ;; dist) get_value_from_cfg_with_spaces distFiles if [ -z "$VAL" ] ; then exit_err "No dist files specified!" fi INSFILE="${VAL}" ;; esac fi export INSFILE fi # Lets start by figuring out what medium we are using case ${INSTALLMEDIUM} in dvd|usb) # Lets start by mounting the disk opt_mount if [ -n "${INSDIR}" ] then INSDIR="${CDMNT}/${INSDIR}" ; export INSDIR start_extract_split else if [ "$PACKAGETYPE" = "dist" ] ; then start_extract_dist "${CDMNT}/usr/freebsd-dist" else INSFILE="${CDMNT}/${INSFILE}" ; export INSFILE start_extract_uzip_tar fi fi ;; ftp) case $PACKAGETYPE in split) fetch_split_files INSDIR="${INSFILE}" ; export INSDIR start_extract_split ;; dist) fetch_dist_file start_extract_dist "$DLDIR" ;; *) fetch_install_file start_extract_uzip_tar ;; esac ;; sftp) ;; rsync) start_rsync_copy ;; image) start_image_install ;; local) get_value_from_cfg localPath if [ -z "$VAL" ] then exit_err "Install medium was set to local, but no localPath was provided!" fi LOCALPATH=$VAL if [ "$PACKAGETYPE" = "dist" ] ; then INSFILE="${INSFILE}" ; export INSFILE start_extract_dist "$LOCALPATH" else INSFILE="${LOCALPATH}/${INSFILE}" ; export INSFILE start_extract_uzip_tar fi ;; *) exit_err "ERROR: Unknown install medium" ;; esac }; Index: head/usr.sbin/pc-sysinstall/backend/functions-ftp.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-ftp.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-ftp.sh (revision 326275) @@ -1,414 +1,416 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh DEFAULT_FTP_SERVER="ftp.freebsd.org" MAIN_FTP_SERVERS="\ Main Site: ftp.freebsd.org" IPV6_FTP_SERVERS="\ IPv6 Main Site: ftp.freebsd.org|\ IPv6 Ireland: ftp3.ie.freebsd.org|\ IPv6 Israel: ftp.il.freebsd.org|\ IPv6 Japan: ftp2.jp.freebsd.org|\ IPv6 Sweden: ftp4.se.freebsd.org|\ IPv6 USA: ftp4.us.freebsd.org|\ IPv6 Turkey: ftp2.tr.freebsd.org" PRIMARY_FTP_SERVERS="\ Primary: ftp1.freebsd.org|\ Primary #2: ftp2.freebsd.org|\ Primary #3: ftp3.freebsd.org|\ Primary #4: ftp4.freebsd.org|\ Primary #5: ftp5.freebsd.org|\ Primary #6: ftp6.freebsd.org|\ Primary #7: ftp7.freebsd.org|\ Primary #8: ftp8.freebsd.org|\ Primary #9: ftp9.freebsd.org|\ Primary #10: ftp10.freebsd.org|\ Primary #11: ftp11.freebsd.org|\ Primary #12: ftp12.freebsd.org|\ Primary #13: ftp13.freebsd.org|\ Primary #14: ftp14.freebsd.org" ARGENTINA_FTP_SERVERS="\ Argentina: ftp.ar.freebsd.org" AUSTRALIA_FTP_SERVERS="\ Australia: ftp.au.freebsd.org|\ Australia #2: ftp2.au.freebsd.org|\ Australia #3: ftp3.au.freebsd.org" AUSTRIA_FTP_SERVERS="\ Austria: ftp.at.freebsd.org|\ Austria #2: ftp2.at.freebsd.org" BRAZIL_FTP_SERVERS="\ Brazil: ftp.br.freebsd.org|\ Brazil #2: ftp2.br.freebsd.org|\ Brazil #3: ftp3.br.freebsd.org|\ Brazil #4: ftp4.br.freebsd.org|\ Brazil #5: ftp5.br.freebsd.org|\ Brazil #6: ftp6.br.freebsd.org|\ Brazil #7: ftp7.br.freebsd.org" CANADA_FTP_SERVERS="\ Canada: ftp.ca.freebsd.org" CHINA_FTP_SERVERS="\ China: ftp.cn.freebsd.org|\ China #2: ftp2.cn.freebsd.org" CROATIA_FTP_SERVERS="\ Croatia: ftp.hr.freebsd.org" CZECH_REPUBLIC_FTP_SERVERS="\ Czech Republic: ftp.cz.freebsd.org" DENMARK_FTP_SERVERS="\ Denmark: ftp.dk.freebsd.org|\ Denmark #2: ftp2.dk.freebsd.org" ESTONIA_FTP_SERVERS="\ Estonia: ftp.ee.freebsd.org" FINLAND_FTP_SERVERS="\ Finland: ftp.fi.freebsd.org" FRANCE_FTP_SERVERS="\ France: ftp.fr.freebsd.org|\ France #2: ftp2.fr.freebsd.org|\ France #3: ftp3.fr.freebsd.org|\ France #5: ftp5.fr.freebsd.org|\ France #6: ftp6.fr.freebsd.org|\ France #8: ftp8.fr.freebsd.org" GERMANY_FTP_SERVERS="\ Germany: ftp.de.freebsd.org|\ Germany #2: ftp2.de.freebsd.org|\ Germany #3: ftp3.de.freebsd.org|\ Germany #4: ftp4.de.freebsd.org|\ Germany #5: ftp5.de.freebsd.org|\ Germany #6: ftp6.de.freebsd.org|\ Germany #7: ftp7.de.freebsd.org|\ Germany #8: ftp8.de.freebsd.org" GREECE_FTP_SERVERS="\ Greece: ftp.gr.freebsd.org|\ Greece #2: ftp2.gr.freebsd.org" HUNGARY_FTP_SERVERS="\ Hungary: ftp.hu.freebsd.org" ICELAND_FTP_SERVERS="\ Iceland: ftp.is.freebsd.org" IRELAND_FTP_SERVERS="\ Ireland: ftp.ie.freebsd.org|\ Ireland #2: ftp2.ie.freebsd.org|\ Ireland #3: ftp3.ie.freebsd.org" ISRAEL_FTP_SERVERS="\ Israel: ftp.il.freebsd.org" ITALY_FTP_SERVERS="\ Italy: ftp.it.freebsd.org" JAPAN_FTP_SERVERS="\ Japan: ftp.jp.freebsd.org|\ Japan #2: ftp2.jp.freebsd.org|\ Japan #3: ftp3.jp.freebsd.org|\ Japan #4: ftp4.jp.freebsd.org|\ Japan #5: ftp5.jp.freebsd.org|\ Japan #6: ftp6.jp.freebsd.org|\ Japan #7: ftp7.jp.freebsd.org|\ Japan #8: ftp8.jp.freebsd.org|\ Japan #9: ftp9.jp.freebsd.org" KOREA_FTP_SERVERS="\ Korea: ftp.kr.freebsd.org|\ Korea #2: ftp2.kr.freebsd.org" LITHUANIA_FTP_SERVERS="\ Lithuania: ftp.lt.freebsd.org" NETHERLANDS_FTP_SERVERS="\ Netherlands: ftp.nl.freebsd.org|\ Netherlands #2: ftp2.nl.freebsd.org" NORWAY_FTP_SERVERS="\ Norway: ftp.no.freebsd.org|\ Norway #3: ftp3.no.freebsd.org" POLAND_FTP_SERVERS="\ Poland: ftp.pl.freebsd.org|\ Poland #2: ftp2.pl.freebsd.org|\ Poland #5: ftp5.pl.freebsd.org" PORTUGAL_FTP_SERVERS="\ Portugal: ftp.pt.freebsd.org|\ Portugal #2: ftp2.pt.freebsd.org|\ Portugal #4: ftp4.pt.freebsd.org" ROMANIA_FTP_SERVERS="\ Romania: ftp.ro.freebsd.org" RUSSIA_FTP_SERVERS="\ Russia: ftp.ru.freebsd.org|\ Russia #2: ftp2.ru.freebsd.org|\ Russia #3: ftp3.ru.freebsd.org|\ Russia #4: ftp4.ru.freebsd.org" SINGAPORE_FTP_SERVERS="\ Singapore: ftp.sg.freebsd.org" SLOVAK_REPUBLIC_FTP_SERVERS="\ Slovak Republic: ftp.sk.freebsd.org" SLOVENIA_FTP_SERVERS="\ Slovenia: ftp.si.freebsd.org|\ Slovenia #2: ftp2.si.freebsd.org" SOUTH_AFRICA_FTP_SERVERS="\ South Africa: ftp.za.freebsd.org|\ South Africa #2: ftp2.za.freebsd.org|\ South Africa #3: ftp3.za.freebsd.org|\ South Africa #4: ftp4.za.freebsd.org" SPAIN_FTP_SERVERS="\ Spain: ftp.es.freebsd.org|\ Spain #2: ftp2.es.freebsd.org|\ Spain #3: ftp3.es.freebsd.org" SWEDEN_FTP_SERVERS="\ Sweden: ftp.se.freebsd.org|\ Sweden #2: ftp2.se.freebsd.org|\ Sweden #3: ftp3.se.freebsd.org|\ Sweden #4: ftp4.se.freebsd.org|\ Sweden #5: ftp5.se.freebsd.org" SWITZERLAND_FTP_SERVERS="\ Switzerland: ftp.ch.freebsd.org|\ Switzerland #2: ftp2.ch.freebsd.org" TAIWAN_FTP_SERVERS="\ Taiwan: ftp.tw.freebsd.org|\ Taiwan #2: ftp2.tw.freebsd.org|\ Taiwan #3: ftp3.tw.freebsd.org|\ Taiwan #4: ftp4.tw.freebsd.org|\ Taiwan #6: ftp6.tw.freebsd.org|\ Taiwan #11: ftp11.tw.freebsd.org" TURKEY_FTP_SERVERS="\ Turkey: ftp.tr.freebsd.org|\ Turkey #2: ftp2.tr.freebsd.org" UK_FTP_SERVERS="\ UK: ftp.uk.freebsd.org|\ UK #2: ftp2.uk.freebsd.org|\ UK #3: ftp3.uk.freebsd.org|\ UK #4: ftp4.uk.freebsd.org|\ UK #5: ftp5.uk.freebsd.org|\ UK #6: ftp6.uk.freebsd.org" UKRAINE_FTP_SERVERS="\ Ukraine: ftp.ua.freebsd.org|\ Ukraine #2: ftp2.ua.freebsd.org|\ Ukraine #5: ftp5.ua.freebsd.org|\ Ukraine #6: ftp6.ua.freebsd.org|\ Ukraine #7: ftp7.ua.freebsd.org|\ Ukraine #8: ftp8.ua.freebsd.org" USA_FTP_SERVERS="\ USA #1: ftp1.us.freebsd.org|\ USA #2: ftp2.us.freebsd.org|\ USA #3: ftp3.us.freebsd.org|\ USA #4: ftp4.us.freebsd.org|\ USA #5: ftp5.us.freebsd.org|\ USA #6: ftp6.us.freebsd.org|\ USA #7: ftp7.us.freebsd.org|\ USA #8: ftp8.us.freebsd.org|\ USA #9: ftp9.us.freebsd.org|\ USA #10: ftp10.us.freebsd.org|\ USA #11: ftp11.us.freebsd.org|\ USA #12: ftp12.us.freebsd.org|\ USA #13: ftp13.us.freebsd.org|\ USA #14: ftp14.us.freebsd.org|\ USA #15: ftp15.us.freebsd.org" show_mirrors() { MIRRORS="${1}" if [ -n "${MIRRORS}" ] then SAVE_IFS="${IFS}" IFS="|" for m in ${MIRRORS} do echo "$m" done IFS="${SAVE_IFS}" fi }; set_ftp_mirror() { MIRROR="${1}" echo "${MIRROR}" > "${CONFDIR}/mirrors.conf" }; get_ftp_mirror() { MIRROR="${DEFAULT_FTP_SERVER}" if [ -f "${CONFDIR}/mirrors.conf" ] then MIRROR=`cat "${CONFDIR}/mirrors.conf"` fi export VAL="${MIRROR}" }; get_ftpHost() { get_value_from_cfg ftpPath ftpPath="$VAL" ftpHost=`echo "${ftpPath}" | sed -E 's|^(ftp://)([^/]*)(.*)|\2|'` export VAL="${ftpHost}" }; get_ftpDir() { get_value_from_cfg ftpPath ftpPath="$VAL" ftpDir=`echo "${ftpPath}" | sed -E 's|^(ftp://)([^/]*)(.*)|\3|'` export VAL="${ftpDir}" }; get_ftp_mirrors() { COUNTRY="${1}" if [ -n "$COUNTRY" ] then COUNTRY=`echo $COUNTRY|tr A-Z a-z` case "${COUNTRY}" in argentina*) VAL="${ARGENTINA_FTP_SERVERS}" ;; australia*) VAL="${AUSTRALIA_FTP_SERVERS}" ;; austria*) VAL="${AUSTRIA_FTP_SERVERS}" ;; brazil*) VAL="${BRAZIL_FTP_SERVERS}" ;; canada*) VAL="${CANADA_FTP_SERVERS}" ;; china*) VAL="${CHINA_FTP_SERVERS}" ;; croatia*) VAL="${CROATIA_FTP_SERVERS}" ;; czech*) VAL="${CZECH_REPUBLIC_FTP_SERVERS}" ;; denmark*) VAL="${DENMARK_FTP_SERVERS}" ;; estonia*) VAL="${ESTONIA_FTP_SERVERS}" ;; finland*) VAL="${FINLAND_FTP_SERVERS}" ;; france*) VAL="${FRANCE_FTP_SERVERS}" ;; germany*) VAL="${GERMANY_FTP_SERVERS}" ;; greece*) VAL="${GREECE_FTP_SERVERS}" ;; hungary*) VAL="${HUNGARY_FTP_SERVERS}" ;; iceland*) VAL="${ICELAND_FTP_SERVERS}" ;; ireland*) VAL="${IRELAND_FTP_SERVERS}" ;; israel*) VAL="${ISRAEL_FTP_SERVERS}" ;; italy*) VAL="${ITALY_FTP_SERVERS}" ;; japan*) VAL="${JAPAN_FTP_SERVERS}" ;; korea*) VAL="${KOREA_FTP_SERVERS}" ;; lithuania*) VAL="${LITHUANIA_FTP_SERVERS}" ;; netherlands*) VAL="${NETHERLANDS_FTP_SERVERS}" ;; norway*) VAL="${NORWAY_FTP_SERVERS}" ;; poland*) VAL="${POLAND_FTP_SERVERS}" ;; portugal*) VAL="${PORTUGAL_FTP_SERVERS}" ;; romania*) VAL="${ROMAINIA_FTP_SERVERS}" ;; russia*) VAL="${RUSSIA_FTP_SERVERS}" ;; singapore*) VAL="${SINGAPORE_FTP_SERVERS}" ;; slovak*) VAL="${SLOVAK_REPUBLIC_FTP_SERVERS}" ;; slovenia*) VAL="${SLOVENIA_FTP_SERVERS}" ;; *africa*) VAL="${SOUTH_AFRICA_FTP_SERVERS}" ;; spain*) VAL="${SPAIN_FTP_SERVERS}" ;; sweden*) VAL="${SWEDEN_FTP_SERVERS}" ;; switzerland*) VAL="${SWITZERLAND_FTP_SERVERS}" ;; taiwan*) VAL="${TAIWAN_FTP_SERVERS}" ;; turkey*) VAL="${TURKEY_FTP_SERVERS}" ;; ukraine*) VAL="${UKRAINE_FTP_SERVERS}" ;; uk*) VAL="${UK_FTP_SERVERS}" ;; usa*) VAL="${USA_FTP_SERVERS}" ;; esac else VAL="${MAIN_FTP_SERVERS}" VAL="${VAL}|${IPV6_FTP_SERVERS}" VAL="${VAL}|${PRIMARY_FTP_SERVERS}" VAL="${VAL}|${ARGENTINA_FTP_SERVERS}" VAL="${VAL}|${AUSTRALIA_FTP_SERVERS}" VAL="${VAL}|${AUSTRIA_FTP_SERVERS}" VAL="${VAL}|${BRAZIL_FTP_SERVERS}" VAL="${VAL}|${CANADA_FTP_SERVERS}" VAL="${VAL}|${CHINA_FTP_SERVERS}" VAL="${VAL}|${CROATIA_FTP_SERVERS}" VAL="${VAL}|${CZECH_REPUBLIC_FTP_SERVERS}" VAL="${VAL}|${DENMARK_FTP_SERVERS}" VAL="${VAL}|${ESTONIA_FTP_SERVERS}" VAL="${VAL}|${FINLAND_FTP_SERVERS}" VAL="${VAL}|${FRANCE_FTP_SERVERS}" VAL="${VAL}|${GERMANY_FTP_SERVERS}" VAL="${VAL}|${GREECE_FTP_SERVERS}" VAL="${VAL}|${HUNGARY_FTP_SERVERS}" VAL="${VAL}|${ICELAND_FTP_SERVERS}" VAL="${VAL}|${IRELAND_FTP_SERVERS}" VAL="${VAL}|${ISRAEL_FTP_SERVERS}" VAL="${VAL}|${ITALY_FTP_SERVERS}" VAL="${VAL}|${JAPAN_FTP_SERVERS}" VAL="${VAL}|${KOREA_FTP_SERVERS}" VAL="${VAL}|${LITHUANIA_FTP_SERVERS}" VAL="${VAL}|${NETHERLANDS_FTP_SERVERS}" VAL="${VAL}|${NORWAY_FTP_SERVERS}" VAL="${VAL}|${POLAND_FTP_SERVERS}" VAL="${VAL}|${PORTUGAL_FTP_SERVERS}" VAL="${VAL}|${ROMANIA_FTP_SERVERS}" VAL="${VAL}|${RUSSIA_FTP_SERVERS}" VAL="${VAL}|${SINGAPORE_FTP_SERVERS}" VAL="${VAL}|${SLOVAK_REPUBLIC_FTP_SERVERS}" VAL="${VAL}|${SLOVENIA_FTP_SERVERS}" VAL="${VAL}|${SOUTH_AFRICA_FTP_SERVERS}" VAL="${VAL}|${SPAIN_FTP_SERVERS}" VAL="${VAL}|${SWEDEN_FTP_SERVERS}" VAL="${VAL}|${SWITZERLAND_FTP_SERVERS}" VAL="${VAL}|${TAIWAN_FTP_SERVERS}" VAL="${VAL}|${TURKEY_FTP_SERVERS}" VAL="${VAL}|${UKRAINE_FTP_SERVERS}" VAL="${VAL}|${UK_FTP_SERVERS}" VAL="${VAL}|${USA_FTP_SERVERS}" fi export VAL }; Index: head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh (revision 326275) @@ -1,177 +1,179 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which check and load any optional modules specified in the config . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh copy_component() { COMPONENT="$1" FAILED="0" CFILES="" # Check the type, and set the components subdir properly TYPE="`grep 'type:' ${COMPDIR}/${COMPONENT}/component.cfg | cut -d ' ' -f 2`" if [ "${TYPE}" = "PBI" ] then SUBDIR="PBI" else SUBDIR="components" fi # Lets start by downloading / copying the files this component needs while read line do CFILE="`echo $line | cut -d ':' -f 1`" CFILEMD5="`echo $line | cut -d ':' -f 2`" CFILE2MD5="`echo $line | cut -d ':' -f 3`" case ${INSTALLMEDIUM} in dvd|usb) # On both dvd / usb, we can just copy the file cp ${CDMNT}/${COMPFILEDIR}/${SUBDIR}/${CFILE} \ ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} RESULT="$?" ;; ftp) get_value_from_cfg ftpPath if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" fi FTPPATH="${VAL}" fetch_file "${FTPPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE}" "${FSMNT}/${COMPTMPDIR}/${CFILE}" "0" RESULT="$?" ;; local) get_value_from_cfg localPath if [ -z "$VAL" ]; then exit_err "Install medium was set to local, but no localPath was provided!" fi LOCALPATH=$VAL cp ${LOCALPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE} \ ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} RESULT="$?" ;; esac if [ "${RESULT}" != "0" ] then echo_log "WARNING: Failed to copy ${CFILE}" FAILED="1" else # Now lets check the MD5 to confirm the file is valid CHECKMD5=`md5 -q ${FSMNT}/${COMPTMPDIR}/${CFILE}` if [ "${CHECKMD5}" != "${CFILEMD5}" -a "${CHECKMD5}" != "${CFILE2MD5}" ] then echo_log "WARNING: ${CFILE} failed md5 checksum" FAILED="1" else if [ -z "${CFILES}" ] then CFILES="${CFILE}" else CFILES="${CFILES},${CFILE}" fi fi fi done < ${COMPDIR}/${COMPONENT}/distfiles if [ "${FAILED}" = "0" ] then # Now install the component run_component_install ${COMPONENT} ${CFILES} fi }; run_component_install() { COMPONENT="$1" CFILES="$1" # Lets install this component now # Start by making a wrapper script which sets the variables # for the component to use echo "#!/bin/sh COMPTMPDIR=\"${COMPTMPDIR}\" export COMPTMPDIR CFILE=\"${CFILE}\" export CFILE mount -t devfs devfs /dev sh ${COMPTMPDIR}/install.sh umount /dev " >${FSMNT}/.componentwrapper.sh chmod 755 ${FSMNT}/.componentwrapper.sh # Copy over the install script for this component cp ${COMPDIR}/${COMPONENT}/install.sh ${FSMNT}/${COMPTMPDIR}/ echo_log "INSTALL COMPONENT: ${i}" chroot ${FSMNT} /.componentwrapper.sh >>${LOGOUT} 2>>${LOGOUT} rm ${FSMNT}/.componentwrapper.sh }; # Check for any modules specified, and begin loading them install_components() { # First, lets check and see if we even have any optional modules get_value_from_cfg installComponents if [ -n "${VAL}" ] then # Lets start by cleaning up the string and getting it ready to parse strip_white_space ${VAL} COMPONENTS=`echo ${VAL} | sed -e "s|,| |g"` for i in $COMPONENTS do if [ ! -e "${COMPDIR}/${i}/install.sh" -o ! -e "${COMPDIR}/${i}/distfiles" ] then echo_log "WARNING: Component ${i} doesn't seem to exist" else # Make the tmpdir on the disk mkdir -p ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} # Start by grabbing the component files copy_component ${i} # Remove the tmpdir now rm -rf ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} fi done fi }; Index: head/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh (revision 326275) @@ -1,188 +1,190 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which check and load any optional packages specified in the config . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh # Recursively determine all dependencies for this package determine_package_dependencies() { local PKGNAME="${1}" local DEPFILE="${2}" grep -q "${PKGNAME}" "${DEPFILE}" if [ $? -ne 0 ] then echo "${PKGNAME}" >> "${DEPFILE}" get_package_dependencies "${PKGNAME}" "1" local DEPS="${VAL}" for d in ${DEPS} do determine_package_dependencies "${d}" "${DEPFILE}" done fi }; # Fetch packages dependencies from a file fetch_package_dependencies() { local DEPFILE local DEPS local SAVEDIR DEPFILE="${1}" DEPS=`cat "${DEPFILE}"` SAVEDIR="${2}" for d in ${DEPS} do get_package_short_name "${d}" SNAME="${VAL}" get_package_category "${SNAME}" CATEGORY="${VAL}" fetch_package "${CATEGORY}" "${d}" "${SAVEDIR}" done }; # Check for any packages specified, and begin loading them install_packages() { echo "Checking for packages to install..." sleep 2 # First, lets check and see if we even have any packages to install get_value_from_cfg installPackages # Nothing to do? if [ -z "${VAL}" ]; then return; fi echo "Installing packages..." sleep 3 local PKGPTH HERE=`pwd` rc_halt "mkdir -p ${FSMNT}${PKGTMPDIR}" # Determine the directory we will install packages from get_package_location rc_halt "cd ${PKGDLDIR}" # Set the location of the INDEXFILE INDEXFILE="${TMPDIR}/INDEX" if [ ! -f "${INDEXFILE}" ]; then get_package_index fi if [ ! -f "${TMPDIR}/INDEX.parsed" -a "$INSTALLMEDIUM" = "ftp" ]; then parse_package_index fi # What extension are we using for pkgs? PKGEXT="txz" get_value_from_cfg pkgExt if [ -n "${VAL}" ]; then strip_white_space ${VAL} PKGEXT="$VAL" fi export PKGEXT # We dont want to be bothered with scripts asking questions PACKAGE_BUILDING=yes export PACKAGE_BUILDING # Lets start by cleaning up the string and getting it ready to parse get_value_from_cfg_with_spaces installPackages PACKAGES="${VAL}" echo_log "Packages to install: `echo $PACKAGES | wc -w | awk '{print $1}'`" for i in $PACKAGES do if ! get_package_name "${i}" then echo_log "Unable to locate package ${i}" continue fi PKGNAME="${VAL}" # Fetch package + deps, but skip if installing from local media if [ "${INSTALLMEDIUM}" = "ftp" ] ; then DEPFILE="${FSMNT}/${PKGTMPDIR}/.${PKGNAME}.deps" rc_nohalt "touch ${DEPFILE}" determine_package_dependencies "${PKGNAME}" "${DEPFILE}" fetch_package_dependencies "${DEPFILE}" "${FSMNT}/${PKGTMPDIR}" fi # Set package location case "${INSTALLMEDIUM}" in usb|dvd|local) PKGPTH="${PKGTMPDIR}/All/${PKGNAME}" ;; *) PKGPTH="${PKGTMPDIR}/${PKGNAME}" ;; esac # See if we need to determine the package format we are working with if [ -z "${PKGINFO}" ] ; then tar tqf "${FSMNT}${PKGPTH}" '+MANIFEST' >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then PKGADD="pkg_add -C ${FSMNT}" PKGINFO="pkg_info" else PKGADD="pkg -c ${FSMNT} add" PKGINFO="pkg info" bootstrap_pkgng fi fi # If the package is not already installed, install it! if ! run_chroot_cmd "${PKGINFO} -e ${PKGNAME}" >/dev/null 2>/dev/null then echo_log "Installing package: ${PKGNAME}" rc_nohalt "${PKGADD} ${PKGPTH}" fi if [ "${INSTALLMEDIUM}" = "ftp" ] ; then rc_nohalt "rm ${DEPFILE}" fi done echo_log "Package installation complete!" # Cleanup after ourselves rc_halt "cd ${HERE}" if [ "${INSTALLMEDIUM}" = "ftp" ] ; then rc_halt "rm -rf ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null else rc_halt "umount ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null rc_halt "rmdir ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null fi }; Index: head/usr.sbin/pc-sysinstall/backend/functions-localize.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-localize.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-localize.sh (revision 326275) @@ -1,541 +1,543 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh # Function which localizes a FreeBSD install localize_freebsd() { sed -i.bak "s/lang=en_US/lang=${LOCALE}/g" ${FSMNT}/etc/login.conf rm ${FSMNT}/etc/login.conf.bak }; localize_x_desktops() { # Check for and customize KDE lang ########################################################################## # Check if we can localize KDE via skel if [ -e "${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals" ] ; then sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals fi # Check if we have a KDE root config if [ -e "${FSMNT}/root/.kde4/share/config/kdeglobals" ] ; then sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals fi # Check for KDM if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc" ] ; then sed -i '' "s/Language=en_US/Language=${LOCALE}.UTF-8/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc fi # Check for and customize GNOME / GDM lang ########################################################################## # See if GDM is enabled and customize its lang cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q "gdm_enable=\"YES\"" 2>/dev/null if [ "$?" = "0" ] ; then echo "gdm_lang=\"${LOCALE}.UTF-8\"" >> ${FSMNT}/etc/rc.conf fi }; # Function which localizes a PC-BSD install localize_pcbsd() { # Check if we have a localized splash screen and copy it if [ -e "${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx" ] then cp ${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx ${FSMNT}/boot/loading-screen.pcx fi }; localize_x_keyboard() { KEYMOD="$1" KEYLAY="$2" KEYVAR="$3" COUNTRY="$4" OPTION="grp:alt_shift_toggle" SETXKBMAP="" if [ "${COUNTRY}" = "NONE" -o "${COUNTRY}" = "us" -o "${COUNTRY}" = "C" ] ; then #In this case we don't need any additional language COUNTRY="" OPTION="" else COUNTRY=",${COUNTRY}" fi if [ "${KEYMOD}" != "NONE" ] then SETXKBMAP="-model ${KEYMOD}" KXMODEL="${KEYMOD}" else KXMODEL="pc104" fi if [ "${KEYLAY}" != "NONE" ] then localize_key_layout "$KEYLAY" SETXKBMAP="${SETXKBMAP} -layout ${KEYLAY}" KXLAYOUT="${KEYLAY}" else KXLAYOUT="us" fi if [ "${KEYVAR}" != "NONE" ] then SETXKBMAP="${SETXKBMAP} -variant ${KEYVAR}" KXVAR="(${KEYVAR})" else KXVAR="" fi # Setup .xprofile with our setxkbmap call now if [ ! -z "${SETXKBMAP}" ] then if [ ! -e "${FSMNT}/usr/share/skel/.xprofile" ] then echo "#!/bin/sh" >${FSMNT}/usr/share/skel/.xprofile fi # Save the keyboard layout for user / root X logins echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/share/skel/.xprofile chmod 755 ${FSMNT}/usr/share/skel/.xprofile cp ${FSMNT}/usr/share/skel/.xprofile ${FSMNT}/root/.xprofile # Save it for KDM if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup" ] ; then echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup fi fi # Create the kxkbrc configuration using these options if [ -d "${FSMNT}/usr/share/skel/.kde4/share/config" ] ; then echo "[Layout] DisplayNames=${KXLAYOUT}${COUNTRY} IndicatorOnly=false LayoutList=${KXLAYOUT}${KXVAR}${COUNTRY} Model=${KXMODEL} Options=${OPTION} ResetOldOptions=true ShowFlag=true ShowSingle=false SwitchMode=WinClass Use=true " >${FSMNT}/usr/share/skel/.kde4/share/config/kxkbrc fi }; localize_key_layout() { KEYLAYOUT="$1" # Set the keylayout in rc.conf case ${KEYLAYOUT} in am) KEYLAYOUT_CONSOLE="hy.armscii-8" ;; ca) KEYLAYOUT_CONSOLE="fr_CA.acc.iso" ;; ch) KEYLAYOUT_CONSOLE="swissgerman.iso" ;; cz) KEYLAYOUT_CONSOLE="cz.iso2" ;; de) KEYLAYOUT_CONSOLE="german.iso" ;; dk) KEYLAYOUT_CONSOLE="danish.iso" ;; ee) KEYLAYOUT_CONSOLE="estonian.iso" ;; es) KEYLAYOUT_CONSOLE="spanish.iso" ;; fi) KEYLAYOUT_CONSOLE="finnish.iso" ;; is) KEYLAYOUT_CONSOLE="icelandic.iso" ;; jp) KEYLAYOUT_CONSOLE="jp.106" ;; nl) KEYLAYOUT_CONSOLE="dutch.iso.acc" ;; no) KEYLAYOUT_CONSOLE="norwegian.iso" ;; pl) KEYLAYOUT_CONSOLE="pl_PL.ISO8859-2" ;; ru) KEYLAYOUT_CONSOLE="ru.koi8-r" ;; sk) KEYLAYOUT_CONSOLE="sk.iso2" ;; se) KEYLAYOUT_CONSOLE="swedish.iso" ;; tr) KEYLAYOUT_CONSOLE="tr.iso9.q" ;; gb) KEYLAYOUT_CONSOLE="uk.iso" ;; *) if [ ! -z "${KEYLAYOUT}" ] then KEYLAYOUT_CONSOLE="${KEYLAYOUT}.iso" fi ;; esac if [ -n "${KEYLAYOUT_CONSOLE}" ] then echo "keymap=\"${KEYLAYOUT_CONSOLE}\"" >>${FSMNT}/etc/rc.conf fi }; # Function which prunes other l10n files from the KDE install localize_prune_langs() { get_value_from_cfg localizeLang KEEPLANG="$VAL" if [ -z "$KEEPLANG" ] ; then KEEPLANG="en" fi export KEEPLANG echo_log "Pruning other l10n files, keeping ${KEEPLANG}" # Create the script to do uninstalls echo '#!/bin/sh for i in `pkg_info -xEI kde-l10n` do echo "$i" | grep "${KEEPLANG}-kde" if [ $? -ne 0 ] ; then pkg_delete ${i} fi done ' > ${FSMNT}/.pruneLangs.sh chmod 755 ${FSMNT}/.pruneLangs.sh chroot ${FSMNT} /.pruneLangs.sh >/dev/null 2>/dev/null rm ${FSMNT}/.pruneLangs.sh }; # Function which sets COUNTRY SETLANG and LOCALE based upon $1 localize_get_codes() { TARGETLANG="${1}" # Setup the presets for the specific lang case $TARGETLANG in af) COUNTRY="C" SETLANG="af" LOCALE="af_ZA" ;; ar) COUNTRY="C" SETLANG="ar" LOCALE="en_US" ;; az) COUNTRY="C" SETLANG="az" LOCALE="en_US" ;; ca) COUNTRY="es" SETLANG="es:ca" LOCALE="ca_ES" ;; be) COUNTRY="be" SETLANG="be" LOCALE="be_BY" ;; bn) COUNTRY="bn" SETLANG="bn" LOCALE="en_US" ;; bg) COUNTRY="bg" SETLANG="bg" LOCALE="bg_BG" ;; cs) COUNTRY="cz" SETLANG="cs" LOCALE="cs_CZ" ;; da) COUNTRY="dk" SETLANG="da" LOCALE="da_DK" ;; de) COUNTRY="de" SETLANG="de" LOCALE="de_DE" ;; en_GB) COUNTRY="gb" SETLANG="en_GB:cy" LOCALE="en_GB" ;; el) COUNTRY="gr" SETLANG="el:gr" LOCALE="el_GR" ;; es) COUNTRY="es" SETLANG="es" LOCALE="es_ES" ;; es_LA) COUNTRY="us" SETLANG="es:en_US" LOCALE="es_ES" ;; et) COUNTRY="ee" SETLANG="et" LOCALE="et_EE" ;; fr) COUNTRY="fr" SETLANG="fr" LOCALE="fr_FR" ;; he) COUNTRY="il" SETLANG="he:ar" LOCALE="he_IL" ;; hr) COUNTRY="hr" SETLANG="hr" LOCALE="hr_HR" ;; hu) COUNTRY="hu" SETLANG="hu" LOCALE="hu_HU" ;; it) COUNTRY="it" SETLANG="it" LOCALE="it_IT" ;; ja) COUNTRY="jp" SETLANG="ja" LOCALE="ja_JP" ;; ko) COUNTRY="kr" SETLANG="ko" LOCALE="ko_KR" ;; nl) COUNTRY="nl" SETLANG="nl" LOCALE="nl_NL" ;; nn) COUNTRY="no" SETLANG="nn" LOCALE="en_US" ;; pa) COUNTRY="pa" SETLANG="pa" LOCALE="en_US" ;; pl) COUNTRY="pl" SETLANG="pl" LOCALE="pl_PL" ;; pt) COUNTRY="pt" SETLANG="pt" LOCALE="pt_PT" ;; pt_BR) COUNTRY="br" SETLANG="pt_BR" LOCALE="pt_BR" ;; ru) COUNTRY="ru" SETLANG="ru" LOCALE="ru_RU" ;; sl) COUNTRY="si" SETLANG="sl" LOCALE="sl_SI" ;; sk) COUNTRY="sk" SETLANG="sk" LOCALE="sk_SK" ;; sv) COUNTRY="se" SETLANG="sv" LOCALE="sv_SE" ;; uk) COUNTRY="ua" SETLANG="uk" LOCALE="uk_UA" ;; vi) COUNTRY="vn" SETLANG="vi" LOCALE="en_US" ;; zh_CN) COUNTRY="cn" SETLANG="zh_CN" LOCALE="zh_CN" ;; zh_TW) COUNTRY="tw" SETLANG="zh_TW" LOCALE="zh_TW" ;; *) COUNTRY="C" SETLANG="${TARGETLANG}" LOCALE="en_US" ;; esac export COUNTRY SETLANG LOCALE }; # Function which sets the timezone on the system set_timezone() { TZONE="$1" cp ${FSMNT}/usr/share/zoneinfo/${TZONE} ${FSMNT}/etc/localtime }; # Function which enables / disables NTP set_ntp() { ENABLED="$1" if [ "$ENABLED" = "yes" -o "${ENABLED}" = "YES" ] then cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'ntpd_enable="YES"' >>${FSMNT}/etc/rc.conf echo 'ntpd_sync_on_start="YES"' >>${FSMNT}/etc/rc.conf fi else cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null if [ $? -ne 0 ] then sed -i.bak 's|ntpd_enable="YES"||g' ${FSMNT}/etc/rc.conf fi fi }; # Starts checking for localization directives run_localize() { KEYLAYOUT="NONE" KEYMOD="NONE" KEYVAR="NONE" while read line do # Check if we need to do any localization echo $line | grep -q "^localizeLang=" 2>/dev/null if [ $? -eq 0 ] then # Set our country / lang / locale variables get_value_from_string "$line" localize_get_codes ${VAL} get_value_from_string "$line" # If we are doing PC-BSD install, localize it as well as FreeBSD base if [ "${INSTALLTYPE}" != "FreeBSD" ] then localize_pcbsd "$VAL" fi # Localize FreeBSD localize_freebsd "$VAL" # Localize any X pkgs localize_x_desktops "$VAL" fi # Check if we need to do any keylayouts echo $line | grep -q "^localizeKeyLayout=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYLAYOUT="$VAL" fi # Check if we need to do any key models echo $line | grep -q "^localizeKeyModel=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYMOD="$VAL" fi # Check if we need to do any key variant echo $line | grep -q "^localizeKeyVariant=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYVAR="$VAL" fi # Check if we need to set a timezone echo $line | grep -q "^timeZone=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" set_timezone "$VAL" fi # Check if we need to set a timezone echo $line | grep -q "^enableNTP=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" set_ntp "$VAL" fi done <${CFGF} if [ "${INSTALLTYPE}" != "FreeBSD" ] ; then # Do our X keyboard localization localize_x_keyboard "${KEYMOD}" "${KEYLAYOUT}" "${KEYVAR}" "${COUNTRY}" fi # Check if we want to prunt any other KDE lang files to save some disk space get_value_from_cfg localizePrune if [ "${VAL}" = "yes" -o "${VAL}" = "YES" ] ; then localize_prune_langs fi # Update the login.conf db, even if we didn't localize, its a good idea to make sure its up2date run_chroot_cmd "/usr/bin/cap_mkdb /etc/login.conf" >/dev/null 2>/dev/null }; Index: head/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh (revision 326275) @@ -1,240 +1,242 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions related mounting the newly formatted disk partitions # Mounts all the specified partition to the mount-point mount_partition() { if [ -z "${1}" -o -z "${2}" -o -z "${3}" ] then exit_err "ERROR: Missing arguments for mount_partition" fi PART="${1}" PARTFS="${2}" MNTPOINT="${3}" MNTFLAGS="${4}" # Setup the MNTOPTS if [ -z "${MNTOPTS}" ] then MNTFLAGS="-o rw" else MNTFLAGS="-o rw,${MNTFLAGS}" fi #We are on ZFS, lets setup this mount-point if [ "${PARTFS}" = "ZFS" ] then ZPOOLNAME=$(get_zpool_name "${PART}") # Check if we have multiple zfs mounts specified for ZMNT in `echo ${MNTPOINT} | sed 's|,| |g'` do # Check for any ZFS specific mount options ZMNTOPTS="`echo $ZMNT | cut -d '(' -f 2 | cut -d ')' -f 1`" if [ "$ZMNTOPTS" = "$ZMNT" ] ; then ZMNTOPTS="" ; fi # Reset ZMNT with options removed ZMNT="`echo $ZMNT | cut -d '(' -f 1`" # First make sure we create the mount point if [ ! -d "${FSMNT}${ZMNT}" ] ; then mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT} fi # Check for any volsize args zcopt="" for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'` do echo "$ZOPT" | grep -q volsize if [ $? -eq 0 ] ; then volsize=`echo $ZOPT | cut -d '=' -f 2` zcopt="-V $volsize" fi done if [ "${ZMNT}" = "/" ] ; then # If creating ZFS / dataset, give it name that beadm works with ZNAME="/ROOT/default" ZMKMNT="" echo_log "zfs create $zcopt -p ${ZPOOLNAME}/ROOT" rc_halt "zfs create $zcopt -p ${ZPOOLNAME}/ROOT" echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" else ZNAME="${ZMNT}" ZMKMNT="${ZMNT}" echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" fi sleep 2 if [ -z "$zcopt" ] ; then rc_halt "zfs set mountpoint=${FSMNT}${ZMKMNT} ${ZPOOLNAME}${ZNAME}" fi # Do we need to make this / zfs dataset bootable? if [ "$ZMNT" = "/" ] ; then echo_log "Stamping ${ZPOOLNAME}/ROOT/default as bootfs" rc_halt "zpool set bootfs=${ZPOOLNAME}/ROOT/default ${ZPOOLNAME}" fi # Do we need to make this /boot zfs dataset bootable? if [ "$ZMNT" = "/boot" ] ; then echo_log "Stamping ${ZPOOLNAME}${ZMNT} as bootfs" rc_halt "zpool set bootfs=${ZPOOLNAME}${ZMNT} ${ZPOOLNAME}" fi # If no ZFS options, we can skip if [ -z "$ZMNTOPTS" ] ; then continue ; fi # Parse any ZFS options now for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'` do echo "$ZOPT" | grep -q volsize if [ $? -eq 0 ] ; then continue ; fi rc_halt "zfs set $ZOPT ${ZPOOLNAME}${ZNAME}" done done # End of adding ZFS mounts else # If we are not on ZFS, lets do the mount now # First make sure we create the mount point if [ ! -d "${FSMNT}${MNTPOINT}" ] then mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT} fi echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}" sleep 2 rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}" fi }; # Mounts all the new file systems to prepare for installation mount_all_filesystems() { # Make sure our mount point exists mkdir -p ${FSMNT} >/dev/null 2>/dev/null # First lets find and mount the / partition ######################################################### for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" if [ ! -e "${PARTDEV}" -a "${PARTFS}" != "ZFS" ] then exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" fi PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" if [ "${PARTENC}" = "ON" ] then EXT=".eli" else EXT="" fi # Check for root partition for mounting, including ZFS "/,/usr" type echo "$PARTMNT" | grep "/," >/dev/null if [ "$?" = "0" -o "$PARTMNT" = "/" ] then case ${PARTFS} in UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; IMAGE) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac fi done # Now that we've mounted "/" lets do any other remaining mount-points ################################################################## for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" if [ ! -e "${PARTDEV}" -a "${PARTFS}" != "ZFS" ] then exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" fi PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" if [ "${PARTENC}" = "ON" ] then EXT=".eli" else EXT="" fi # Check if we've found "/" again, don't need to mount it twice echo "$PARTMNT" | grep "/," >/dev/null if [ "$?" != "0" -a "$PARTMNT" != "/" ] then case ${PARTFS} in UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; SWAP) # Lets enable this swap now if [ "$PARTENC" = "ON" ] then echo_log "Enabling encrypted swap on ${PARTDEV}" rc_halt "geli onetime -d -e 3des ${PARTDEV}" sleep 5 rc_halt "swapon ${PARTDEV}.eli" else echo_log "swapon ${PARTDEV}" sleep 5 rc_halt "swapon ${PARTDEV}" fi ;; IMAGE) if [ ! -d "${PARTMNT}" ] then mkdir -p "${PARTMNT}" fi mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac fi done }; Index: head/usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh (revision 326275) @@ -1,152 +1,154 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which perform mounting / unmounting and switching of # optical / usb media . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh # Displays an optical failure message opt_fail() { # If we got here, we must not have a DVD/USB we can find :( get_value_from_cfg installInteractive if [ "${VAL}" = "yes" ] then # We are running interactive, and didn't find a DVD, prompt user again echo_log "DISK ERROR: Unable to find installation disk!" echo_log "Please insert the installation disk and press enter." read tmp else exit_err "ERROR: Unable to locate installation DVD/USB" fi }; # Performs the extraction of data to disk opt_mount() { FOUND="0" # Ensure we have a directory where its supposed to be if [ ! -d "${CDMNT}" ] then mkdir -p ${CDMNT} fi # Start by checking if we already have a cd mounted at CDMNT mount | grep -q "${CDMNT} " 2>/dev/null if [ $? -eq 0 ] then if [ -e "${CDMNT}/${INSFILE}" ] then echo "MOUNTED" >${TMPDIR}/cdmnt echo_log "FOUND DVD: MOUNTED" FOUND="1" return fi # failed to find optical disk opt_fail return fi # Setup our loop to search for installation media while z=1 do # Loop though and look for an installation disk for i in `ls -1 /dev/cd* 2>/dev/null` do # Find the CD Device /sbin/mount_cd9660 $i ${CDMNT} # Check the package type to see if we have our install data if [ -e "${CDMNT}/${INSFILE}" ] then echo "${i}" >${TMPDIR}/cdmnt echo_log "FOUND DVD: ${i}" FOUND="1" break fi /sbin/umount ${CDMNT} >/dev/null 2>/dev/null done # If no DVD found, try USB if [ "$FOUND" != "1" ] then # Loop though and look for an installation disk for i in `ls -1 /dev/da* 2>/dev/null` do # Check if we can mount this device UFS /sbin/mount -r $i ${CDMNT} # Check the package type to see if we have our install data if [ -e "${CDMNT}/${INSFILE}" ] then echo "${i}" >${TMPDIR}/cdmnt echo_log "FOUND USB: ${i}" FOUND="1" break fi /sbin/umount ${CDMNT} >/dev/null 2>/dev/null # Also check if it is a FAT mount /sbin/mount -r -t msdosfs $i ${CDMNT} # Check the package type to see if we have our install data if [ -e "${CDMNT}/${INSFILE}" ] then echo "${i}" >${TMPDIR}/cdmnt echo_log "FOUND USB: ${i}" FOUND="1" break fi /sbin/umount ${CDMNT} >/dev/null 2>/dev/null done fi # End of USB Check if [ "$FOUND" = "1" ] then break fi # Failed to find a disk, take action now opt_fail done }; # Function to unmount optical media opt_umount() { /sbin/umount ${CDMNT} >/dev/null 2>/dev/null }; Index: head/usr.sbin/pc-sysinstall/backend/functions-networking.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-networking.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-networking.sh (revision 326275) @@ -1,500 +1,502 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # Copyright (c) 2011 The FreeBSD Foundation # All rights reserved. # # Portions of this software were developed by Bjoern Zeeb # under sponsorship from the FreeBSD Foundation. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which perform our networking setup # Function which creates a kde4 .desktop file for the PC-BSD net tray create_desktop_nettray() { NIC="${1}" echo "#!/usr/bin/env xdg-open [Desktop Entry] Exec=/usr/local/kde4/bin/pc-nettray ${NIC} Icon=network StartupNotify=false Type=Application" > ${FSMNT}/usr/share/skel/.kde4/Autostart/tray-${NIC}.desktop chmod 744 ${FSMNT}/usr/share/skel/.kde4/Autostart/tray-${NIC}.desktop }; # Function which checks is a nic is wifi or not check_is_wifi() { NIC="$1" ifconfig ${NIC} | grep -q "802.11" 2>/dev/null if [ $? -eq 0 ] then return 0 else return 1 fi }; # Function to get the first available wired nic, used for setup get_first_wired_nic() { rm ${TMPDIR}/.niclist >/dev/null 2>/dev/null # start by getting a list of nics on this system ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist if [ -e "${TMPDIR}/.niclist" ] then while read line do NIC="`echo $line | cut -d ':' -f 1`" check_is_wifi ${NIC} if [ $? -ne 0 ] then export VAL="${NIC}" return fi done < ${TMPDIR}/.niclist fi export VAL="" return }; # Function which simply enables plain dhcp on all detected nics enable_dhcp_all() { rm ${TMPDIR}/.niclist >/dev/null 2>/dev/null # start by getting a list of nics on this system ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist if [ -e "${TMPDIR}/.niclist" ] then echo "# Auto-Enabled NICs from pc-sysinstall" >>${FSMNT}/etc/rc.conf WLANCOUNT="0" while read line do NIC="`echo $line | cut -d ':' -f 1`" DESC="`echo $line | cut -d ':' -f 2`" echo_log "Setting $NIC to DHCP on the system." check_is_wifi ${NIC} if [ $? -eq 0 ] then # We have a wifi device, setup a wlan* entry for it WLAN="wlan${WLANCOUNT}" cat ${FSMNT}/etc/rc.conf | grep -q "wlans_${NIC}=" if [ $? -ne 0 ] ; then echo "wlans_${NIC}=\"${WLAN}\"" >>${FSMNT}/etc/rc.conf fi echo "ifconfig_${WLAN}=\"DHCP\"" >>${FSMNT}/etc/rc.conf CNIC="${WLAN}" WLANCOUNT=$((WLANCOUNT+1)) else echo "ifconfig_${NIC}=\"DHCP\"" >>${FSMNT}/etc/rc.conf CNIC="${NIC}" fi done < ${TMPDIR}/.niclist fi }; # Function which detects available nics, and enables dhcp on them save_auto_dhcp() { enable_dhcp_all }; # Function which simply enables iPv6 SLAAC on all detected nics enable_slaac_all() { rm ${TMPDIR}/.niclist >/dev/null 2>/dev/null # start by getting a list of nics on this system ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist if [ -e "${TMPDIR}/.niclist" ] then echo "# Auto-Enabled NICs from pc-sysinstall" >>${FSMNT}/etc/rc.conf WLANCOUNT="0" while read line do NIC="`echo $line | cut -d ':' -f 1`" DESC="`echo $line | cut -d ':' -f 2`" echo_log "Setting $NIC to accepting RAs on the system." check_is_wifi ${NIC} if [ $? -eq 0 ] then # We have a wifi device, setup a wlan* entry for it # Given we cannot have DHCP and SLAAC the same time currently # it's save to just duplicate. WLAN="wlan${WLANCOUNT}" cat ${FSMNT}/etc/rc.conf | grep -q "wlans_${NIC}=" if [ $? -ne 0 ] ; then echo "wlans_${NIC}=\"${WLAN}\"" >>${FSMNT}/etc/rc.conf fi #echo "ifconfig_${NIC}=\"up\"" >>${FSMNT}/etc/rc.conf echo "ifconfig_${WLAN}_ipv6=\"inet6 accept_rtadv\"" >>${FSMNT}/etc/rc.conf CNIC="${WLAN}" WLANCOUNT=$((WLANCOUNT+1)) else #echo "ifconfig_${NIC}=\"up\"" >>${FSMNT}/etc/rc.conf echo "ifconfig_${NIC}_ipv6=\"inet6 accept_rtadv\"" >>${FSMNT}/etc/rc.conf CNIC="${NIC}" fi done < ${TMPDIR}/.niclist fi # Given we cannot yet rely on RAs to provide DNS information as much # as we can in the DHCP world, we should append a given nameserver. : > ${FSMNT}/etc/resolv.conf get_value_from_cfg netSaveIPv6NameServer NAMESERVER="${VAL}" if [ -n "${NAMESERVER}" ] then echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf fi }; # Function which detects available nics, and enables IPv6 SLAAC on them save_auto_slaac() { enable_slaac_all }; # Function which saves a manual nic setup to the installed system save_manual_nic() { # Get the target nic NIC="$1" get_value_from_cfg netSaveIP_${NIC} NETIP="${VAL}" if [ "$NETIP" = "DHCP" ] then echo_log "Setting $NIC to DHCP on the system." echo "ifconfig_${NIC}=\"DHCP\"" >>${FSMNT}/etc/rc.conf return 0 fi # If we get here, we have a manual setup, lets do so now IFARGS="" IF6ARGS="" # Set the manual IP if [ -n "${NETIP}" ] then IFARGS="inet ${NETIP}" # Check if we have a netmask to set get_value_from_cfg netSaveMask_${NIC} NETMASK="${VAL}" if [ -n "${NETMASK}" ] then IFARGS="${IFARGS} netmask ${NETMASK}" fi fi get_value_from_cfg netSaveIPv6_${NIC} NETIP6="${VAL}" if [ -n "${NETIP6}" ] then # Make sure we have one inet6 prefix. IF6ARGS=`echo "${NETIP6}" | awk '{ if ("^inet6 ") { print $0; } else { printf "inet6 %s", $0; } }'` fi echo "# Auto-Enabled NICs from pc-sysinstall" >>${FSMNT}/etc/rc.conf if [ -n "${IFARGS}" ] then echo "ifconfig_${NIC}=\"${IFARGS}\"" >>${FSMNT}/etc/rc.conf fi if [ -n "${IF6ARGS}" ] then echo "ifconfig_${NIC}_ipv6=\"${IF6ARGS}\"" >>${FSMNT}/etc/rc.conf fi }; # Function which saves a manual gateway router setup to the installed system save_manual_router() { # Check if we have a default router to set get_value_from_cfg netSaveDefaultRouter NETROUTE="${VAL}" if [ -n "${NETROUTE}" ] then echo "defaultrouter=\"${NETROUTE}\"" >>${FSMNT}/etc/rc.conf fi get_value_from_cfg netSaveIPv6DefaultRouter NETROUTE="${VAL}" if [ -n "${NETROUTE}" ] then echo "ipv6_defaultrouter=\"${NETROUTE}\"" >>${FSMNT}/etc/rc.conf fi }; save_manual_nameserver() { # Check if we have a nameserver to enable : > ${FSMNT}/etc/resolv.conf get_value_from_cfg_with_spaces netSaveNameServer NAMESERVERLIST="${VAL}" if [ ! -z "${NAMESERVERLIST}" ] then for NAMESERVER in ${NAMESERVERLIST} do echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf done fi get_value_from_cfg_with_spaces netSaveIPv6NameServer NAMESERVERLIST="${VAL}" if [ ! -z "${NAMESERVERLIST}" ] then for NAMESERVER in ${NAMESERVERLIST} do echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf done fi }; # Function which determines if a nic is active / up is_nic_active() { ifconfig ${1} | grep -q "status: active" 2>/dev/null if [ $? -eq 0 ] ; then return 0 else return 1 fi }; # Function which detects available nics, and runs DHCP on them until # a success is found enable_auto_dhcp() { # start by getting a list of nics on this system ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist while read line do NIC="`echo $line | cut -d ':' -f 1`" DESC="`echo $line | cut -d ':' -f 2`" is_nic_active "${NIC}" if [ $? -eq 0 ] ; then echo_log "Trying DHCP on $NIC $DESC" dhclient ${NIC} >/dev/null 2>/dev/null if [ $? -eq 0 ] ; then # Got a valid DHCP IP, we can return now export WRKNIC="$NIC" return 0 fi fi done < ${TMPDIR}/.niclist }; # Function which detects available nics, and runs rtsol on them. enable_auto_slaac() { # start by getting a list of nics on this system ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist ALLNICS="" while read line do NIC="`echo $line | cut -d ':' -f 1`" DESC="`echo $line | cut -d ':' -f 2`" is_nic_active "${NIC}" if [ $? -eq 0 ] ; then echo_log "Will try IPv6 SLAAC on $NIC $DESC" ifconfig ${NIC} inet6 -ifdisabled accept_rtadv up ALLNICS="${ALLNICS} ${NIC}" fi done < ${TMPDIR}/.niclist # XXX once we support it in-tree call /sbin/resovconf here. echo_log "Running rtsol on ${ALLNICS}" rtsol -F ${ALLNICS} >/dev/null 2>/dev/null } # Get the mac address of a target NIC get_nic_mac() { FOUNDMAC="`ifconfig ${1} | grep 'ether' | tr -d '\t' | cut -d ' ' -f 2`" export FOUNDMAC } # Function which performs the manual setup of a target nic in the cfg enable_manual_nic() { # Get the target nic NIC="$1" # Check that this NIC exists rc_halt "ifconfig ${NIC}" get_value_from_cfg netIP NETIP="${VAL}" if [ "$NETIP" = "DHCP" ] then echo_log "Enabling DHCP on $NIC" rc_halt "dhclient ${NIC}" return 0 fi # If we get here, we have a manual setup, lets do so now # IPv4: # Set the manual IP if [ -n "${NETIP}" ] then # Check if we have a netmask to set get_value_from_cfg netMask NETMASK="${VAL}" if [ -n "${NETMASK}" ] then rc_halt "ifconfig inet ${NIC} netmask ${NETMASK}" else rc_halt "ifconfig inet ${NIC} ${NETIP}" fi fi # Check if we have a default router to set get_value_from_cfg netDefaultRouter NETROUTE="${VAL}" if [ -n "${NETROUTE}" ] then rc_halt "route add -inet default ${NETROUTE}" fi # IPv6: # Set static IPv6 address get_value_from_cfg netIPv6 NETIP="${VAL}" if [ -n ${NETIP} ] then rc_halt "ifconfig inet6 ${NIC} ${NETIP} -ifdisabled up" fi # Default router get_value_from_cfg netIPv6DefaultRouter NETROUTE="${VAL}" if [ -n "${NETROUTE}" ] then rc_halt "route add -inet6 default ${NETROUTE}" fi # Check if we have a nameserver to enable : >/etc/resolv.conf get_value_from_cfg netNameServer NAMESERVER="${VAL}" if [ -n "${NAMESERVER}" ] then echo "nameserver ${NAMESERVER}" >>/etc/resolv.conf fi get_value_from_cfg netIPv6NameServer NAMESERVER="${VAL}" if [ -n "${NAMESERVER}" ] then echo "nameserver ${NAMESERVER}" >>/etc/resolv.conf fi }; # Function which parses the cfg and enables networking per specified start_networking() { # Check if we have any networking requested get_value_from_cfg netDev if [ -z "${VAL}" ] then return 0 fi NETDEV="${VAL}" if [ "$NETDEV" = "AUTO-DHCP" ] then enable_auto_dhcp elif [ "$NETDEV" = "IPv6-SLAAC" ] then enable_auto_slaac elif [ "$NETDEV" = "AUTO-DHCP-SLAAC" ] then enable_auto_dhcp enable_auto_slaac else enable_manual_nic ${NETDEV} fi }; # Function which checks the cfg and enables the specified networking on # the installed system save_networking_install() { # Check if we have any networking requested to save get_value_from_cfg_with_spaces netSaveDev if [ -z "${VAL}" ] then return 0 fi NETDEVLIST="${VAL}" if [ "$NETDEVLIST" = "AUTO-DHCP" ] then save_auto_dhcp elif [ "$NETDEVLIST" = "IPv6-SLAAC" ] then save_auto_slaac elif [ "$NETDEVLIST" = "AUTO-DHCP-SLAAC" ] then save_auto_dhcp save_auto_slaac else for NETDEV in ${NETDEVLIST} do save_manual_nic ${NETDEV} done save_manual_router save_manual_nameserver fi }; Index: head/usr.sbin/pc-sysinstall/backend/functions-newfs.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-newfs.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-newfs.sh (revision 326275) @@ -1,262 +1,264 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions related to disk operations using newfs # Function which performs the ZFS magic setup_zfs_filesystem() { PART="$1" PARTFS="$2" PARTMNT="$3" EXT="$4" PARTGEOM="$5" ZPOOLOPTS="$6" ROOTSLICE="`echo ${PART} | rev | cut -b 2- | rev`" ZPOOLNAME=$(get_zpool_name "${PART}") # Sleep a few moments, let the disk catch its breath sleep 5 sync # Check if we have multiple zfs mounts specified for i in `echo ${PARTMNT} | sed 's|,| |g'` do # Check if we ended up with needing a zfs bootable partition if [ "${i}" = "/" -o "${i}" = "/boot" ] then if [ "$HAVEBOOT" = "YES" ] ; then continue ; fi if [ "${PARTGEOM}" = "MBR" ] ; then # Lets stamp the proper ZFS boot loader echo_log "Setting up ZFS boot loader support" rc_halt "dd if=/boot/zfsboot of=${ROOTSLICE} count=1" rc_halt "dd if=/boot/zfsboot of=${PART}${EXT} skip=1 seek=1024" fi fi done # Check if we have some custom zpool arguments and use them if so if [ ! -z "${ZPOOLOPTS}" ] ; then # Sort through devices and run gnop on them local gnopDev="" local newOpts="" for i in $ZPOOLOPTS do echo "$i" | grep -q '/dev/' if [ $? -eq 0 ] ; then rc_halt "gnop create -S 4096 ${i}" gnopDev="$gnopDev $i" newOpts="$newOpts ${i}.nop" else newOpts="$newOpts $i" fi done echo_log "Creating zpool ${ZPOOLNAME} with $newOpts" rc_halt "zpool create -m none -f ${ZPOOLNAME} ${newOpts}" # Export the pool rc_halt "zpool export ${ZPOOLNAME}" # Destroy the gnop devices for i in $gnopDev do rc_halt "gnop destroy ${i}.nop" done # And lastly re-import the pool rc_halt "zpool import ${ZPOOLNAME}" else # Lets do our pseudo-4k drive rc_halt "gnop create -S 4096 ${PART}${EXT}" # No zpool options, create pool on single device echo_log "Creating zpool ${ZPOOLNAME} on ${PART}${EXT}" rc_halt "zpool create -m none -f ${ZPOOLNAME} ${PART}${EXT}.nop" # Finish up the gnop 4k trickery rc_halt "zpool export ${ZPOOLNAME}" rc_halt "gnop destroy ${PART}${EXT}.nop" rc_halt "zpool import ${ZPOOLNAME}" fi # Disable atime for this zfs partition, speed increase rc_nohalt "zfs set atime=off ${ZPOOLNAME}" }; # Runs newfs on all the partiions which we've setup with bsdlabel setup_filesystems() { # Create the keydir rm -rf ${GELIKEYDIR} >/dev/null 2>/dev/null mkdir ${GELIKEYDIR} # Lets go ahead and read through the saved partitions we created, and determine if we need to run # newfs on any of them for PART in `ls ${PARTDIR}` do PARTDEV="`echo $PART | sed 's|-|/|g'`" PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`" PARTGEOM="`cat ${PARTDIR}/${PART} | cut -d '#' -f 5`" PARTXTRAOPTS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 6`" PARTIMAGE="`cat ${PARTDIR}/${PART} | cut -d '#' -f 7`" if [ ! -e "${PARTDEV}" ] ; then exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" fi # Make sure journaling isn't enabled on this device if [ -e "${PARTDEV}.journal" ] then rc_nohalt "gjournal stop -f ${PARTDEV}.journal" rc_nohalt "gjournal clear ${PARTDEV}" fi # Setup encryption if necessary if [ "${PARTENC}" = "ON" -a "${PARTFS}" != "SWAP" ] then echo_log "Creating geli provider for ${PARTDEV}" if [ -e "${PARTDIR}-enc/${PART}-encpass" ] ; then # Using a passphrase rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1" rc_halt "geli init -J ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}" rc_halt "geli attach -j ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}" else # No Encryption password, use key file rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1" rc_halt "geli init -b -s 4096 -P -K ${GELIKEYDIR}/${PART}.key ${PARTDEV}" rc_halt "geli attach -p -k ${GELIKEYDIR}/${PART}.key ${PARTDEV}" fi EXT=".eli" else # No Encryption EXT="" fi case ${PARTFS} in UFS) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 rc_halt "newfs -t ${PARTXTRAOPTS} ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+S) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+SUJ) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "tunefs -j enable ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+J) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 rc_halt "newfs ${PARTDEV}${EXT}" sleep 2 rc_halt "gjournal label -f ${PARTDEV}${EXT}" sleep 2 rc_halt "newfs ${PARTXTRAOPTS} -O 2 -J ${PARTDEV}${EXT}.journal" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; ZFS) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" setup_zfs_filesystem "${PARTDEV}" "${PARTFS}" "${PARTMNT}" "${EXT}" "${PARTGEOM}" "${PARTXTRAOPTS}" ;; SWAP) rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" sleep 2 ;; IMAGE) write_image "${PARTIMAGE}" "${PARTDEV}" sleep 2 ;; *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac done }; Index: head/usr.sbin/pc-sysinstall/backend/functions-packages.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-packages.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-packages.sh (revision 326275) @@ -1,411 +1,413 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh . ${BACKEND}/functions-ftp.sh get_package_index_by_ftp() { local INDEX_FILE local FTP_SERVER FTP_SERVER="${1}" INDEX_FILE="INDEX" USE_BZIP2=0 if [ -f "/usr/bin/bzip2" ] then INDEX_FILE="${INDEX_FILE}.bz2" USE_BZIP2=1 INDEX_PATH="${INDEXFILE}.bz2" else INDEX_PATH="${INDEXFILE}" fi fetch_file "${FTP_SERVER}/${INDEX_FILE}" "${INDEX_PATH}" "1" if [ -f "${INDEX_PATH}" ] && [ "${USE_BZIP2}" -eq "1" ] then bzip2 -d "${INDEX_PATH}" fi }; get_package_index_by_fs() { if [ "$INSTALLMEDIUM" = "local" ] ; then INDEXFILE="${LOCALPATH}/packages/INDEX" else INDEXFILE="${CDMNT}/packages/INDEX" fi }; get_package_index_size() { if [ -f "${INDEXFILE}" ] then SIZE=`ls -l ${INDEXFILE} | awk '{ print $5 }'` else get_ftp_mirror FTPHOST="${VAL}" FTPDIR="/pub/FreeBSD/releases/${FBSD_ARCH}/${FBSD_BRANCH}" FTPPATH="ftp://${FTPHOST}${FTPDIR}/packages" fetch -s "${FTPPATH}/INDEX.bz2" fi }; get_package_index() { RES=0 if [ -z "${INSTALLMODE}" ] then get_ftp_mirror FTPHOST="${VAL}" FTPDIR="/pub/FreeBSD/releases/${FBSD_ARCH}/${FBSD_BRANCH}" FTPPATH="ftp://${FTPHOST}${FTPDIR}/packages" get_package_index_by_ftp "${FTPPATH}" else case "${INSTALLMEDIUM}" in usb|dvd|local) get_package_index_by_fs ;; ftp) get_value_from_cfg ftpHost if [ -z "$VAL" ]; then exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" fi FTPHOST="${VAL}" get_value_from_cfg ftpDir if [ -z "$VAL" ]; then exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" fi FTPDIR="${VAL}" FTPPATH="ftp://${FTPHOST}${FTPDIR}" get_package_index_by_ftp "${FTPPATH}" ;; sftp) ;; *) RES=1 ;; esac fi return ${RES} }; parse_package_index() { echo_log "Building package dep list.. Please wait.." INDEX_FILE="${PKGDIR}/INDEX" exec 3<&0 exec 0<"${INDEXFILE}" while read -r line do PKGNAME="" CATEGORY="" PACKAGE="" DESC="" DEPS="" i=0 SAVE_IFS="${IFS}" IFS="|" for part in ${line} do if [ ${i} -eq 0 ] then PKGNAME="${part}" elif [ ${i} -eq 1 ] then PACKAGE=`basename "${part}"` elif [ ${i} -eq 3 ] then DESC="${part}" elif [ ${i} -eq 6 ] then CATEGORY=`echo "${part}" | cut -f1 -d' '` elif [ ${i} -eq 8 ] then DEPS="${part}" fi i=$((i+1)) done echo "${CATEGORY}|${PACKAGE}|${DESC}" >> "${INDEX_FILE}.parsed" echo "${PACKAGE}|${PKGNAME}|${DEPS}" >> "${INDEX_FILE}.deps" IFS="${SAVE_IFS}" done exec 0<&3 }; show_package_file() { PKGFILE="${1}" echo "Available Packages:" exec 3<&0 exec 0<"${PKGFILE}" while read -r line do CATEGORY=`echo "${line}" | cut -f1 -d'|'` PACKAGE=`echo "${line}" | cut -f2 -d'|'` DESC=`echo "${line}" | cut -f3 -d'|'` echo "${CATEGORY}/${PACKAGE}:${DESC}" done exec 0<&3 }; show_packages_by_category() { CATEGORY="${1}" INDEX_FILE="${PKGDIR}/INDEX.parsed" TMPFILE="/tmp/.pkg.cat" grep "^${CATEGORY}|" "${INDEX_FILE}" > "${TMPFILE}" show_package_file "${TMPFILE}" rm "${TMPFILE}" }; show_package_by_name() { CATEGORY="${1}" PACKAGE="${2}" INDEX_FILE="${PKGDIR}/INDEX.parsed" TMPFILE="/tmp/.pkg.cat.pak" grep "^${CATEGORY}|${PACKAGE}" "${INDEX_FILE}" > "${TMPFILE}" show_package_file "${TMPFILE}" rm "${TMPFILE}" }; show_packages() { show_package_file "${PKGDIR}/INDEX.parsed" }; get_package_dependencies() { PACKAGE="${1}" LONG="${2:-0}" RES=0 INDEX_FILE="${PKGDIR}/INDEX.deps" REGEX="^${PACKAGE}|" if [ ${LONG} -ne 0 ] then REGEX="^.*|${PACKAGE}|" fi LINE=`grep "${REGEX}" "${INDEX_FILE}" 2>/dev/null` DEPS=`echo "${LINE}"|cut -f3 -d'|'` export VAL="${DEPS}" if [ -z "${VAL}" ] then RES=1 fi return ${RES} }; get_package_name() { PACKAGE="${1}" RES=0 local PKGPTH # If we are on a local medium, we can parse the Latest/ directory if [ "${INSTALLMEDIUM}" != "ftp" ] ; then case "${INSTALLMEDIUM}" in usb|dvd) PKGPTH="${CDMNT}/packages" ;; *) PKGPTH="${LOCALPATH}/packages" ;; esac # Check the /Latest dir for generic names, then look for specific version in All/ if [ -e "${PKGPTH}/Latest/${PACKAGE}.${PKGEXT}" ] ; then NAME=`ls -al ${PKGPTH}/Latest/${PACKAGE}.${PKGEXT} 2>/dev/null | cut -d '>' -f 2 | rev | cut -f1 -d'/' | rev | tr -s ' '` else NAME=`ls -al ${PKGPTH}/All/${PACKAGE}.${PKGEXT} 2>/dev/null | cut -d '>' -f 2 | rev | cut -f1 -d'/' | rev | tr -s ' '` fi export VAL="${NAME}" else # Doing remote fetch, we we will look up, but some generic names like # "perl" wont work, since we don't know the default version INDEX_FILE="${PKGDIR}/INDEX.deps" REGEX="^${PACKAGE}|" LINE=`grep "${REGEX}" "${INDEX_FILE}" 2>/dev/null` NAME=`echo "${LINE}"|cut -f2 -d'|'` export VAL="${NAME}" fi if [ -z "${VAL}" ] then RES=1 fi return ${RES} }; get_package_short_name() { PACKAGE="${1}" RES=0 INDEX_FILE="${PKGDIR}/INDEX.deps" REGEX="^.*|${PACKAGE}|" LINE=`grep "${REGEX}" "${INDEX_FILE}" 2>/dev/null` NAME=`echo "${LINE}"|cut -f1 -d'|'` export VAL="${NAME}" if [ -z "${VAL}" ] then RES=1 fi return ${RES} }; get_package_category() { PACKAGE="${1}" INDEX_FILE="${PKGDIR}/INDEX.parsed" RES=0 LINE=`grep "|${PACKAGE}|" "${INDEX_FILE}" 2>/dev/null` NAME=`echo "${LINE}"|cut -f1 -d'|'` export VAL="${NAME}" if [ -z "${VAL}" ] then RES=1 fi return ${RES} }; fetch_package_by_ftp() { CATEGORY="${1}" PACKAGE="${2}" SAVEDIR="${3}" get_value_from_cfg ftpHost if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" fi FTPHOST="${VAL}" get_value_from_cfg ftpDir if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" fi FTPDIR="${VAL}" PACKAGE="${PACKAGE}.${PKGEXT}" FTP_SERVER="ftp://${FTPHOST}${FTPDIR}" if [ ! -f "${SAVEDIR}/${PACKAGE}" ] then PKGPATH="${CATEGORY}/${PACKAGE}" FTP_PATH="${FTP_HOST}/packages/${PKGPATH}" fetch_file "${FTP_PATH}" "${SAVEDIR}/" "0" fi }; fetch_package() { CATEGORY="${1}" PACKAGE="${2}" SAVEDIR="${3}" # Fetch package, but skip if installing from local media case "${INSTALLMEDIUM}" in usb|dvd|local) return ;; ftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;; sftp) ;; esac }; bootstrap_pkgng() { # Check if we need to boot-strap pkgng if run_chroot_cmd "which pkg-static" >/dev/null 2>/dev/null then return fi local PKGPTH # Ok, lets boot-strap this sucker echo_log "Bootstraping pkgng.." fetch_package "Latest" "pkg" "${PKGDLDIR}" # Figure out real location of "pkg" package case "${INSTALLMEDIUM}" in usb|dvd|local) PKGPTH="${PKGTMPDIR}/Latest/pkg.${PKGEXT}" ;; *) PKGPTH="${PKGTMPDIR}/pkg.${PKGEXT}" ;; esac rc_halt "pkg -c ${FSMNT} add ${PKGPTH}" ; run_chroot_cmd "pkg2ng" } get_package_location() { case "${INSTALLMEDIUM}" in usb|dvd) rc_halt "mount_nullfs ${CDMNT}/packages ${FSMNT}${PKGTMPDIR}" PKGDLDIR="${FSMNT}${PKGTMPDIR}/All" ;; local) rc_halt "mount_nullfs ${LOCALPATH}/packages ${FSMNT}${PKGTMPDIR}" PKGDLDIR="${FSMNT}${PKGTMPDIR}/All" ;; *) PKGDLDIR="${FSMNT}${PKGTMPDIR}" ;; esac export PKGDLDIR } Index: head/usr.sbin/pc-sysinstall/backend/functions-parse.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-parse.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-parse.sh (revision 326275) @@ -1,229 +1,231 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # functions.sh # Library of functions which pc-sysinstall may call upon for parsing the config # which gets the value of a setting in the provided line get_value_from_string() { if [ -n "${1}" ] then export VAL="`echo ${1} | cut -d '=' -f 2-`" else echo "Error: Did we forgot to supply a string to parse?" exit 1 fi }; # Get the value from the cfg file including spaces get_value_from_cfg_with_spaces() { if [ -n "${1}" ] then export VAL="`grep ^${1}= ${CFGF} | head -n 1 | cut -d '=' -f 2-`" else exit_err "Error: Did we forgot to supply a setting to grab?" fi }; # Get the value from the cfg file get_value_from_cfg() { if [ -n "${1}" ] then export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2- | tr -d ' '` else exit_err "Error: Did we forgot to supply a setting to grab?" fi }; # Checks the value of a setting in the provided line with supplied possibilities # 1 = setting we are checking, 2 = list of valid values if_check_value_exists() { if [ -n "${1}" -a -n "${2}" ] then # Get the first occurrence of the setting from the config, strip out whitespace VAL=`grep "^${1}" ${CFGF} | head -n 1 | cut -d '=' -f 2- | tr -d ' '` if [ -z "${VAL}" ] then # This value doesn't exist, lets return return 0 fi VALID="1" for i in ${2} do VAL=`echo "$VAL"|tr A-Z a-z` if [ "$VAL" = "${i}" ] then VALID="0" fi done if [ "$VALID" = "1" ] then exit_err "Error: ${1} is set to unknown value $VAL" fi else exit_err "Error: Did we forgot to supply a string to parse and setting to grab?" fi }; # Checks the value of a setting in the provided line with supplied possibilities # 1 = setting we are checking, 2 = list of valid values check_value() { if [ -n "${1}" -a -n "${2}" ] then # Get the first occurrence of the setting from the config, strip out whitespace VAL=`grep "^${1}" ${CFGF} | head -n 1 | cut -d '=' -f 2- | tr -d ' '` VALID="1" for i in ${2} do if [ "$VAL" = "${i}" ] then VALID="0" fi done if [ "$VALID" = "1" ] then exit_err "Error: ${1} is set to unknown value $VAL" fi else exit_err "Error: Did we forgot to supply a string to parse and setting to grab?" fi }; # Checks for the presence of the supplied arguments in the config file # 1 = values to confirm exist file_sanity_check() { if [ -n "$CFGF" -a -n "$1" ] then for i in $1 do grep -q "^${i}=" $CFGF 2>/dev/null if [ $? -eq 0 ] then LN=`grep "^${i}=" ${CFGF} | head -n 1 | cut -d '=' -f 2- | tr -d ' '` if [ -z "${LN}" ] then echo "Error: Config fails sanity test! ${i}= is empty" exit 1 fi else echo "Error: Config fails sanity test! Missing ${i}=" exit 1 fi done else echo "Error: Missing config file, and / or values to sanity check for!" exit 1 fi }; # Function which merges the contents of a new config into the specified old one # Only works with = type configurations merge_config() { OLDCFG="${1}" NEWCFG="${2}" FINALCFG="${3}" # Copy our oldcfg to the new one, which will be used as basis cp ${OLDCFG} ${FINALCFG} # Remove blank lines from new file cat ${NEWCFG} | sed '/^$/d' > ${FINALCFG}.tmp # Set our marker if we've found any FOUNDMERGE="NO" while read newline do echo ${newline} | grep -q "^#" 2>/dev/null if [ $? -ne 0 ] ; then VAL="`echo ${newline} | cut -d '=' -f 1`" cat ${OLDCFG} | grep -q ${VAL} 2>/dev/null if [ $? -ne 0 ] ; then if [ "${FOUNDMERGE}" = "NO" ] ; then echo "" >> ${FINALCFG} echo "# Auto-merged values from newer ${NEWCFG}" >> ${FINALCFG} FOUNDMERGE="YES" fi echo "${newline}" >> ${FINALCFG} fi fi done < ${FINALCFG}.tmp rm ${FINALCFG}.tmp }; # Loop to check for a specified mount-point in a list check_for_mount() { MNTS="${1}" FINDMNT="${2}" # Check if we found a valid root partition for CHECKMNT in `echo ${MNTS} | sed 's|,| |g'` do if [ "${CHECKMNT}" = "${FINDMNT}" ] ; then return 0 fi done return 1 }; # Function which returns the next line in the specified config file get_next_cfg_line() { CURFILE="$1" CURLINE="$2" FOUND="1" while read line do if [ "$FOUND" = "0" ] ; then export VAL="$line" return fi if [ "$line" = "${CURLINE}" ] ; then FOUND="0" fi done <${CURFILE} # Got here, couldn't find this line or at end of file, set VAL to "" export VAL="" }; Index: head/usr.sbin/pc-sysinstall/backend/functions-runcommands.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-runcommands.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-runcommands.sh (revision 326275) @@ -1,110 +1,112 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh run_chroot_cmd() { CMD="$@" echo_log "Running chroot command: ${CMD}" echo "$CMD" >${FSMNT}/.runcmd.sh chmod 755 ${FSMNT}/.runcmd.sh chroot ${FSMNT} sh /.runcmd.sh RES=$? rm ${FSMNT}/.runcmd.sh return ${RES} }; run_chroot_script() { SCRIPT="$@" SBASE=`basename $SCRIPT` cp ${SCRIPT} ${FSMNT}/.$SBASE chmod 755 ${FSMNT}/.${SBASE} echo_log "Running chroot script: ${SCRIPT}" chroot ${FSMNT} /.${SBASE} RES=$? rm ${FSMNT}/.${SBASE} return ${RES} }; run_ext_cmd() { CMD="$@" # Make sure to export FSMNT, in case cmd needs it export FSMNT echo_log "Running external command: ${CMD}" echo "${CMD}"> ${TMPDIR}/.runcmd.sh chmod 755 ${TMPDIR}/.runcmd.sh sh ${TMPDIR}/.runcmd.sh RES=$? rm ${TMPDIR}/.runcmd.sh return ${RES} }; # Starts the user setup run_commands() { while read line do # Check if we need to run any chroot command echo $line | grep -q ^runCommand= 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "$line" run_chroot_cmd "$VAL" fi # Check if we need to run any chroot script echo $line | grep -q ^runScript= 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "$line" run_chroot_script "$VAL" fi # Check if we need to run any chroot command echo $line | grep -q ^runExtCommand= 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "$line" run_ext_cmd "$VAL" fi done <${CFGF} }; Index: head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh (revision 326275) @@ -1,210 +1,212 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which unmount all mounted disk filesystems # Unmount all mounted partitions under specified dir umount_all_dir() { _udir="$1" _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3` for _ud in $_umntdirs do umount -f ${_ud} done } # Script that adds our gmirror devices for syncing start_gmirror_sync() { cd ${MIRRORCFGDIR} for DISK in `ls ${MIRRORCFGDIR}` do MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`" MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`" MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`" # Start the mirroring service rc_nohalt "gmirror forget ${MIRRORNAME}" rc_halt "gmirror insert ${MIRRORNAME} ${MIRRORDISK}" done }; # Unmounts all our mounted file-systems unmount_all_filesystems() { # Copy the logfile to disk before we unmount cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log cd / # Start by unmounting any ZFS partitions zfs_cleanup_unmount # Lets read our partition list, and unmount each ################################################################## for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`" if [ "${PARTENC}" = "ON" ] then EXT=".eli" else EXT="" fi if [ "${PARTFS}" = "SWAP" ] then rc_nohalt "swapoff ${PARTDEV}${EXT}" fi # Check if we've found "/", and unmount that last if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] then rc_halt "umount -f ${PARTDEV}${EXT}" # Re-check if we are missing a label for this device and create it again if so if [ ! -e "/dev/label/${PARTLABEL}" ] then case ${PARTFS} in UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;; *) ;; esac fi fi # Check if we've found "/" and make sure the label exists if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ] then if [ ! -e "/dev/label/${PARTLABEL}" ] then case ${PARTFS} in UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;; *) ;; esac fi fi done # Last lets the /mnt partition ######################################################### rc_nohalt "umount -f ${FSMNT}" # If are using a ZFS on "/" set it to legacy if [ ! -z "${FOUNDZFSROOT}" ] then rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}" fi # If we need to relabel "/" do it now if [ ! -z "${ROOTRELABEL}" ] then ${ROOTRELABEL} fi # Unmount our CDMNT rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null # Check if we need to run any gmirror syncing ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null if [ $? -eq 0 ] then # Lets start syncing now start_gmirror_sync fi }; # Unmounts any filesystems after a failure unmount_all_filesystems_failure() { cd / # if we did a fresh install, start unmounting if [ "${INSTALLMODE}" = "fresh" ] then # Lets read our partition list, and unmount each ################################################################## if [ -d "${PARTDIR}" ] then for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" if [ "${PARTFS}" = "SWAP" ] then if [ "${PARTENC}" = "ON" ] then swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null else swapoff ${PARTDEV} >/dev/null 2>/dev/null fi fi # Check if we've found "/" again, don't need to mount it twice if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] then umount -f ${PARTDEV} >/dev/null 2>/dev/null umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null fi done # Last lets the /mnt partition ######################################################### umount -f ${FSMNT} >/dev/null 2>/dev/null fi else # We are doing a upgrade, try unmounting any of these filesystems chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null umount -f ${FSMNT}/usr >/dev/null 2>/dev/null umount -f ${FSMNT}/dev >/dev/null 2>/dev/null umount -f ${FSMNT} >/dev/null 2>/dev/null sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null fi # Unmount our CDMNT umount ${CDMNT} >/dev/null 2>/dev/null }; Index: head/usr.sbin/pc-sysinstall/backend/functions-upgrade.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-upgrade.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-upgrade.sh (revision 326275) @@ -1,247 +1,249 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which perform the mounting / unmount for upgrades . ${PROGDIR}/backend/functions-unmount.sh mount_target_slice() { MPART="${1}" # Import any zpools zpool import -o altroot=${FSMNT} -a umount_all_dir "${FSMNT}" # Set a variable of files we want to make backups of before doing upgrade BKFILES="/etc/rc.conf /boot/loader.conf" if [ -e "/dev/${MPART}" ] ; then rc_nohalt "mount /dev/${MPART} ${FSMNT}" if [ $? -ne 0 ] ; then # Check if we have ZFS tank name rc_halt "mount -t zfs ${MPART} ${FSMNT}" fi else # Check if we have ZFS tank name rc_halt "mount -t zfs ${MPART} ${FSMNT}" fi # Mount devfs in chroot mount -t devfs devfs ${FSMNT}/dev # Check if we have any ZFS partitions to mount zfs mount -a # Mount all the fstab goodies on disk chroot ${FSMNT} /sbin/mount -a -t nolinprocfs >>${LOGOUT} 2>>${LOGOUT} chroot ${FSMNT} umount /proc >/dev/null 2>/dev/null chroot ${FSMNT} umount /compat/linux/proc >/dev/null 2>/dev/null # Now before we start the upgrade, make sure we set our noschg flags echo_log "Cleaning up old filesystem... Please wait..." rc_halt "chflags -R noschg ${FSMNT}" # Make backup copies of some files for i in ${BKFILES} do cp ${FSMNT}${i} ${FSMNT}${i}.preUpgrade >/dev/null 2>/dev/null done # Remove some old dirs rm -rf ${FSMNT}/etc/rc.d >/dev/null 2>/dev/null # If we are doing PC-BSD install, lets cleanup old pkgs on disk if [ "$INSTALLTYPE" != "FreeBSD" ] then echo_log "Removing old packages, this may take a while... Please wait..." echo '#!/bin/sh for i in `pkg_info -aE` do echo "Uninstalling package: ${i}" pkg_delete -f ${i} >/dev/null 2>/dev/null done ' >${FSMNT}/.cleanPkgs.sh chmod 755 ${FSMNT}/.cleanPkgs.sh chroot ${FSMNT} /.cleanPkgs.sh rm ${FSMNT}/.cleanPkgs.sh run_chroot_cmd "pkg_delete -f \*" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /usr/PCBSD" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /PCBSD" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /var/db/pkgs" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /usr/local32" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /usr/sbin" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /usr/lib" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /usr/bin" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /boot/kernel" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /sbin" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /bin" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /lib" >/dev/null 2>/dev/null run_chroot_cmd "rm -rf /libexec" >/dev/null 2>/dev/null fi }; # Mount the target upgrade partitions mount_upgrade() { # Make sure we remove the old upgrade-mount script rm -rf ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null # We are ready to start mounting, lets read the config and do it while read line do echo $line | grep -q "^disk0=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" DISK="$VAL" fi echo $line | grep -q "^commitDiskPart" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this disk setup / lets do sanity check and do it if [ -n "${DISK}" ] then # Start mounting this slice mount_target_slice "${DISK}" # Increment our disk counter to look for next disk and unset unset DISK break else exit_err "ERROR: commitDiskPart was called without procceding disk= and partition= entries!!!" fi fi done <${CFGF} }; copy_skel_files_upgrade() { # Now make sure we fix any user profile scripts, which cause problems from 7.x->8.x echo '#!/bin/sh cd /home for i in `ls` do # Backup the old profile dirs if [ -d "${i}" ] then mv /home/${i}/.kde4 /home/${i}/.kde4.preUpgrade >/dev/null 2>/dev/null mv /home/${i}/.kde /home/${i}/.kde.preUpgrade >/dev/null 2>/dev/null mv /home/${i}/.fluxbox /home/${i}/.fluxbox.preUpgrade >/dev/null 2>/dev/null # Copy over the skel directories tar cv --exclude "./dot.*" -f - -C /usr/share/skel . 2>/dev/null | tar xvf - -C /home/${i} 2>/dev/null for j in `ls /usr/share/skel/dot*` do dname=`echo ${j} | sed s/dot//` cp /usr/share/skel/${j} /home/${i}/${dname} done chown -R ${i}:${i} /home/${i} fi done ' >${FSMNT}/.fixUserProfile.sh chmod 755 ${FSMNT}/.fixUserProfile.sh chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null rm ${FSMNT}/.fixUserProfile.sh # if the user wants to keep their original .kde4 profile ########################################################################### get_value_from_cfg "upgradeKeepDesktopProfile" if [ "$VAL" = "YES" -o "$VAL" = "yes" ] ; then echo '#!/bin/sh cd /home for i in `ls` do # Import the old config again if [ -d "${i}/.kde4.preUpgrade" ] then # Copy over the skel directories tar cv -f - -C /home/${i}/.kde4.preUpgrade . 2>/dev/null | tar xvf - -C /home/${i}/.kde4 2>/dev/null chown -R ${i}:${i} /home/${i}/.kde4 fi done ' >${FSMNT}/.fixUserProfile.sh chmod 755 ${FSMNT}/.fixUserProfile.sh chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null rm ${FSMNT}/.fixUserProfile.sh fi }; # Function which merges some configuration files with the new defaults merge_old_configs() { # Merge the loader.conf with old cp ${FSMNT}/boot/loader.conf ${FSMNT}/boot/loader.conf.new merge_config "${FSMNT}/boot/loader.conf.preUpgrade" "${FSMNT}/boot/loader.conf.new" "${FSMNT}/boot/loader.conf" rm ${FSMNT}/boot/loader.conf.new # Merge the rc.conf with old cp ${FSMNT}/etc/rc.conf ${FSMNT}/etc/rc.conf.new merge_config "${FSMNT}/etc/rc.conf.preUpgrade" "${FSMNT}/etc/rc.conf.new" "${FSMNT}/etc/rc.conf" rm ${FSMNT}/etc/rc.conf.new }; # Function which unmounts all the mounted file-systems unmount_upgrade() { # If on PC-BSD, make sure we copy any fixed skel files if [ "$INSTALLTYPE" != "FreeBSD" ] ; then copy_skel_files_upgrade fi cd / # Unmount FS umount_all_dir "${FSMNT}" # Run our saved unmount script for these file-systems rc_nohalt "umount -f ${FSMNT}" umount ${CDMNT} }; Index: head/usr.sbin/pc-sysinstall/backend/functions-users.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions-users.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions-users.sh (revision 326275) @@ -1,186 +1,188 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh # Function which checks and sets up auto-login for a user if specified check_autologin() { get_value_from_cfg autoLoginUser if [ -n "${VAL}" -a "${INSTALLTYPE}" = "PCBSD" ] then AUTOU="${VAL}" # Add the auto-login user line sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc # Add the auto-login user line sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc fi }; # Function which actually runs the adduser command on the filesystem add_user() { ARGS="${1}" if [ -e "${FSMNT}/.tmpPass" ] then # Add a user with a supplied password run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" rc_halt "rm ${FSMNT}/.tmpPass" else # Add a user with no password run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" fi }; # Function which reads in the config, and adds any users specified setup_users() { # We are ready to start setting up the users, lets read the config while read line do echo $line | grep -q "^userName=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERNAME="$VAL" fi echo $line | grep -q "^userComment=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERCOMMENT="$VAL" fi echo $line | grep -q "^userPass=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERPASS="$VAL" fi echo $line | grep -q "^userEncPass=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERENCPASS="$VAL" fi echo $line | grep -q "^userShell=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" strip_white_space "$VAL" USERSHELL="$VAL" fi echo $line | grep -q "^userHome=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERHOME="$VAL" fi echo $line | grep -q "^userGroups=" 2>/dev/null if [ $? -eq 0 ] then get_value_from_string "${line}" USERGROUPS="$VAL" fi echo $line | grep -q "^commitUser" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this user, lets check and do it if [ -n "${USERNAME}" ] then # Now add this user to the system, by building our args list ARGS="-n ${USERNAME}" if [ -n "${USERCOMMENT}" ] then ARGS="${ARGS} -c \"${USERCOMMENT}\"" fi if [ -n "${USERPASS}" ] then ARGS="${ARGS} -h 0" echo "${USERPASS}" >${FSMNT}/.tmpPass elif [ -n "${USERENCPASS}" ] then ARGS="${ARGS} -H 0" echo "${USERENCPASS}" >${FSMNT}/.tmpPass else ARGS="${ARGS} -h -" rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null fi if [ -n "${USERSHELL}" ] then ARGS="${ARGS} -s \"${USERSHELL}\"" else ARGS="${ARGS} -s \"/nonexistant\"" fi if [ -n "${USERHOME}" ] then ARGS="${ARGS} -m -d \"${USERHOME}\"" fi if [ -n "${USERGROUPS}" ] then ARGS="${ARGS} -G \"${USERGROUPS}\"" fi add_user "${ARGS}" # Unset our vars before looking for any more users unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS else exit_err "ERROR: commitUser was called without any userName= entry!!!" fi fi done <${CFGF} # Check if we need to enable a user to auto-login to the desktop check_autologin }; Index: head/usr.sbin/pc-sysinstall/backend/functions.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/functions.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/functions.sh (revision 326275) @@ -1,540 +1,542 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # functions.sh # Library of functions which pc-sysinstall may call upon # Function which displays the help-index file display_help() { if [ -e "${PROGDIR}/doc/help-index" ] then cat ${PROGDIR}/doc/help-index else echo "Error: ${PROGDIR}/doc/help-index not found" exit 1 fi }; # Function which displays the help for a specified command display_command_help() { if [ -z "$1" ] then echo "Error: No command specified to display help for" exit 1 fi if [ -e "${PROGDIR}/doc/help-${1}" ] then cat ${PROGDIR}/doc/help-${1} else echo "Error: ${PROGDIR}/doc/help-${1} not found" exit 1 fi }; # Function to convert bytes to megabytes convert_byte_to_megabyte() { if [ -z "${1}" ] then echo "Error: No bytes specified!" exit 1 fi expr -e ${1} / 1048576 }; # Function to convert blocks to megabytes convert_blocks_to_megabyte() { if [ -z "${1}" ] ; then echo "Error: No blocks specified!" exit 1 fi expr -e ${1} / 2048 }; # Takes $1 and strips the whitespace out of it, returns VAL strip_white_space() { if [ -z "${1}" ] then echo "Error: No value setup to strip whitespace from!" exit 1 fi export VAL=`echo "$1" | tr -d ' '` }; # Displays an error message and exits with error 1 exit_err() { # Echo the message for the users benefit echo "EXITERROR: $1" # Save this error to the log file echo "EXITERROR: ${1}" >>$LOGOUT # Check if we need to unmount any file-systems after this failure unmount_all_filesystems_failure echo "For more details see log file: $LOGOUT" exit 1 }; # Run-command, don't halt if command exits with non-0 rc_nohalt() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_nohalt()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} >>${LOGOUT} 2>>${LOGOUT} }; # Run-command, halt if command exits with non-0 rc_halt() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_halt()" fi echo "Running: ${CMD}" >>${LOGOUT} eval ${CMD} >>${LOGOUT} 2>>${LOGOUT} STATUS="$?" if [ "${STATUS}" != "0" ] then exit_err "Error ${STATUS}: ${CMD}" fi }; # Run-command w/echo to screen, halt if command exits with non-0 rc_halt_echo() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_halt_echo()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} 2>&1 | tee -a ${LOGOUT} STATUS="$?" if [ "$STATUS" != "0" ] then exit_err "Error ${STATUS}: $CMD" fi }; # Run-command w/echo, don't halt if command exits with non-0 rc_nohalt_echo() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_nohalt_echo()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} 2>&1 | tee -a ${LOGOUT} }; # Echo to the screen and to the log echo_log() { STR="$1" if [ -z "${STR}" ] then exit_err "Error: missing argument in echo_log()" fi echo "${STR}" | tee -a ${LOGOUT} }; # Make sure we have a numeric is_num() { expr $1 + 1 2>/dev/null return $? } # Function which uses "fetch" to download a file, and display a progress report fetch_file() { FETCHFILE="$1" FETCHOUTFILE="$2" EXITFAILED="$3" EXITFILE="${TMPDIR}/.fetchExit" rm ${FETCHOUTFILE} 2>/dev/null >/dev/null SIZE=$(( `fetch -s "${FETCHFILE}"` / 1024 )) echo "FETCH: ${FETCHFILE}" echo "FETCH: ${FETCHOUTFILE}" >>${LOGOUT} ( fetch -o ${FETCHOUTFILE} "${FETCHFILE}" >/dev/null 2>/dev/null ; echo "$?" > ${EXITFILE} ) & PID="$!" while z=1 do if [ -e "${FETCHOUTFILE}" ] then DSIZE=`du -k ${FETCHOUTFILE} | tr -d '\t' | cut -d '/' -f 1` if [ $(is_num "$DSIZE") ] ; then if [ $SIZE -lt $DSIZE ] ; then DSIZE="$SIZE"; fi echo "SIZE: ${SIZE} DOWNLOADED: ${DSIZE}" echo "SIZE: ${SIZE} DOWNLOADED: ${DSIZE}" >>${LOGOUT} fi fi # Check if the download is finished ps -p ${PID} >/dev/null 2>/dev/null if [ $? -ne 0 ] then break; fi sleep 2 done echo "FETCHDONE" EXIT="`cat ${EXITFILE}`" if [ "${EXIT}" != "0" -a "$EXITFAILED" = "1" ] then exit_err "Error: Failed to download ${FETCHFILE}" fi return $EXIT }; # Function to return a the zpool name for this device get_zpool_name() { DEVICE="$1" # Set the base name we use for zpools BASENAME="tank" if [ ! -d "${TMPDIR}/.zpools" ] ; then mkdir -p ${TMPDIR}/.zpools fi if [ -e "${TMPDIR}/.zpools/${DEVICE}" ] ; then cat ${TMPDIR}/.zpools/${DEVICE} return 0 else # Need to generate a zpool name for this device NUM=`ls ${TMPDIR}/.zpools/ | wc -l | sed 's| ||g'` # Is it used in another zpool? while : do NEWNAME="${BASENAME}${NUM}" zpool list | grep -qw "${NEWNAME}" local chk1=$? zpool import | grep -qw "${NEWNAME}" local chk2=$? if [ $chk1 -eq 1 -a $chk2 -eq 1 ] ; then break ; fi NUM=$((NUM+1)) done # Now save the new tank name mkdir -p ${TMPDIR}/.zpools/`dirname $DEVICE` echo "$NEWNAME" >${TMPDIR}/.zpools/${DEVICE} echo "${NEWNAME}" return 0 fi }; iscompressed() { local FILE local RES FILE="$1" RES=1 if echo "${FILE}" | \ grep -qiE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' 2>&1 then RES=0 fi return ${RES} } get_compression_type() { local FILE local SUFFIX FILE="$1" SUFFIX=`echo "${FILE}" | sed -E 's|^(.+)\.(.+)$|\2|'` VAL="" SUFFIX=`echo "${SUFFIX}" | tr A-Z a-z` case "${SUFFIX}" in z) VAL="lzw" ;; lzo) VAL="lzo" ;; lzw) VAL="lzw" ;; lzma) VAL="lzma" ;; gz) VAL="gzip" ;; bz2) VAL="bzip2" ;; xz) VAL="xz" ;; zip) VAL="zip" ;; esac export VAL } write_image() { local DEVICE_FILE IMAGE_FILE="$1" DEVICE_FILE="$2" if [ -z "${IMAGE_FILE}" ] then exit_err "ERROR: Image file not specified!" fi if [ -z "${DEVICE_FILE}" ] then exit_err "ERROR: Device file not specified!" fi if [ ! -f "${IMAGE_FILE}" ] then exit_err "ERROR: '${IMAGE_FILE}' does not exist!" fi DEVICE_FILE="${DEVICE_FILE#/dev/}" DEVICE_FILE="/dev/${DEVICE_FILE}" if [ ! -c "${DEVICE_FILE}" ] then exit_err "ERROR: '${DEVICE_FILE}' is not a character device!" fi if iscompressed "${IMAGE_FILE}" then local COMPRESSION get_compression_type "${IMAGE_FILE}" COMPRESSION="${VAL}" case "${COMPRESSION}" in lzw) rc_halt "uncompress ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.Z}" ;; lzo) rc_halt "lzop -d $IMAGE_{FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.lzo}" ;; lzma) rc_halt "lzma -d ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.lzma}" ;; gzip) rc_halt "gunzip ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.gz}" ;; bzip2) rc_halt "bunzip2 ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.bz2}" ;; xz) rc_halt "xz -d ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.xz}" ;; zip) rc_halt "unzip ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.zip}" ;; *) exit_err "ERROR: ${COMPRESSION} compression is not supported" ;; esac else rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE}" fi }; # Setup and install on a new disk / partition install_fresh() { # Lets start setting up the disk slices now setup_disk_slice if [ -z "${ROOTIMAGE}" ] then # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels setup_disk_label # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs # to setup the filesystems setup_filesystems # Lets mount the partitions now mount_all_filesystems # We are ready to begin extraction, lets start now init_extraction # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # Do any localization in configuration run_localize # Save any networking config on the installed system save_networking_install # Now add any users setup_users # Do any last cleanup / setup before unmounting run_final_cleanup # Now run any commands specified run_commands # Unmount and finish up unmount_all_filesystems fi echo_log "Installation finished!" }; # Extract the system to a pre-mounted directory install_extractonly() { # We are ready to begin extraction, lets start now init_extraction # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # Do any localization in configuration run_localize # Save any networking config on the installed system save_networking_install # Now add any users setup_users # Now run any commands specified run_commands # Set a hostname on the install system setup_hostname # Set the root_pw if it is specified set_root_pw echo_log "Installation finished!" }; install_image() { # We are ready to begin extraction, lets start now init_extraction echo_log "Installation finished!" }; install_upgrade() { # We're going to do an upgrade, skip all the disk setup # and start by mounting the target drive/slices mount_upgrade # Start the extraction process init_extraction # Do any localization in configuration run_localize # Now run any commands specified run_commands # Merge any old configuration files merge_old_configs # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # All finished, unmount the file-systems unmount_upgrade echo_log "Upgrade finished!" }; Index: head/usr.sbin/pc-sysinstall/backend/installimage.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/installimage.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/installimage.sh (revision 326275) @@ -1,34 +1,36 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Source our functions scripts . ${BACKEND}/functions.sh IMAGE_FILE="${1}" DEVICE_FILE="${2}" write_image "${IMAGE_FILE}" "${DEVICE_FILE}" Index: head/usr.sbin/pc-sysinstall/backend/parseconfig.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/parseconfig.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/parseconfig.sh (revision 326275) @@ -1,124 +1,126 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Main install configuration parsing script # # Source our functions scripts . ${BACKEND}/functions.sh . ${BACKEND}/functions-bsdlabel.sh . ${BACKEND}/functions-cleanup.sh . ${BACKEND}/functions-disk.sh . ${BACKEND}/functions-extractimage.sh . ${BACKEND}/functions-installcomponents.sh . ${BACKEND}/functions-installpackages.sh . ${BACKEND}/functions-localize.sh . ${BACKEND}/functions-mountdisk.sh . ${BACKEND}/functions-networking.sh . ${BACKEND}/functions-newfs.sh . ${BACKEND}/functions-packages.sh . ${BACKEND}/functions-parse.sh . ${BACKEND}/functions-runcommands.sh . ${BACKEND}/functions-ftp.sh . ${BACKEND}/functions-unmount.sh . ${BACKEND}/functions-upgrade.sh . ${BACKEND}/functions-users.sh # Check that the config file exists if [ ! -e "${1}" ] then echo "ERROR: Install configuration $1 does not exist!" exit 1 fi # Set our config file variable CFGF="$1" # Resolve any relative pathing CFGF="`realpath ${CFGF}`" export CFGF # Start by doing a sanity check, which will catch any obvious mistakes in the config file_sanity_check "installMode installType installMedium packageType" # We passed the Sanity check, lets grab some of the universal config settings and store them check_value installMode "fresh upgrade extract" check_value installType "PCBSD FreeBSD" check_value installMedium "dvd usb ftp rsync image local" check_value packageType "uzip tar rsync split dist" if_check_value_exists mirrorbal "load prefer round-robin split" # We passed all sanity checks! Yay, lets start the install echo "File Sanity Check -> OK" # Lets load the various universal settings now get_value_from_cfg installMode export INSTALLMODE="${VAL}" get_value_from_cfg installType export INSTALLTYPE="${VAL}" get_value_from_cfg installMedium export INSTALLMEDIUM="${VAL}" get_value_from_cfg packageType export PACKAGETYPE="${VAL}" # Check if we are doing any networking setup start_networking # If we are not doing an upgrade, lets go ahead and setup the disk case "${INSTALLMODE}" in fresh) if [ "${INSTALLMEDIUM}" = "image" ] then install_image else install_fresh fi ;; extract) # Extracting only, make sure we have a valid target directory get_value_from_cfg installLocation export FSMNT="${VAL}" if [ -z "$FSMNT" ] ; then exit_err "Missing installLocation=" ; fi if [ ! -d "$FSMNT" ] ; then exit_err "No such directory: $FSMNT" ; fi install_extractonly ;; upgrade) install_upgrade ;; *) exit 1 ;; esac exit 0 Index: head/usr.sbin/pc-sysinstall/backend/startautoinstall.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend/startautoinstall.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend/startautoinstall.sh (revision 326275) @@ -1,136 +1,138 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # Script which reads the pc-autoinstall.conf directive, and begins the install # # $FreeBSD$ # Source our functions scripts . ${BACKEND}/functions.sh . ${BACKEND}/functions-networking.sh . ${BACKEND}/functions-parse.sh # Check that the config file exists if [ ! -e "${1}" ] then echo "ERROR: Install configuration $1 does not exist!" exit 1 fi # Set our config file variable CONF=${1} INSTALL_CFG="/tmp/pc-sysinstall.cfg" # Check if the config file is on disk as well PCCFG=`grep "pc_config:" ${CONF} | grep -v "^#" | sed "s|pc_config: ||g" | sed "s|pc_config:||g"` SHUTDOWN_CMD=`grep "shutdown_cmd:" ${CONF} | grep -v "^#" | sed "s|shutdown_cmd: ||g" | sed "s|shutdown_cmd:||g"` CONFIRM_INS=`grep "confirm_install:" ${CONF} | grep -v "^#" | sed "s|confirm_install: ||g" | sed "s|confirm_install:||g"` # Check that this isn't a http / ftp file we need to fetch later echo "${PCCFG}" | grep -q -e "^http" -e "^ftp" 2>/dev/null if [ $? -ne 0 ] then # Copy over the install cfg file, if not done already if [ ! -e "${INSTALL_CFG}" ] then cp ${PCCFG} ${INSTALL_CFG} fi # Make sure we have the file which was copied into /tmp previously if [ ! -e "${INSTALL_CFG}" ] then echo "Error: ${INSTALL_CFG} is missing! Exiting in 10 seconds..." sleep 10 exit 150 fi else # We need to fetch a remote file, check and set any nic options before doing so NICCFG=`grep "nic_config:" ${CONF} | grep -v "^#" | sed "s|nic_config: ||g" | sed "s|nic_config:||g"` if [ "${NICCFG}" = "dhcp-all" -o "${NICCFG}" = "DHCP-ALL" ] then # Try to auto-enable dhcp on any nics we find enable_auto_dhcp else echo "Running command \"ifconfig ${NICCFG}\"" ifconfig ${NICCFG} WRKNIC="`echo ${NICCFG} | cut -d ' ' -f 1`" NICDNS=`grep "nic_dns:" ${CONF} | grep -v "^#" | sed "s|nic_dns: ||g" | sed "s|nic_dns:||g"` NICGATE=`grep "nic_gateway:" ${CONF} | grep -v "^#" | sed "s|nic_gateway: ||g" | sed "s|nic_gateway:||g"` echo "nameserver ${NICDNS}" >/etc/resolv.conf echo "Running command \"route add default ${NICGATE}\"" route add default ${NICGATE} fi get_nic_mac "$WRKNIC" nic_mac="${FOUNDMAC}" PCCFG=`echo ${PCCFG} | sed "s|%%NIC_MAC%%|${nic_mac}|g"` # Now try to fetch the remove file echo "Fetching cfg with: \"fetch -o ${INSTALL_CFG} ${PCCFG}\"" fetch -o "${INSTALL_CFG}" "${PCCFG}" if [ $? -ne 0 ] then echo "ERROR: Failed to fetch ${PCCFG}, install aborted" exit 150 fi fi # If we end up with a valid config, lets proccede if [ -e "${INSTALL_CFG}" ] then if [ "${CONFIRM_INS}" != "no" -a "${CONFIRM_INS}" != "NO" ] then echo "Type in 'install' to begin automated installation. Warning: Data on target disks may be destroyed!" read tmp case $tmp in install|INSTALL) ;; *) echo "Install canceled!" ; exit 150 ;; esac fi pc-sysinstall -c ${INSTALL_CFG} if [ $? -eq 0 ] then if [ -n "$SHUTDOWN_CMD" ] then ${SHUTDOWN_CMD} else echo "SUCCESS: Installation finished! Press ENTER to reboot." read tmp shutdown -r now fi else echo "ERROR: Installation failed, press ENTER to drop to shell." read tmp /bin/csh fi else echo "ERROR: Failed to get /tmp/pc-sysinstall.cfg for automated install..." exit 150 fi Index: head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh (revision 326275) @@ -1,102 +1,104 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Create partitions on a target disk ############################# . ${PROGDIR}/backend/functions.sh if [ -z "${1}" ] ; then echo "Error: No disk specified!" exit 1 fi if [ -z "${2}" ] ; then echo "Error: No size specified!" exit 1 fi if [ ! -e "/dev/${1}" ] ; then echo "Error: Disk /dev/${1} does not exist!" exit 1 fi DISK="${1}" MB="${2}" TYPE="${3}" STARTBLOCK="${4}" TOTALBLOCKS="`expr $MB \* 2048`" # If no TYPE specified, default to MBR if [ -z "$TYPE" ] ; then TYPE="mbr" ; fi # Sanity check the gpart type case $TYPE in apm|APM) ;; bsd|BSD) ;; ebr|EBR) ;; gpt|GPT) ;; mbr|MBR) ;; vtoc8|VTOC8) ;; *) echo "Error: Unknown gpart type: $TYPE" ; exit 1 ;; esac # Lets figure out what number this partition will be LASTSLICE="`gpart show $DISK | grep -v -e $DISK -e '\- free \-' -e '^$' | awk 'END {print $3}'`" if [ -z "${LASTSLICE}" ] ; then LASTSLICE="1" else LASTSLICE="`expr $LASTSLICE + 1`" fi SLICENUM="${LASTSLICE}" # Set a 4k Aligned start block if none specified if [ "${SLICENUM}" = "1" -a -z "$STARTBLOCK" ] ; then STARTBLOCK="2016" fi # If this is an empty disk, see if we need to create a new scheme for it gpart show ${DISK} >/dev/null 2>/dev/null if [ $? -eq 0 -a "${SLICENUM}" = "1" ] ; then if [ "${TYPE}" = "mbr" -o "${TYPE}" = "MBR" ] ; then flags="-s ${TYPE} -f active" else flags="-s ${TYPE}" fi gpart create ${flags} ${DISK} fi # If we have a starting block, use it if [ -n "$STARTBLOCK" ] ; then sBLOCK="-b $STARTBLOCK" fi gpart add ${sBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK} exit "$?" Index: head/usr.sbin/pc-sysinstall/backend-partmanager/delete-part.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-partmanager/delete-part.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-partmanager/delete-part.sh (revision 326275) @@ -1,89 +1,91 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Delete a specified partition, takes effect immediately ######################################################## . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-disk.sh if [ -z "${1}" ] then echo "Error: No partition specified!" exit 1 fi if [ ! -e "/dev/${1}" ] then echo "Error: Partition /dev/${1} does not exist!" exit 1 fi PARTITION="${1}" # First lets figure out the partition number for the given device ################################################################## # Get the number of characters in this dev CHARS="`echo $PARTITION | wc -c`" PARTINDEX="" # Lets read through backwards until we get the part number while z=1 do CHARS=$((CHARS-1)) LAST_CHAR=`echo "${PARTITION}" | cut -c $CHARS` echo "${LAST_CHAR}" | grep -q "^[0-9]$" 2>/dev/null if [ $? -eq 0 ] ; then PARTINDEX="${LAST_CHAR}${PARTINDEX}" else break fi done # Now get current disk we are working on CHARS=`expr $CHARS - 1` DISK="`echo $PARTITION | cut -c 1-${CHARS}`" # Make sure we have a valid disk name still if [ ! -e "/dev/${DISK}" ] ; then echo "Error: Disk: ${DISK} doesn't exist!" exit 1 fi echo "Running: gpart delete -i ${PARTINDEX} ${DISK}" gpart delete -i ${PARTINDEX} ${DISK} >/dev/null 2>/dev/null # Check if this was the last partition and destroy the disk geom if so get_disk_partitions "${DISK}" if [ -z "${VAL}" ] ; then gpart destroy ${DISK} fi exit "$?" Index: head/usr.sbin/pc-sysinstall/backend-query/detect-emulation.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/detect-emulation.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/detect-emulation.sh (revision 326275) @@ -1,41 +1,43 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ case "$(kenv smbios.system.product)" in VirtualBox) echo "emulation: VIRTUALBOX" exit 0 ;; VMware*) echo "emulation: VMWARE" exit 0 ;; *) echo "emulation: NO" exit 1 ;; esac Index: head/usr.sbin/pc-sysinstall/backend-query/detect-laptop.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/detect-laptop.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/detect-laptop.sh (revision 326275) @@ -1,32 +1,34 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ if devinfo | grep -q acpi_acad0; then echo "laptop: YES" else echo "laptop: NO" fi Index: head/usr.sbin/pc-sysinstall/backend-query/detect-nics.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/detect-nics.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/detect-nics.sh (revision 326275) @@ -1,36 +1,38 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ for i in $(ifconfig -l); do case "${i%%[0-9]*}" in lo|fwe|fwip|plip|pfsync|pflog|tun) continue ;; esac IDENT=$(dmesg | sed -n "s/^$i: <\(.*\)>.*$/\1/p" | head -1) echo "${i}: <$IDENT>" done Index: head/usr.sbin/pc-sysinstall/backend-query/disk-info.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/disk-info.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/disk-info.sh (revision 326275) @@ -1,60 +1,62 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Query a disk for partitions and display them ############################################################################# . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-disk.sh DISK="${1}" [ -z "${DISK}" ] && { echo 'Error: No disk specified!'; exit 1; } [ ! -e "/dev/${DISK}" ] && \ { echo "Error: Disk /dev/${DISK} does not exist!"; exit 1; } get_disk_cyl "${DISK}" CYLS="${VAL}" get_disk_heads "${DISK}" HEADS="${VAL}" get_disk_sectors "${DISK}" SECS="${VAL}" # Now get the disks size in MB KB="`diskinfo -v ${1} | grep 'bytes' | cut -d '#' -f 1 | tr -s '\t' ' ' | tr -d ' '`" MB=$(convert_byte_to_megabyte ${KB}) # Now get the Controller Type CTYPE="`dmesg | grep "^${1}:" | grep "B <" | cut -d '>' -f 2 | cut -d ' ' -f 3-10`" echo "cylinders=${CYLS}" echo "heads=${HEADS}" echo "sectors=${SECS}" echo "size=${MB}" echo "type=${CTYPE}" Index: head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh (revision 326275) @@ -1,112 +1,114 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ ARGS=$1 FLAGS_MD="" FLAGS_CD="" FLAGS_VERBOSE="" shift while [ -n "$1" ] do case "$1" in -m) FLAGS_MD=1 ;; -v) FLAGS_VERBOSE=1 ;; -c) FLAGS_CD=1 ;; esac shift done # Create our device listing SYSDISK=$(sysctl -n kern.disks) if [ -n "${FLAGS_MD}" ] then MDS=`mdconfig -l` if [ -n "${MDS}" ] then SYSDISK="${SYSDISK} ${MDS}" fi fi # Add any RAID devices if [ -d "/dev/raid" ] ; then cd /dev/raid for i in `ls` do SYSDISK="${SYSDISK} ${i}" done fi # Now loop through these devices, and list the disk drives for i in ${SYSDISK} do # Get the current device DEV="${i}" # Make sure we don't find any cd devices if [ -z "${FLAGS_CD}" ] then case "${DEV}" in acd[0-9]*|cd[0-9]*|scd[0-9]*) continue ;; esac fi # Try and get some identification information from GEOM NEWLINE=$(geom disk list $DEV 2>/dev/null | sed -ne 's/^ descr: *//p') if [ -z "$NEWLINE" ]; then NEWLINE=" " fi if [ -n "${FLAGS_MD}" ] && echo "${DEV}" | grep -E '^md[0-9]+' >/dev/null 2>/dev/null then NEWLINE=" " fi if [ -n "${FLAGS_VERBOSE}" ] then : fi # Save the disk list if [ ! -z "$DLIST" ] then DLIST="\n${DLIST}" fi DLIST="${DEV}:${NEWLINE}${DLIST}" done # Echo out the found line echo -e "$DLIST" | sort Index: head/usr.sbin/pc-sysinstall/backend-query/disk-part.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/disk-part.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/disk-part.sh (revision 326275) @@ -1,111 +1,113 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Query a disk for partitions and display them ############################# . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-disk.sh if [ -z "${1}" ] then echo "Error: No disk specified!" exit 1 fi if [ ! -e "/dev/${1}" ] then echo "Error: Disk /dev/${1} does not exist!" exit 1 fi DISK="${1}" # Now get the disks size in MB KB="`diskinfo -v ${1} | grep 'bytes' | cut -d '#' -f 1 | tr -s '\t' ' ' | tr -d ' '`" MB=$(convert_byte_to_megabyte ${KB}) TOTALSIZE="$MB" TOTALB="`diskinfo -v ${1} | grep 'in sectors' | tr -s '\t' ' ' | cut -d ' ' -f 2`" gpart show ${1} >/dev/null 2>/dev/null if [ "$?" != "0" ] ; then # No partitions on this disk, display entire disk size and exit echo "${1}-freemb: ${TOTALSIZE}" echo "${1}-freeblocks: ${TOTALB}" exit fi # Display if this is GPT or MBR formatted TYPE=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'` echo "${1}-format: $TYPE" # Set some search flags PART="0" EXTENDED="0" START="0" SIZEB="0" # Get a listing of partitions on this disk get_disk_partitions "${DISK}" PARTS="${VAL}" for curpart in $PARTS do # First get the sysid / label for this partition if [ "$TYPE" = "MBR" ] ; then get_partition_sysid_mbr "${DISK}" "${curpart}" echo "${curpart}-sysid: ${VAL}" get_partition_label_mbr "${DISK}" "${curpart}" echo "${curpart}-label: ${VAL}" else get_partition_label_gpt "${DISK}" "${curpart}" echo "${curpart}-sysid: ${VAL}" echo "${curpart}-label: ${VAL}" fi # Now get the startblock, blocksize and MB size of this partition get_partition_startblock "${DISK}" "${curpart}" START="${VAL}" echo "${curpart}-blockstart: ${START}" get_partition_blocksize "${DISK}" "${curpart}" SIZEB="${VAL}" echo "${curpart}-blocksize: ${SIZEB}" SIZEMB=$(convert_blocks_to_megabyte ${SIZEB}) echo "${curpart}-sizemb: ${SIZEMB}" done # Now calculate any free space LASTB="`expr $SIZEB + $START`" FREEB="`expr $TOTALB - $LASTB`" FREEMB="`expr ${FREEB} / 2048`" echo "${1}-freemb: $FREEMB" echo "${1}-freeblocks: $FREEB" Index: head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh (revision 326275) @@ -1,114 +1,116 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # Copyright (c) 2011 The FreeBSD Foundation # All rights reserved. # # Portions of this software were developed by Bjoern Zeeb # under sponsorship from the FreeBSD Foundation. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which enables networking with specified options ########################################################################### . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/conf/pc-sysinstall.conf . ${BACKEND}/functions-networking.sh . ${BACKEND}/functions-parse.sh NIC="$1" IP="$2" NETMASK="$3" DNS="$4" GATEWAY="$5" MIRRORFETCH="$6" IPV6="$7" IPV6GATE="$8" IPV6DNS="$9" if [ -z "${NIC}" ] then echo "ERROR: Usage enable-net " \ " " exit 150 fi if [ "$NIC" = "AUTO-DHCP" ] then enable_auto_dhcp elif [ "$NIC" = "IPv6-SLAAC" ] then enable_auto_slaac # In addition, if static values were defined, add them as well. # We might not get DNS information from RAs, for example. if [ -n "${IPV6}" ]; then VAL="" get_first_wired_nic if [ -n "${VAL}" ]; then ifconfig ${VAL} inet6 ${IPV6} alias fi fi # Append only here. if [ -n "${IPV6DNS}" ]; then echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf fi # Do not if [ -n "${IPV6GATE}" ]; then # Check if we have a default route already to not overwrite. if ! route -n get -inet6 default > /dev/null 2>&1 ; then route add -inet6 default ${IPV6GATE} fi fi else echo "Enabling NIC: $NIC" if [ -n "${IP}" ]; then ifconfig ${NIC} inet ${IP} ${NETMASK} fi if [ -n "${IPV6}" ]; then ifconfig ${NIC} inet6 ${IPV6} alias fi # Keep default from IPv4-only support times and clear the resolv.conf file. : > /etc/resolv.conf if [ -n "${DNS}" ]; then echo "nameserver ${DNS}" >>/etc/resolv.conf fi if [ -n "${IPV6DNS}" ]; then echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf fi if [ -n "${GATE}" ]; then route add -inet default ${GATE} fi if [ -n "${IPV6GATE}" ]; then route add -inet6 default ${IPV6GATE} fi fi case ${MIRRORFETCH} in ON|on|yes|YES) fetch -o /tmp/mirrors-list.txt ${MIRRORLIST} >/dev/null 2>/dev/null;; *) ;; esac Index: head/usr.sbin/pc-sysinstall/backend-query/get-packages.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/get-packages.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/get-packages.sh (revision 326275) @@ -1,52 +1,54 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which lists the available packages for this release ########################################################################### . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-packages.sh ID=`id -u` if [ "${ID}" -ne "0" ] then echo "Error: must be root!" exit 1 fi if [ ! -f "${PKGDIR}/INDEX" ] then get_package_index fi if [ -f "${PKGDIR}/INDEX" ] then echo "${PKGDIR}/INDEX" exit 0 fi exit 1 Index: head/usr.sbin/pc-sysinstall/backend-query/list-components.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-components.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-components.sh (revision 326275) @@ -1,55 +1,57 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which lists the available components for this release ########################################################################### . ${PROGDIR}/backend/functions.sh echo "Available Components:" if [ -d "${COMPDIR}" ] then cd ${COMPDIR} for i in `ls -d *` do if [ -e "${i}/component.cfg" -a -e "${i}/install.sh" -a -e "${i}/distfiles" ] then NAME="`grep 'name:' ${i}/component.cfg | cut -d ':' -f 2`" DESC="`grep 'description:' ${i}/component.cfg | cut -d ':' -f 2`" TYPE="`grep 'type:' ${i}/component.cfg | cut -d ':' -f 2`" echo " " echo "name: ${i}" echo "desc:${DESC}" echo "type:${TYPE}" if [ -e "${i}/component.png" ] then echo "icon: ${COMPDIR}/${i}/component.png" fi fi done fi Index: head/usr.sbin/pc-sysinstall/backend-query/list-config.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-config.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-config.sh (revision 326275) @@ -1,30 +1,32 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ echo "branch=${FBSD_BRANCH}" echo "arch=${FBSD_ARCH}" exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh (revision 326275) @@ -1,37 +1,39 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-ftp.sh # Backend script which lists all the available ftp mirrors for front-ends to display COUNTRY="${1}" get_ftp_mirrors "${COUNTRY}" show_mirrors "${VAL}" exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/list-packages.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-packages.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-packages.sh (revision 326275) @@ -1,86 +1,88 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which lists the available packages for this release ########################################################################### . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-packages.sh PACKAGE_CATEGORY="${1}" PACKAGE_NAME="${2}" NARGS=0 if [ ! -f "${PKGDIR}/INDEX" ] then echo "Error: please fetch package index with get-packages!" exit 1 fi if [ ! -f "${PKGDIR}/INDEX.parsed" ] then parse_package_index fi if [ -n "${PACKAGE_CATEGORY}" ] then NARGS=$((NARGS+1)) fi if [ -n "${PACKAGE_NAME}" ] then NARGS=$((NARGS+1)) fi if [ "${NARGS}" -eq "0" ] then show_packages elif [ "${NARGS}" -eq "1" ] then if [ "${PACKAGE_CATEGORY}" = "@INDEX@" ] then if [ -f "${PKGDIR}/INDEX" ] then echo "${PKGDIR}/INDEX" exit 0 else exit 1 fi else show_packages_by_category "${PACKAGE_CATEGORY}" fi elif [ "${NARGS}" -eq "2" ] then show_package_by_name "${PACKAGE_CATEGORY}" "${PACKAGE_NAME}" else show_packages fi Index: head/usr.sbin/pc-sysinstall/backend-query/list-rsync-backups.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-rsync-backups.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-rsync-backups.sh (revision 326275) @@ -1,70 +1,72 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which lists the backups present on a server ########################################################################### . ${PROGDIR}/backend/functions.sh SSHUSER=$1 SSHHOST=$2 SSHPORT=$3 if [ -z "${SSHHOST}" -o -z "${SSHPORT}" ] then echo "ERROR: Usage list-rsync-backups.sh " exit 150 fi # Look for full-system backups, needs at minimum a kernel to be bootable FINDCMD="find . -type d -maxdepth 6 -name 'kernel' | grep '/boot/kernel'" # Get a listing of the number of full backups saved OLDBACKUPS=`ssh -o 'BatchMode=yes' -p ${SSHPORT} ${SSHUSER}@${SSHHOST} "${FINDCMD}"` if [ "$?" = "0" ] then for i in ${OLDBACKUPS} do BACKPATH="`echo ${i} | sed 's|/boot/.*||g' | sed 's|^./||g'`" if [ -z "${BACKLIST}" ] then BACKLIST="${BACKPATH}" else BACKLIST="${BACKLIST}:${BACKPATH}" fi done if [ -z "${BACKLIST}" ] then echo "NONE" else echo "$BACKLIST" fi else echo "FAILED" fi Index: head/usr.sbin/pc-sysinstall/backend-query/list-tzones.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/list-tzones.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/list-tzones.sh (revision 326275) @@ -1,34 +1,36 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Backend script which lists all the available timezones for front-ends to display egrep -v '^#' /usr/share/zoneinfo/zone.tab |\ tr -s "\t" ":" |\ cut -d ":" -f 3-4 |\ sort exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/query-langs.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/query-langs.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/query-langs.sh (revision 326275) @@ -1,30 +1,32 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ cat ${PROGDIR}/conf/avail-langs exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/send-logs.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/send-logs.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/send-logs.sh (revision 326275) @@ -1,83 +1,85 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which creates a gzipped log and optionally mails it to the specified address ############################################################################ . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/conf/pc-sysinstall.conf . ${BACKEND}/functions-networking.sh . ${BACKEND}/functions-parse.sh # Bring up all NICS under DHCP enable_auto_dhcp MAILTO="$1" MAILRESULT="0" # Set the location of our compressed log TMPLOG="/tmp/pc-sysinstall.log" echo "# PC-SYSINSTALL LOG" >${TMPLOG} cat ${LOGOUT} >> ${TMPLOG} # Check if we have a GUI generated install cfg if [ -e "/tmp/sys-install.cfg" ] then echo "" >>${TMPLOG} echo "# PC-SYSINSTALL CFG " >>${TMPLOG} cat /tmp/sys-install.cfg | grep -vE 'rootPass|userPass' >> ${TMPLOG} fi # Save dmesg output echo "" >>${TMPLOG} echo "# DMESG OUTPUT " >>${TMPLOG} dmesg >> ${TMPLOG} # Get gpart info on all disks for i in `pc-sysinstall disk-list | cut -d ':' -f 1` do echo "" >>${TMPLOG} echo "# DISK INFO $i " >>${TMPLOG} ls /dev/${i}* >>${TMPLOG} gpart show ${i} >> ${TMPLOG} done # Show Mounted volumes echo "" >>${TMPLOG} echo "# MOUNT OUTPUT " >>${TMPLOG} mount >> ${TMPLOG} echo "Log file saved to ${TMPLOG}" echo "Warning: This file will be lost once the system is rebooted." echo "Do you wish to view this logfile now? (Y/N)" read tmp if [ "$tmp" = "Y" -o "$tmp" = "y" ] then more ${TMPLOG} fi Index: head/usr.sbin/pc-sysinstall/backend-query/set-mirror.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/set-mirror.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/set-mirror.sh (revision 326275) @@ -1,40 +1,42 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXSystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ . ${PROGDIR}/backend/functions.sh . ${PROGDIR}/backend/functions-ftp.sh MIRROR="${1}" if [ -z "${MIRROR}" ] then echo "Error: No mirror specified!" exit 1 fi set_ftp_mirror "${MIRROR}" exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/setup-ssh-keys.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/setup-ssh-keys.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/setup-ssh-keys.sh (revision 326275) @@ -1,64 +1,66 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which sets up password-less logins for ssh host ########################################################################### . ${PROGDIR}/backend/functions.sh SSHUSER=$1 SSHHOST=$2 SSHPORT=$3 if [ -z "${SSHUSER}" -o -z "${SSHHOST}" -o -z "${SSHPORT}" ] then echo "ERROR: Usage setup-ssh-keys " exit 150 fi cd ~ echo "Preparing to setup SSH key authorization..." echo "When prompted, enter your password for ${SSHUSER}@${SSHHOST}" if [ ! -e ".ssh/id_rsa.pub" ] then mkdir .ssh >/dev/null 2>/dev/null ssh-keygen -q -t rsa -N '' -f .ssh/id_rsa sleep 1 fi if [ ! -e ".ssh/id_rsa.pub" ] then echo "ERROR: Failed creating .ssh/id_rsa.pub" exit 150 fi # Get the .pub key PUBKEY="`cat .ssh/id_rsa.pub`" ssh -p ${SSHPORT} ${SSHUSER}@${SSHHOST} "mkdir .ssh ; echo $PUBKEY >> .ssh/authorized_keys; chmod 600 .ssh/authorized_keys ; echo $PUBKEY >> .ssh/authorized_keys2; chmod 600 .ssh/authorized_keys2" Index: head/usr.sbin/pc-sysinstall/backend-query/sys-mem.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/sys-mem.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/sys-mem.sh (revision 326275) @@ -1,39 +1,41 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ if smbios_mem=$(kenv -q smbios.memory.enabled); then smbios_mem=$(expr $smbios_mem / 1024) else smbios_mem=0 fi realmem=$(expr $(sysctl -n hw.realmem) / 1048576) if [ $smbios_mem -gt $realmem ]; then echo $smbios_mem else echo $realmem fi Index: head/usr.sbin/pc-sysinstall/backend-query/test-live.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/test-live.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/test-live.sh (revision 326275) @@ -1,33 +1,35 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which checks if we are running from install media, or real system ############################################################################# dmesg | grep -q 'md0: Preloaded image' || { echo 'REAL-DISK'; exit 1; } echo 'INSTALL-MEDIA' Index: head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh (revision 326275) @@ -1,69 +1,71 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # Copyright (c) 2011 The FreeBSD Foundation # All rights reserved. # # Portions of this software were developed by Bjoern Zeeb # under sponsorship from the FreeBSD Foundation.# # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Script which tries to ping "home" to see if Internet connectivity is # available. ############################################################################# rm ${TMPDIR}/.testftp >/dev/null 2>/dev/null ping -c 2 www.pcbsd.org >/dev/null 2>/dev/null if [ "$?" = "0" ] then echo "ftp: Up" exit 0 fi ping6 -c 2 www.pcbsd.org >/dev/null 2>/dev/null if [ "$?" = "0" ] then echo "ftp: Up" exit 0 fi ping -c 2 www.freebsd.org >/dev/null 2>/dev/null if [ "$?" = "0" ] then echo "ftp: Up" exit 0 fi ping6 -c 2 www.freebsd.org >/dev/null 2>/dev/null if [ "$?" = "0" ] then echo "ftp: Up" exit 0 fi echo "ftp: Down" exit 1 Index: head/usr.sbin/pc-sysinstall/backend-query/update-part-list.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/update-part-list.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/update-part-list.sh (revision 326275) @@ -1,99 +1,101 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ # Need access to a some unmount functions . ${PROGDIR}/backend/functions-unmount.sh echo "Running: find-update-parts" >> ${LOGOUT} rm ${TMPDIR}/AvailUpgrades >/dev/null 2>/dev/null FSMNT="/mnt" # Get the freebsd version on this partition get_fbsd_ver() { sFiles="/bin/sh /boot/kernel/kernel" for file in $sFiles do if [ ! -e "${FSMNT}/$file" ] ; then continue ; fi VER="`file ${FSMNT}/$file | grep 'for FreeBSD' | sed 's|for FreeBSD |;|g' | cut -d ';' -f 2 | cut -d ',' -f 1`" if [ "$?" = "0" ] ; then file ${FSMNT}/$file | grep '32-bit' >/dev/null 2>/dev/null if [ "${?}" = "0" ] ; then echo "${1}: FreeBSD ${VER} (32bit)" else echo "${1}: FreeBSD ${VER} (64bit)" fi fi break done } # Create our device listing SYSDISK="`sysctl kern.disks | cut -d ':' -f 2 | sed 's/^[ \t]*//'`" DEVS="" # Now loop through these devices, and list the disk drives for i in ${SYSDISK} do # Get the current device DEV="${i}" # Make sure we don't find any cd devices echo "${DEV}" | grep -e "^acd[0-9]" -e "^cd[0-9]" -e "^scd[0-9]" >/dev/null 2>/dev/null if [ "$?" != "0" ] ; then DEVS="${DEVS} `ls /dev/${i}*`" fi done # Search for regular UFS / Geom Partitions to upgrade for i in $DEVS do if [ ! -e "${i}a.journal" -a ! -e "${i}a" -a ! -e "${i}p2" -a ! -e "${i}p2.journal" ] ; then continue fi if [ -e "${i}a.journal" ] ; then _dsk="${i}a.journal" elif [ -e "${i}a" ] ; then _dsk="${i}a" elif [ -e "${i}p2" ] ; then _dsk="${i}p2" elif [ -e "${i}p2.journal" ] ; then _dsk="${i}p2.journal" fi mount -o ro ${_dsk} ${FSMNT} >>${LOGOUT} 2>>${LOGOUT} if [ $? -eq 0 ] ; then get_fbsd_ver "`echo ${_dsk} | sed 's|/dev/||g'`" umount -f ${FSMNT} >/dev/null 2>/dev/null fi done Index: head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-layouts.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-layouts.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-layouts.sh (revision 326275) @@ -1,67 +1,69 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ FOUND="0" TMPLIST="/tmp/.xkeyList.$$" XLST="/usr/local/share/X11/xkb/rules/xorg.lst" if [ ! -e "${XLST}" ] ; then exit 1 fi # Lets parse the xorg.list file, and see what layouts are supported while read line do if [ "$FOUND" = "1" -a ! -z "$line" ] then echo $line | grep '! ' >/dev/null 2>/dev/null if [ "$?" = "0" ] then break else echo "$line" >> ${TMPLIST} fi fi if [ "${FOUND}" = "0" ] then echo $line | grep '! layout' >/dev/null 2>/dev/null if [ "$?" = "0" ] then FOUND="1" fi fi done < $XLST sort -b -d +1 $TMPLIST # Delete the tmp file rm $TMPLIST exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-models.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-models.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-models.sh (revision 326275) @@ -1,58 +1,60 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ FOUND="0" # Lets parse the xorg.list file, and see what models are supported while read line do if [ "$FOUND" = "1" -a ! -z "$line" ] then echo $line | grep '! ' >/dev/null 2>/dev/null if [ "$?" = "0" ] then exit 0 else model="`echo $line | sed 's|(|[|g'`" model="`echo $model | sed 's|)|]|g'`" echo "$model" fi fi if [ "${FOUND}" = "0" ] then echo $line | grep '! model' >/dev/null 2>/dev/null if [ "$?" = "0" ] then FOUND="1" fi fi done < /usr/local/share/X11/xkb/rules/xorg.lst exit 0 Index: head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-variants.sh =================================================================== --- head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-variants.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/backend-query/xkeyboard-variants.sh (revision 326275) @@ -1,56 +1,58 @@ #!/bin/sh #- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $FreeBSD$ FOUND="0" # Lets parse the xorg.list file, and see what varients are supported while read line do if [ "$FOUND" = "1" -a ! -z "$line" ] then echo $line | grep '! ' >/dev/null 2>/dev/null if [ "$?" = "0" ] then exit 0 else echo "$line" fi fi if [ "${FOUND}" = "0" ] then echo $line | grep '! variant' >/dev/null 2>/dev/null if [ "$?" = "0" ] then FOUND="1" fi fi done < /usr/local/share/X11/xkb/rules/xorg.lst exit 0 Index: head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh =================================================================== --- head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh (revision 326274) +++ head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh (revision 326275) @@ -1,240 +1,242 @@ #!/bin/sh ##################################################################### # Author: Kris Moore # License: BSD # Description: pc-sysinstall provides a backend for performing # system installations, as well as calls which a front-end can use # to retrive information about the system ##################################################################### +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright 2010 iXsystems # All rights reserved # # Redistribution and use in source and binary forms, with or without # modification, are permitted providing 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 BY THE AUTHOR ``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. # # $FreeBSD$ ##################################################################### # User-editable configuration variables # Set this to the program location if [ -z "${PROGDIR}" ] then PROGDIR="/usr/share/pc-sysinstall" export PROGDIR fi # Set this to the components location COMPDIR="${PROGDIR}/components" export COMPDIR CONFDIR="${PROGDIR}/conf" export CONFDIR # Set this to the packages location PKGDIR="${CONFDIR}" export PKGDIR # End of user-editable configuration ##################################################################### # Set our QUERYDIR QUERYDIR="${PROGDIR}/backend-query" export QUERYDIR # Set our BACKEND BACKEND="${PROGDIR}/backend" export BACKEND PARTMANAGERDIR="${PROGDIR}/backend-partmanager" export PARTMANAGERDIR # Start by sourcing our conf file if [ -e "${PROGDIR}/conf/pc-sysinstall.conf" ] then . ${PROGDIR}/conf/pc-sysinstall.conf else echo "ERROR: Could not find ${PROGDIR}/conf/pc-sysinstall.conf" exit 1 fi # Now source our functions.sh if [ -e "${PROGDIR}/backend/functions.sh" ] then . ${PROGDIR}/backend/functions.sh else echo "ERROR: Could not find ${PROGDIR}/backend/functions.sh" exit 1 fi # Check if we are called without any flags and display help if [ -z "${1}" ] then # Display the help index display_help exit 0 fi case $1 in # The -c flag has been given, time to parse the script -c) if [ -z "${2}" ] then display_help else ${BACKEND}/parseconfig.sh ${2} exit $? fi ;; # The user requsted help help) if [ -z "${2}" ] then display_help else display_command_help ${2} fi ;; # Install an image file to a device install-image) ${BACKEND}/installimage.sh "${2}" "${3}" ;; # Parse an auto-install directive, and begin the installation start-autoinstall) ${BACKEND}/startautoinstall.sh ${2} ;; # The user is wanting to create a new partition create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}" "${4}" "${5}" ;; # The user is wanting to delete an existing partition delete-part) ${PARTMANAGERDIR}/delete-part.sh "${2}" ;; # The user is wanting to check if we are on a laptop or desktop detect-laptop) ${QUERYDIR}/detect-laptop.sh ;; # The user is wanting to see what nics are available on the system detect-nics) ${QUERYDIR}/detect-nics.sh ;; # The user is wanting to check if we are in emulation detect-emulation) ${QUERYDIR}/detect-emulation.sh ;; # The user is wanting to query a disk's information disk-info) ${QUERYDIR}/disk-info.sh ${2} ;; # The user is wanting to query which disks are available disk-list) ${QUERYDIR}/disk-list.sh $* ;; # The user is wanting to query a disk's partitions disk-part) ${QUERYDIR}/disk-part.sh ${2} ;; # Function allows the setting of networking by a calling front-end enable-net) ${QUERYDIR}/enable-net.sh "${2}" "${3}" "${4}" "${5}" "${6}" "${7}" ;; # Function which lists components available list-components) ${QUERYDIR}/list-components.sh ;; # Function which lists pc-sysinstall configuration list-config) ${QUERYDIR}/list-config.sh ;; # Function which lists available FTP mirrors list-mirrors) ${QUERYDIR}/list-mirrors.sh "${2}" ;; # Function which lists available packages list-packages) ${QUERYDIR}/list-packages.sh "${2}" "${3}" ;; # Function which lists available backups on a rsync/ssh server list-rsync-backups) ${QUERYDIR}/list-rsync-backups.sh "${2}" "${3}" "${4}" ;; # Function which lists timezones available list-tzones) ${QUERYDIR}/list-tzones.sh ;; # Requested a list of languages this install will support query-langs) ${QUERYDIR}/query-langs.sh ;; # Function which creates a error report, and mails it to the specified address send-logs) ${QUERYDIR}/send-logs.sh ${2} ;; # Function to get package index get-packages) ${QUERYDIR}/get-packages.sh "${2}" ;; # Function to set FTP mirror set-mirror) ${QUERYDIR}/set-mirror.sh "${2}" ;; # Function which allows setting up of SSH keys setup-ssh-keys) ${QUERYDIR}/setup-ssh-keys.sh "${2}" "${3}" "${4}" ;; # Function which lists the real memory of the system in MB sys-mem) ${QUERYDIR}/sys-mem.sh ;; # Run script which determines if we are booted from install media, or on disk test-live) ${QUERYDIR}/test-live.sh ;; # The user is wanting to test if the network is up and working test-netup) ${QUERYDIR}/test-netup.sh ;; # The user is wanting to get a list of partitions available to be updated / repaired update-part-list) ${QUERYDIR}/update-part-list.sh ;; # Requested a list of keyboard layouts that xorg supports xkeyboard-layouts) ${QUERYDIR}/xkeyboard-layouts.sh ;; # Requested a list of keyboard models that xorg supports xkeyboard-models) ${QUERYDIR}/xkeyboard-models.sh ;; # Requested a list of keyboard variants that xorg supports xkeyboard-variants) ${QUERYDIR}/xkeyboard-variants.sh ;; *) echo "Unknown Command: ${1}" exit 1 ;; esac # Exit with success if we made it to the end exit $?