diff --git a/release/packages/generate-ucl.sh b/release/packages/generate-ucl.sh index 72db4a3180b8..b7d6875b3eb1 100755 --- a/release/packages/generate-ucl.sh +++ b/release/packages/generate-ucl.sh @@ -1,164 +1,164 @@ #!/bin/sh # # main() { desc= comment= debug= uclsource= while getopts "do:s:u:" arg; do case ${arg} in d) debug=1 ;; o) outname="${OPTARG}" origname="${OPTARG}" ;; s) srctree="${OPTARG}" ;; u) uclfile="${OPTARG}" ;; *) echo "Unknown argument" ;; esac done shift $(( ${OPTIND} - 1 )) case "${outname}" in bootloader) pkgdeps="" ;; certctl) pkgdeps="caroot openssl" ;; clang) pkgdeps="lld libcompiler_rt-dev" ;; periodic) pkgdeps="cron" ;; # -dev packages that have no corresponding non-dev package # as a dependency. libcompat-dev|libcompiler_rt-dev|liby-dev) outname=${outname%%-dev} _descr="Development Files" ;; libcompat-lib32_dev|libcompiler_rt-lib32_dev|liby-lib32_dev) outname=${outname%%-lib32_dev} _descr="32-bit Libraries, Development Files" ;; libcompat-man|libelftc-man) outname=${outname%%-man} _descr="Manual Pages" ;; utilities) uclfile="${uclfile}" ;; runtime) outname="runtime" _descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)" ;; *-lib32_dev) outname="${outname%%-lib32_dev}" _descr="32-bit Libraries, Development Files" pkgdeps="${outname}" ;; *-lib32_dbg) outname="${outname%%-lib32_dbg}" _descr="32-bit Libraries, Debugging Symbols" pkgdeps="${outname}" ;; *-lib32) outname="${outname%%-lib32}" _descr="32-bit Libraries" pkgdeps="${outname}" ;; *-dev) outname="${outname%%-dev}" _descr="Development Files" pkgdeps="${outname}" ;; *-dbg) outname="${outname%%-dbg}" _descr="Debugging Symbols" pkgdeps="${outname}" ;; *-man) outname="${outname%%-man}" _descr="Manual Pages" pkgdeps="${outname}" ;; ${origname}) ;; *) uclfile="${outname##*}${origname}" outname="${outname##*}${origname}" ;; esac desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)" comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)" uclsource="${srctree}/release/packages/template.ucl" - if [ ! -z "${debug}" ]; then + if [ -n "${debug}" ]; then echo "" echo "===============================================================" echo "DEBUG:" echo "_descr=${_descr}" echo "outname=${outname}" echo "origname=${origname}" echo "srctree=${srctree}" echo "uclfile=${uclfile}" echo "desc=${desc}" echo "comment=${comment}" echo "vital=${vital}" echo "cp ${uclsource} -> ${uclfile}" echo "===============================================================" echo "" echo "" echo "" fi [ -z "${comment}" ] && comment="${outname} package" - [ ! -z "${_descr}" ] && comment="${comment} (${_descr})" + [ -n "${_descr}" ] && comment="${comment} (${_descr})" [ -z "${desc}" ] && desc="${outname} package" cp "${uclsource}" "${uclfile}" - if [ ! -z "${pkgdeps}" ]; then + if [ -n "${pkgdeps}" ]; then echo 'deps: {' >> ${uclfile} for dep in ${pkgdeps}; do cat <> ${uclfile} ${PKG_NAME_PREFIX}-${dep}: { origin: "base", version: "${PKG_VERSION}" } EOF done echo '}' >> ${uclfile} fi cap_arg="$( make -f ${srctree}/share/mk/bsd.endian.mk -VCAP_MKDB_ENDIAN )" ${srctree}/release/packages/generate-ucl.lua \ VERSION "${PKG_VERSION}" \ PKGNAME "${origname}" \ PKGGENNAME "${outname}" \ PKG_NAME_PREFIX "${PKG_NAME_PREFIX}" \ COMMENT "${comment}" \ DESC "${desc}" \ CAP_MKDB_ENDIAN "${cap_arg}" \ PKG_WWW "${PKG_WWW}" \ PKG_MAINTAINER "${PKG_MAINTAINER}" \ UCLFILES "${srctree}/release/packages/" \ ${uclfile} ${uclfile} return 0 } main "${@}" diff --git a/release/release.sh b/release/release.sh index 5a6de297f7a1..8f0624e57344 100755 --- a/release/release.sh +++ b/release/release.sh @@ -1,460 +1,460 @@ #!/bin/sh #- # Copyright (c) 2020-2021 Rubicon Communications, LLC (netgate.com) # Copyright (c) 2013-2019 The FreeBSD Foundation # Copyright (c) 2013 Glen Barber # Copyright (c) 2011 Nathan Whitehorn # All rights reserved. # # Portions of this software were developed by Glen Barber # 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. # # release.sh: check out source trees, and build release components with # totally clean, fresh trees. # Based on release/generate-release.sh written by Nathan Whitehorn # export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" VERSION=3 # Prototypes that can be redefined per-chroot or per-target. load_chroot_env() { } load_target_env() { } buildenv_setup() { } usage() { echo "Usage: $0 [-c release.conf]" exit 1 } # env_setup(): Set up the default build environment variables, such as the # CHROOTDIR, VCSCMD, GITROOT, etc. This is called before the release.conf # file is sourced, if '-c ' is specified. env_setup() { # The directory within which the release will be built. CHROOTDIR="/scratch" if [ -z "${RELENGDIR}" ]; then export RELENGDIR="$(dirname $(realpath ${0}))" fi # The default version control system command to obtain the sources. for _dir in /usr/bin /usr/local/bin; do [ -x "${_dir}/git" ] && VCSCMD="/${_dir}/git" - [ ! -z "${VCSCMD}" ] && break 2 + [ -n "${VCSCMD}" ] && break 2 done if [ -z "${VCSCMD}" -a -z "${NOGIT}" ]; then echo "*** The devel/git port/package is required." exit 1 fi VCSCMD="/usr/local/bin/git clone -q" # The default git checkout server, and branches for src/, doc/, # and ports/. GITROOT="https://git.FreeBSD.org/" SRCBRANCH="main" PORTBRANCH="main" GITSRC="src.git" GITPORTS="ports.git" # Set for embedded device builds. EMBEDDEDBUILD= # The default make.conf and src.conf to use. Set to /dev/null # by default to avoid polluting the chroot(8) environment with # non-default settings. MAKE_CONF="/dev/null" SRC_CONF="/dev/null" # The number of make(1) jobs, defaults to the number of CPUs available # for buildworld, and half of number of CPUs available for buildkernel # and 'make release'. WORLD_FLAGS="-j$(sysctl -n hw.ncpu)" KERNEL_FLAGS="-j$(( $(( $(sysctl -n hw.ncpu) + 1 )) / 2))" RELEASE_FLAGS="-j$(( $(( $(sysctl -n hw.ncpu) + 1 )) / 2))" MAKE_FLAGS="-s" # The name of the kernel to build, defaults to GENERIC. KERNEL="GENERIC" # Set to non-empty value to disable checkout of doc/ and/or ports/. NOPORTS= # Set to non-empty value to disable distributing source tree. NOSRC= # Set to non-empty value to build dvd1.iso as part of the release. WITH_DVD= WITH_COMPRESSED_IMAGES= # Set to non-empty value to build virtual machine images as part of # the release. WITH_VMIMAGES= WITH_COMPRESSED_VMIMAGES= XZ_THREADS=0 # Set to non-empty value to build virtual machine images for various # cloud providers as part of the release. WITH_CLOUDWARE= # Set to non-empty to build OCI images as part of the release WITH_OCIIMAGES= return 0 } # env_setup() # env_check(): Perform sanity tests on the build environment, such as ensuring # files/directories exist, as well as adding backwards-compatibility hacks if # necessary. This is called unconditionally, and overrides the defaults set # in env_setup() if '-c ' is specified. env_check() { chroot_build_release_cmd="chroot_build_release" # Prefix the branches with the GITROOT for the full checkout URL. SRC="${GITROOT}${GITSRC}" PORT="${GITROOT}${GITPORTS}" if [ -n "${EMBEDDEDBUILD}" ]; then WITH_DVD= WITH_COMPRESSED_IMAGES= case ${EMBEDDED_TARGET}:${EMBEDDED_TARGET_ARCH} in arm:arm*|arm64:aarch64|riscv:riscv64*) chroot_build_release_cmd="chroot_arm_build_release" ;; *) ;; esac fi # If NOSRC and/or NOPORTS are unset, they must not pass to make # as variables. The release makefile verifies definedness of the # NOPORTS variable instead of its value. SRCPORTS= if [ -n "${NOPORTS}" ]; then SRCPORTS="NOPORTS=yes" fi if [ -n "${NOSRC}" ]; then SRCPORTS="${SRCPORTS}${SRCPORTS:+ }NOSRC=yes" fi # The aggregated build-time flags based upon variables defined within # this file, unless overridden by release.conf. In most cases, these # will not need to be changed. CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}" NOCONF_FILES="__MAKE_CONF=/dev/null SRCCONF=/dev/null" if [ -n "${TARGET}" ] && [ -n "${TARGET_ARCH}" ]; then ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" else ARCH_FLAGS= fi if [ -z "${CHROOTDIR}" ]; then echo "Please set CHROOTDIR." exit 1 fi if [ $(id -u) -ne 0 ]; then echo "Needs to be run as root." exit 1 fi # Unset CHROOTBUILD_SKIP if the chroot(8) does not appear to exist. - if [ ! -z "${CHROOTBUILD_SKIP}" -a ! -e ${CHROOTDIR}/bin/sh ]; then + if [ -n "${CHROOTBUILD_SKIP}" -a ! -e ${CHROOTDIR}/bin/sh ]; then CHROOTBUILD_SKIP= fi CHROOT_MAKEENV="${CHROOT_MAKEENV} \ MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj" CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${NOCONF_FILES}" CHROOT_IMAKEFLAGS="${WORLD_FLAGS} ${NOCONF_FILES}" CHROOT_DMAKEFLAGS="${WORLD_FLAGS} ${NOCONF_FILES}" RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} \ ${CONF_FILES}" RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} \ KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}" RELEASE_RMAKEFLAGS="${ARCH_FLAGS} ${RELEASE_FLAGS} \ KERNCONF=\"${KERNEL}\" ${CONF_FILES} ${SRCPORTS} \ WITH_DVD=${WITH_DVD} WITH_VMIMAGES=${WITH_VMIMAGES} \ WITH_CLOUDWARE=${WITH_CLOUDWARE} WITH_OCIIMAGES=${WITH_OCIIMAGES} \ XZ_THREADS=${XZ_THREADS}" return 0 } # env_check() # chroot_setup(): Prepare the build chroot environment for the release build. chroot_setup() { load_chroot_env mkdir -p ${CHROOTDIR}/usr if [ -z "${SRC_UPDATE_SKIP}" ]; then if [ -d "${CHROOTDIR}/usr/src/.git" ]; then git -C ${CHROOTDIR}/usr/src pull -q else ${VCSCMD} ${SRC} -b ${SRCBRANCH} ${CHROOTDIR}/usr/src fi fi if [ -z "${NOPORTS}" ] && [ -z "${PORTS_UPDATE_SKIP}" ]; then if [ -d "${CHROOTDIR}/usr/ports/.git" ]; then git -C ${CHROOTDIR}/usr/ports pull -q else ${VCSCMD} ${PORT} -b ${PORTBRANCH} ${CHROOTDIR}/usr/ports fi fi if [ -z "${CHROOTBUILD_SKIP}" ]; then cd ${CHROOTDIR}/usr/src env ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld env ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \ DESTDIR=${CHROOTDIR} env ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \ DESTDIR=${CHROOTDIR} fi return 0 } # chroot_setup() # extra_chroot_setup(): Prepare anything additional within the build # necessary for the release build. extra_chroot_setup() { mkdir -p ${CHROOTDIR}/dev mount -t devfs devfs ${CHROOTDIR}/dev [ -e /etc/resolv.conf -a ! -e ${CHROOTDIR}/etc/resolv.conf ] && \ cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints # is created. This is needed by ports-mgmt/pkg. eval chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart # If MAKE_CONF and/or SRC_CONF are set and not character devices # (/dev/null), copy them to the chroot. if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF}) cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF} fi if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF}) cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF} fi _gitcmd="$(which git)" if [ -z "${NOGIT}" -a -z "${_gitcmd}" ]; then # Install git from ports if the ports tree is available; # otherwise install the pkg. if [ -d ${CHROOTDIR}/usr/ports ]; then # Trick the ports 'run-autotools-fixup' target to do the right # thing. _OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U) REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION) BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH) UNAME_r=${REVISION}-${BRANCH} GITUNSETOPTS="CONTRIB CURL CVS GITWEB GUI HTMLDOCS" GITUNSETOPTS="${GITUNSETOPTS} ICONV NLS P4 PERL" GITUNSETOPTS="${GITUNSETOPTS} SEND_EMAIL SUBTREE SVN" GITUNSETOPTS="${GITUNSETOPTS} PCRE PCRE2" PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes" PBUILD_FLAGS="${PBUILD_FLAGS} UNAME_r=${UNAME_r}" PBUILD_FLAGS="${PBUILD_FLAGS} OSREL=${REVISION}" PBUILD_FLAGS="${PBUILD_FLAGS} WRKDIRPREFIX=/tmp/ports" PBUILD_FLAGS="${PBUILD_FLAGS} DISTDIR=/tmp/distfiles" eval chroot ${CHROOTDIR} env OPTIONS_UNSET=\"${GITUNSETOPTS}\" \ ${PBUILD_FLAGS} \ make -C /usr/ports/devel/git FORCE_PKG_REGISTER=1 \ WRKDIRPREFIX=/tmp/ports \ DISTDIR=/tmp/distfiles \ install clean distclean else eval chroot ${CHROOTDIR} env ASSUME_ALWAYS_YES=yes \ pkg install -y devel/git eval chroot ${CHROOTDIR} env ASSUME_ALWAYS_YES=yes \ pkg clean -y fi fi - if [ ! -z "${EMBEDDEDPORTS}" ]; then + if [ -n "${EMBEDDEDPORTS}" ]; then _OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U) REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION) BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH) UNAME_r=${REVISION}-${BRANCH} PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes" PBUILD_FLAGS="${PBUILD_FLAGS} UNAME_r=${UNAME_r}" PBUILD_FLAGS="${PBUILD_FLAGS} OSREL=${REVISION}" PBUILD_FLAGS="${PBUILD_FLAGS} WRKDIRPREFIX=/tmp/ports" PBUILD_FLAGS="${PBUILD_FLAGS} DISTDIR=/tmp/distfiles" for _PORT in ${EMBEDDEDPORTS}; do eval chroot ${CHROOTDIR} env ${PBUILD_FLAGS} make -C \ /usr/ports/${_PORT} \ FORCE_PKG_REGISTER=1 deinstall install clean distclean done fi buildenv_setup return 0 } # extra_chroot_setup() # chroot_build_target(): Build the userland and kernel for the build target. chroot_build_target() { load_target_env - if [ ! -z "${EMBEDDEDBUILD}" ]; then + if [ -n "${EMBEDDEDBUILD}" ]; then RELEASE_WMAKEFLAGS="${RELEASE_WMAKEFLAGS} \ TARGET=${EMBEDDED_TARGET} \ TARGET_ARCH=${EMBEDDED_TARGET_ARCH}" RELEASE_KMAKEFLAGS="${RELEASE_KMAKEFLAGS} \ TARGET=${EMBEDDED_TARGET} \ TARGET_ARCH=${EMBEDDED_TARGET_ARCH}" fi eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel - if [ ! -z "${WITH_OCIIMAGES}" ]; then + if [ -n "${WITH_OCIIMAGES}" ]; then eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} packages fi return 0 } # chroot_build_target # chroot_build_release(): Invoke the 'make release' target. chroot_build_release() { load_target_env - if [ ! -z "${WITH_VMIMAGES}" ]; then + if [ -n "${WITH_VMIMAGES}" ]; then if [ -z "${VMFORMATS}" ]; then VMFORMATS="$(eval chroot ${CHROOTDIR} \ make -C /usr/src/release -V VMFORMATS)" fi if [ -z "${VMSIZE}" ]; then VMSIZE="$(eval chroot ${CHROOTDIR} \ make -C /usr/src/release ${ARCH_FLAGS} -V VMSIZE)" fi RELEASE_RMAKEFLAGS="${RELEASE_RMAKEFLAGS} \ VMFORMATS=\"${VMFORMATS}\" VMSIZE=${VMSIZE}" fi eval chroot ${CHROOTDIR} make -C /usr/src/release \ ${RELEASE_RMAKEFLAGS} release eval chroot ${CHROOTDIR} make -C /usr/src/release \ ${RELEASE_RMAKEFLAGS} install DESTDIR=/R \ WITH_COMPRESSED_IMAGES=${WITH_COMPRESSED_IMAGES} \ WITH_COMPRESSED_VMIMAGES=${WITH_COMPRESSED_VMIMAGES} return 0 } # chroot_build_release() efi_boot_name() { case $1 in arm) echo "bootarm.efi" ;; arm64) echo "bootaa64.efi" ;; amd64) echo "bootx64.efi" ;; riscv) echo "bootriscv64.efi" ;; esac } # chroot_arm_build_release(): Create arm SD card image. chroot_arm_build_release() { load_target_env case ${EMBEDDED_TARGET} in arm|arm64|riscv) if [ -e "${RELENGDIR}/tools/arm.subr" ]; then . "${RELENGDIR}/tools/arm.subr" fi ;; *) ;; esac - [ ! -z "${RELEASECONF}" ] && . "${RELEASECONF}" + [ -n "${RELEASECONF}" ] && . "${RELEASECONF}" export MAKE_FLAGS="${MAKE_FLAGS} TARGET=${EMBEDDED_TARGET}" export MAKE_FLAGS="${MAKE_FLAGS} TARGET_ARCH=${EMBEDDED_TARGET_ARCH}" export MAKE_FLAGS="${MAKE_FLAGS} ${CONF_FILES}" eval chroot ${CHROOTDIR} env WITH_UNIFIED_OBJDIR=1 make ${MAKE_FLAGS} -C /usr/src/release obj export WORLDDIR="$(eval chroot ${CHROOTDIR} make ${MAKE_FLAGS} -C /usr/src/release -V WORLDDIR)" export OBJDIR="$(eval chroot ${CHROOTDIR} env WITH_UNIFIED_OBJDIR=1 make ${MAKE_FLAGS} -C /usr/src/release -V .OBJDIR)" export DESTDIR="${OBJDIR}/${KERNEL}" export IMGBASE="${CHROOTDIR}/${OBJDIR}/${BOARDNAME}.img" export OSRELEASE="$(eval chroot ${CHROOTDIR} make ${MAKE_FLAGS} -C /usr/src/release \ TARGET=${EMBEDDED_TARGET} TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \ -V OSRELEASE)" chroot ${CHROOTDIR} mkdir -p ${DESTDIR} chroot ${CHROOTDIR} truncate -s ${IMAGE_SIZE} ${IMGBASE##${CHROOTDIR}} export mddev=$(chroot ${CHROOTDIR} \ mdconfig -f ${IMGBASE##${CHROOTDIR}} ${MD_ARGS}) arm_create_disk arm_install_base arm_install_boot arm_install_uboot mdconfig -d -u ${mddev} chroot ${CHROOTDIR} rmdir ${DESTDIR} mv ${IMGBASE} ${CHROOTDIR}/${OBJDIR}/${OSRELEASE}-${BOARDNAME}.img chroot ${CHROOTDIR} mkdir -p /R chroot ${CHROOTDIR} cp -p ${OBJDIR}/${OSRELEASE}-${BOARDNAME}.img \ /R/${OSRELEASE}-${BOARDNAME}.img chroot ${CHROOTDIR} xz -T ${XZ_THREADS} /R/${OSRELEASE}-${BOARDNAME}.img cd ${CHROOTDIR}/R && sha512 ${OSRELEASE}* \ > CHECKSUM.SHA512 cd ${CHROOTDIR}/R && sha256 ${OSRELEASE}* \ > CHECKSUM.SHA256 return 0 } # chroot_arm_build_release() # main(): Start here. main() { set -e # Everything must succeed env_setup while getopts c: opt; do case ${opt} in c) RELEASECONF="$(realpath ${OPTARG})" ;; \?) usage ;; esac done shift $(($OPTIND - 1)) - if [ ! -z "${RELEASECONF}" ]; then + if [ -n "${RELEASECONF}" ]; then if [ -e "${RELEASECONF}" ]; then . ${RELEASECONF} else echo "Nonexistent configuration file: ${RELEASECONF}" echo "Using default build environment." fi fi env_check trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit chroot_setup extra_chroot_setup chroot_build_target ${chroot_build_release_cmd} return 0 } # main() main "${@}" diff --git a/release/scripts/atlas-upload.sh b/release/scripts/atlas-upload.sh index 6fa1a6a2e9d4..b10588501886 100755 --- a/release/scripts/atlas-upload.sh +++ b/release/scripts/atlas-upload.sh @@ -1,158 +1,158 @@ #!/bin/sh #- # 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. # # Upload a Vagrant image to Hashicorp's Atlas service # # ATLAS_API_URL='' ATLAS_UPLOAD_URL='https://app.vagrantup.com' DESCRIPTION="FreeBSD Snapshot Build" usage() { echo "${0} usage:" echo "-b box-name -d 'box description' -f box-to-upload -k api-key -p provider -u user -v version" return 1 } main () { while getopts "b:d:f:k:p:u:v:" arg; do case "${arg}" in b) BOX="${OPTARG}" ;; d) DESCRIPTION="${OPTARG}" ;; f) FILE="${OPTARG}" ;; k) KEY="${OPTARG}" ;; p) PROVIDER="${OPTARG}" ;; u) USERNAME="${OPTARG}" ;; v) VERSION="${OPTARG}" ;; *) ;; esac done if [ -z "${BOX}" -o \ -z "${FILE}" -o \ -z "${KEY}" -o \ -z "${PROVIDER}" -o \ -z "${USERNAME}" -o \ -z "${VERSION}" ]; then usage || exit 0 fi # Check to see if the box exists or create it BOXRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}") if [ $? != 0 ]; then echo "Failed to connect to the API" exit 2; fi echo $BOXRESULT | grep "\"name\":\"${BOX}\"" > /dev/null if [ $? != 0 ]; then echo "Creating box: ${BOX}" /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null else echo "Box already exists" fi # Check to see if the version exists or create it VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}") if [ $? != 0 ]; then echo "Failed to connect to the API" exit 2; fi echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null if [ $? != 0 ]; then echo "Creating version: ${VERSION}" /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}") echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null if [ $? != 0 ]; then echo "Failed to create version" exit 2 fi else echo "Version already exists" fi # Check to see if the provider exists or create it PROVIDERRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}") if [ $? != 0 ]; then echo "Failed to connect to the API" exit 2; fi echo $PROVIDERRESULT | grep "provider/${PROVIDER}" > /dev/null if [ $? != 0 ]; then echo "Creating provider: ${PROVIDER}" /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null else echo "Provider already exists" fi # Request an upload token TOKENRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}") if [ $? != 0 ]; then echo "Failed to get the token from the API" exit 2; fi echo ${TOKENRESULT} | grep -E "upload_path" > /dev/null if [ $? != 0 ]; then echo "No token found from the API" exit 2 else TOKEN=$(echo $TOKENRESULT | sed -e 's/.*token":"//' -e 's/.*upload_path":"//' -e 's/}$//g' -e 's/"//g') echo "Uploading to Atlas" UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} "${TOKEN}") # Validate the Upload echo "Validating" VALIDRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}") HOSTED_TOKEN=$(echo $VALIDRESULT | sed -e 's/.*"hosted"://' -e 's/,.*$//') - if [ ! -z ${TOKEN} -a "${HOSTED_TOKEN}" != "true" ]; then + if [ -n ${TOKEN} -a "${HOSTED_TOKEN}" != "true" ]; then echo "Upload failed, try again." exit 2 fi # Release the version echo "Releasing ${VERSION} of ${BOX} in Atlas" /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null fi } main "$@" diff --git a/release/scripts/mk-vmimage.sh b/release/scripts/mk-vmimage.sh index dfd91f43140d..3ca369b04d8e 100755 --- a/release/scripts/mk-vmimage.sh +++ b/release/scripts/mk-vmimage.sh @@ -1,115 +1,115 @@ #!/bin/sh #- # Copyright (c) 2014, 2015 The FreeBSD Foundation # # This software was developed by Glen Barber 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. # # mk-vmimage.sh: Create virtual machine disk images in various formats. # # usage() { echo "${0} usage:" echo "${@}" return 1 } main() { local arg VMCONFIG="/dev/null" while getopts "C:c:d:F:f:i:o:s:S:" arg; do case "${arg}" in C) VMBUILDCONF="${OPTARG}" ;; c) VMCONFIG="${OPTARG}" ;; d) DESTDIR="${OPTARG}" ;; F) VMFS="${OPTARG}" ;; f) VMFORMAT="${OPTARG}" ;; i) VMBASE="${OPTARG}" ;; o) VMIMAGE="${OPTARG}" ;; s) VMSIZE="${OPTARG}" ;; S) WORLDDIR="${OPTARG}" ;; *) ;; esac done shift $(( ${OPTIND} - 1)) if [ -z "${VMBASE}" -o \ -z "${WORLDDIR}" -o \ -z "${DESTDIR}" -o \ -z "${VMSIZE}" -o \ -z "${VMIMAGE}" -o \ -z "${VMFS}" ]; then usage || exit 0 fi if [ -z "${VMBUILDCONF}" ] || [ ! -e "${VMBUILDCONF}" ]; then echo "Must provide the path to vmimage.subr." return 1 fi . "${VMBUILDCONF}" - if [ ! -z "${VMCONFIG}" ] && [ ! -c "${VMCONFIG}" ]; then + if [ -n "${VMCONFIG}" ] && [ ! -c "${VMCONFIG}" ]; then . "${VMCONFIG}" fi vm_create_base vm_install_base vm_emulation_setup vm_extra_install_base vm_extra_install_packages vm_extra_install_ports vm_extra_enable_services vm_extra_pre_umount vm_extra_pkg_rmcache vm_emulation_cleanup vm_copy_base vm_create_disk || return 0 vm_extra_create_disk return 0 } main "$@" diff --git a/release/scripts/pkg-stage.sh b/release/scripts/pkg-stage.sh index 58b6d25fcccf..9f121e5ab011 100755 --- a/release/scripts/pkg-stage.sh +++ b/release/scripts/pkg-stage.sh @@ -1,94 +1,94 @@ #!/bin/sh # # set -e export ASSUME_ALWAYS_YES="YES" export PKG_DBDIR="/tmp/pkg" export PERMISSIVE="YES" export REPO_AUTOUPDATE="NO" export ROOTDIR="$PWD/dvd" export PKGCMD="/usr/sbin/pkg -d --rootdir ${ROOTDIR}" export PORTSDIR="${PORTSDIR:-/usr/ports}" _DVD_PACKAGES="devel/git@lite graphics/drm-kmod graphics/drm-510-kmod graphics/drm-515-kmod misc/freebsd-doc-all net/mpd5 net/rsync net/wifi-firmware-kmod@release ports-mgmt/pkg shells/bash shells/zsh security/sudo@default sysutils/screen sysutils/seatd sysutils/tmux www/firefox www/links x11/gnome x11/kde x11/sddm x11/xorg x11-wm/sway" # If NOPORTS is set for the release, do not attempt to build pkg(8). if [ ! -f ${PORTSDIR}/Makefile ]; then echo "*** ${PORTSDIR} is missing! ***" echo "*** Skipping pkg-stage.sh ***" echo "*** Unset NOPORTS to fix this ***" exit 0 fi if [ ! -x /usr/local/sbin/pkg ]; then /etc/rc.d/ldconfig restart /usr/bin/make -C ${PORTSDIR}/ports-mgmt/pkg install clean fi export PKG_ABI=$(pkg --rootdir ${ROOTDIR} config ABI) export PKG_ALTABI=$(pkg --rootdir ${ROOTDIR} config ALTABI 2>/dev/null) export PKG_REPODIR="packages/${PKG_ABI}" /bin/mkdir -p ${ROOTDIR}/${PKG_REPODIR} -if [ ! -z "${PKG_ALTABI}" ]; then +if [ -n "${PKG_ALTABI}" ]; then ln -s ${PKG_ABI} ${ROOTDIR}/packages/${PKG_ALTABI} fi # Ensure the ports listed in _DVD_PACKAGES exist to sanitize the # final list. for _P in ${_DVD_PACKAGES}; do if [ -d "${PORTSDIR}/${_P%%@*}" ]; then DVD_PACKAGES="${DVD_PACKAGES} ${_P}" else echo "*** Skipping nonexistent port: ${_P%%@*}" fi done # Make sure the package list is not empty. if [ -z "${DVD_PACKAGES}" ]; then echo "*** The package list is empty." echo "*** Something is very wrong." # Exit '0' so the rest of the build process continues # so other issues (if any) can be addressed as well. exit 0 fi # Print pkg(8) information to make debugging easier. ${PKGCMD} -vv ${PKGCMD} update -f ${PKGCMD} fetch -o ${PKG_REPODIR} -d ${DVD_PACKAGES} # Create the 'Latest/pkg.txz' symlink so 'pkg bootstrap' works # using the on-disc packages. export LATEST_DIR="${ROOTDIR}/${PKG_REPODIR}/Latest" mkdir -p ${LATEST_DIR} ln -s ../All/$(${PKGCMD} rquery %n-%v pkg).pkg ${LATEST_DIR}/pkg.pkg ln -sf pkg.pkg ${LATEST_DIR}/pkg.txz ${PKGCMD} repo ${PKG_REPODIR} # Always exit '0', even if pkg(8) complains about conflicts. exit 0 diff --git a/release/tools/arm.subr b/release/tools/arm.subr index 983c3ea75dc7..5c5ebd29681d 100644 --- a/release/tools/arm.subr +++ b/release/tools/arm.subr @@ -1,282 +1,282 @@ #!/bin/sh #- # Copyright (c) 2015-2017 The FreeBSD Foundation # # Portions of this software were developed by Glen Barber # 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. # # Common subroutines used to build arm, arm64, or RISC-V SD card images. # # cleanup() { if [ -c "${DESTDIR}/dev/null" ]; then umount_loop ${DESTDIR}/dev 2>/dev/null fi umount_loop ${DESTDIR} - if [ ! -z "${mddev}" ]; then + if [ -n "${mddev}" ]; then mdconfig -d -u ${mddev} fi return 0 } umount_loop() { DIR=$1 i=0 sync while ! umount ${DIR}; do i=$(( $i + 1 )) if [ $i -ge 10 ]; then # This should never happen. But, it has happened. echo "Cannot umount(8) ${DIR}" echo "Something has gone horribly wrong." return 1 fi sleep 1 done return 0 } arm_create_disk() { if [ $(sysctl -n kern.geom.part.mbr.enforce_chs) != 0 ]; then return 1 fi # Create the target raw file and temporary work directory. chroot ${CHROOTDIR} gpart create -s ${PART_SCHEME} ${mddev} arm_create_partitions if [ "${PART_SCHEME}" = "GPT" ]; then chroot ${CHROOTDIR} gpart add -t efi -l efi -a 512k -s ${FAT_SIZE} ${mddev} chroot ${CHROOTDIR} gpart add -t freebsd-ufs -l rootfs -a 64k ${mddev} fi if [ "${PART_SCHEME}" = "MBR" ]; then chroot ${CHROOTDIR} gpart add -t '!12' -a 512k -s ${FAT_SIZE} ${mddev} chroot ${CHROOTDIR} gpart set -a active -i 1 ${mddev} chroot ${CHROOTDIR} gpart add -t freebsd ${mddev} chroot ${CHROOTDIR} gpart create -s bsd ${mddev}${BSDLABEL_SUFFIX} chroot ${CHROOTDIR} gpart add -t freebsd-ufs -a 64k -b 64k ${mddev}${BSDLABEL_SUFFIX} fi # Create the EFI and UFS filesystems chroot ${CHROOTDIR} newfs_msdos -L efi -F ${FAT_TYPE} /dev/${mddev}${EFIPART_SUFFIX} chroot ${CHROOTDIR} newfs -U -L rootfs /dev/${mddev}${ROOTFSPART_SUFFIX} return 0 } arm_create_user() { # Create a default user account 'freebsd' with the password 'freebsd', # and set the default password for the 'root' user to 'root'. chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \ groupadd freebsd -g 1001 chroot ${CHROOTDIR} mkdir -p ${DESTDIR}/home/freebsd chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \ useradd freebsd \ -m -M 0755 -w yes -n freebsd -u 1001 -g 1001 -G 0 \ -c 'FreeBSD User' -d '/home/freebsd' -s '/bin/csh' chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \ usermod root -w yes return 0 } arm_setup_usb_otg() { # Set up virtual serial port over USB OTG / device mode. echo >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo '# Required for USB OTG virtual serial port.' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo 'notify 100 {' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo ' match "system" "DEVFS";' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo ' match "subsystem" "CDEV";' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo ' match "type" "CREATE";' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo ' match "cdev" "ttyU[0-9]+";' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo ' action "/sbin/init q";' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo '};' \ >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf echo '# USB OTG virtual serial port' \ >> ${CHROOTDIR}/${DESTDIR}/etc/ttys echo 'ttyU0 "/usr/libexec/getty 3wire" vt100 onifconsole secure' \ >> ${CHROOTDIR}/${DESTDIR}/etc/ttys echo 'ttyU1 "/usr/libexec/getty 3wire" vt100 onifconsole secure' \ >> ${CHROOTDIR}/${DESTDIR}/etc/ttys echo '# Configure USB OTG; see usb_template(4).' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'hw.usb.template=3' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'umodem_load="YES"' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf } arm64_setup_multicons() { if [ "${EMBEDDED_TARGET_ARCH}" != "aarch64" ]; then return fi echo '# Multiple console (serial+efi gop) enabled.' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'boot_multicons="YES"' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'boot_serial="YES"' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf } arm_setup_fdt_overlays() { if [ -z "${FDT_OVERLAYS}" ]; then return fi echo '# DTB OVERLAYS' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo "fdt_overlays=\"${FDT_OVERLAYS}\"" \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf } arm_setup_minimal_loader() { echo '# Disable the beastie menu and color' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'beastie_disable="YES"' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf echo 'loader_color="NO"' \ >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf } arm_install_base() { chroot ${CHROOTDIR} mount /dev/${mddev}${ROOTFSPART_SUFFIX} ${DESTDIR} _OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U) REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION) BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH) export UNAME_r=${REVISION}-${BRANCH} eval chroot ${CHROOTDIR} make -C ${WORLDDIR} \ TARGET=${EMBEDDED_TARGET} \ TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \ DESTDIR=${DESTDIR} KERNCONF=${KERNEL} \ ${CONF_FILES} installworld installkernel distribution chroot ${CHROOTDIR} mkdir -p ${DESTDIR}/boot/efi # Compatibility symlink to /boot/msdos for 13.1 and earlier chroot ${CHROOTDIR} ln -s efi ${DESTDIR}/boot/msdos arm_create_user arm_setup_usb_otg arm64_setup_multicons arm_setup_fdt_overlays arm_setup_minimal_loader arm_do_quirk echo '# Custom /etc/fstab for FreeBSD embedded images' \ > ${CHROOTDIR}/${DESTDIR}/etc/fstab echo "/dev/ufs/rootfs / ufs rw 1 1" \ >> ${CHROOTDIR}/${DESTDIR}/etc/fstab echo "/dev/msdosfs/EFI /boot/efi msdosfs rw,noatime 0 0" \ >> ${CHROOTDIR}/${DESTDIR}/etc/fstab echo "tmpfs /tmp tmpfs rw,mode=1777 0 0" \ >> ${CHROOTDIR}/${DESTDIR}/etc/fstab local hostname hostname="$(echo ${KERNEL} | tr '[:upper:]' '[:lower:]')" echo "hostname=\"${hostname}\"" > ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'ifconfig_DEFAULT="DHCP inet6 accept_rtadv"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'sshd_enable="YES"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'sendmail_enable="NONE"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'sendmail_submit_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'sendmail_outbound_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'sendmail_msp_queue_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf echo 'growfs_enable="YES"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf if [ -n "${CONFIG_POWERD_ENABLE}" ]; then echo 'powerd_enable="YES"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf fi sync umount_loop ${CHROOTDIR}/${DESTDIR} return 0 } arm_install_boot() { FATMOUNT="${DESTDIR%${KERNEL}}/fat" UFSMOUNT="${DESTDIR%${KERNEL}}/ufs" chroot ${CHROOTDIR} mkdir -p "${FATMOUNT}" "${UFSMOUNT}" dospart="/dev/${mddev}${EFIPART_SUFFIX}" ufspart="/dev/${mddev}${ROOTFSPART_SUFFIX}" chroot ${CHROOTDIR} mount_msdosfs ${dospart} ${FATMOUNT} chroot ${CHROOTDIR} mount ${ufspart} ${UFSMOUNT} BOOTFILES="$(chroot ${CHROOTDIR} \ env TARGET=${EMBEDDED_TARGET} TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \ WITH_UNIFIED_OBJDIR=yes \ make -C ${WORLDDIR}/stand -V .OBJDIR)" BOOTFILES="$(chroot ${CHROOTDIR} realpath ${BOOTFILES})" chroot ${CHROOTDIR} mkdir -p ${FATMOUNT}/EFI/BOOT chroot ${CHROOTDIR} cp -p ${BOOTFILES}/efi/loader_lua/loader_lua.efi \ ${FATMOUNT}/EFI/BOOT/$(efi_boot_name ${EMBEDDED_TARGET}) chroot ${CHROOTDIR} cp -R ${UFSMOUNT}/boot/dtb ${FATMOUNT} chroot ${CHROOTDIR} touch ${UFSMOUNT}/firstboot sync umount_loop ${CHROOTDIR}/${FATMOUNT} umount_loop ${CHROOTDIR}/${UFSMOUNT} chroot ${CHROOTDIR} rmdir ${FATMOUNT} chroot ${CHROOTDIR} rmdir ${UFSMOUNT} } arm_install_uboot() { # Override in the ${EMBEDDED_TARGET}/${BOARDNAME}.conf file. return 0 } arm_do_quirk() { # Override in the ${EMBEDDED_TARGET}/${BOARDNAME}.conf file. } arm_create_partitions() { # Override in the ${EMBEDDED_TARGET}/${BOARDNAME}.conf file. # Set defaults for EFIPART_SUFFIX, ROOTFSPART_SUFFIX, and # BSDLABEL_SUFFIX (MBR only), needed elsewhere. if [ "${PART_SCHEME}" = "GPT" ]; then export EFIPART_SUFFIX=p1 export ROOTFSPART_SUFFIX=p2 fi if [ "${PART_SCHEME}" = "MBR" ]; then export EFIPART_SUFFIX=s1 export BSDLABEL_SUFFIX=s2 export ROOTFSPART_SUFFIX=s2a fi } diff --git a/release/tools/gce.conf b/release/tools/gce.conf index 5ad83bcded53..fc72b381a02d 100644 --- a/release/tools/gce.conf +++ b/release/tools/gce.conf @@ -1,132 +1,132 @@ #!/bin/sh # # # The default of 3GB is too small for GCE, so override the size here. export VMSIZE=20g # Set to a list of packages to install. export VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} firstboot-freebsd-update \ firstboot-pkgs google-cloud-sdk panicmail sudo \ sysutils/py-google-compute-engine lang/python \ lang/python3" # Set to a list of third-party software to enable in rc.conf(5). export VM_RC_LIST="ntpd sshd growfs \ firstboot_pkgs firstboot_freebsd_update google_startup \ google_accounts_daemon google_clock_skew_daemon \ google_instance_setup google_network_daemon" vm_extra_install_base() { echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf } vm_extra_pre_umount() { # Enable growfs on every boot, not only the first, as as instance's disk can # be enlarged post-creation sed -i -e '/KEYWORD: firstboot/d' /etc/rc.d/growfs cat << EOF >> ${DESTDIR}/etc/rc.conf dumpdev="AUTO" ifconfig_DEFAULT="SYNCDHCP mtu 1460" ntpd_sync_on_start="YES" # need to fill in something here #firstboot_pkgs_list="" panicmail_autosubmit="YES" EOF cat << EOF >> ${DESTDIR}/boot/loader.conf autoboot_delay="-1" beastie_disable="YES" loader_logo="none" hw.memtest.tests="0" console="comconsole,vidconsole" hw.vtnet.mq_disable=1 kern.timecounter.hardware=ACPI-safe aesni_load="YES" nvme_load="YES" EOF echo '169.254.169.254 metadata.google.internal metadata' >> \ ${DESTDIR}/etc/hosts # overwrite ntp.conf cat << EOF > ${DESTDIR}/etc/ntp.conf server metadata.google.internal iburst restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1 restrict 127.127.1.0 EOF cat << EOF >> ${DESTDIR}/etc/syslog.conf *.err;kern.warning;auth.notice;mail.crit /dev/console EOF cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config KbdInteractiveAuthentication no X11Forwarding no AcceptEnv LANG AllowAgentForwarding no ClientAliveInterval 420 EOF cat << EOF >> ${DESTDIR}/etc/crontab 0 3 * * * root /usr/sbin/freebsd-update cron EOF cat << EOF >> ${DESTDIR}/etc/sysctl.conf net.inet.icmp.drop_redirect=1 net.inet.ip.redirect=0 kern.ipc.soacceptqueue=1024 debug.trace_on_panic=1 debug.debugger_on_panic=0 EOF # To meet GCE marketplace requirements, extract the src.txz and # ports.txz distributions to the target virtual machine disk image # and fetch the sources for the third-party software installed on # the image. if [ ! -c "${DESTDIR}/dev/null" ]; then mkdir -p ${DESTDIR}/dev mount -t devfs devfs ${DESTDIR}/dev fi if [ -e "${DESTDIR}/../ftp/src.txz" ]; then tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR} fi if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR} _INSTALLED_PACKAGES=$(chroot ${DESTDIR} pkg info -o -q -a) for PACKAGE in ${_INSTALLED_PACKAGES}; do chroot ${DESTDIR} \ make -C /usr/ports/${PACKAGE} fetch done fi if [ -c "${DESTDIR}/dev/null" ]; then umount_loop ${DESTDIR}/dev fi ## XXX: Verify this is needed. I do not see this requirement ## in the docs, and it impairs the ability to boot-test a copy ## of the image prior to packaging for upload to GCE. #sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys touch ${DESTDIR}/firstboot return 0 } # Do everything except deleting resolv.conf since we construct our own # Googlized resolv.conf file in vm_extra_install_base. vm_emulation_cleanup() { - if ! [ -z "${QEMUSTATIC}" ]; then + if [ -n "${QEMUSTATIC}" ]; then rm -f ${DESTDIR}/${EMULATOR} fi umount_loop ${DESTDIR}/dev return 0 } diff --git a/release/tools/vmimage.subr b/release/tools/vmimage.subr index 9b8813e6dc4a..ce0ea03c096c 100644 --- a/release/tools/vmimage.subr +++ b/release/tools/vmimage.subr @@ -1,369 +1,369 @@ #!/bin/sh # # # # Common functions for virtual machine image build scripts. # scriptdir=$(dirname $(realpath $0)) . ${scriptdir}/../../tools/boot/install-boot.sh export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin" trap "cleanup" INT QUIT TRAP ABRT TERM # Platform-specific large-scale setup # Most platforms use GPT, so put that as default, then special cases PARTSCHEME=gpt ROOTLABEL="gpt" case "${TARGET}:${TARGET_ARCH}" in powerpc:powerpc*) PARTSCHEME=mbr ROOTLABEL="ufs" NOSWAP=yes # Can't label swap partition with MBR, so no swap ;; esac err() { printf "${@}\n" cleanup return 1 } cleanup() { if [ -c "${DESTDIR}/dev/null" ]; then umount_loop ${DESTDIR}/dev 2>/dev/null fi return 0 } metalog_add_data() { if [ -n "${NO_ROOT}" ]; then echo "$1 type=file uname=root gname=wheel mode=0644" >> \ ${DESTDIR}/METALOG fi } vm_create_base() { mkdir -p ${DESTDIR} return 0 } vm_copy_base() { # Defunct return 0 } vm_install_base() { # Installs the FreeBSD userland/kernel to the virtual machine disk. cd ${WORLDDIR} && \ make DESTDIR=${DESTDIR} ${INSTALLOPTS} \ installworld installkernel distribution || \ err "\n\nCannot install the base system to ${DESTDIR}." # Bootstrap etcupdate(8) database. mkdir -p ${DESTDIR}/var/db/etcupdate etcupdate extract -B \ -M "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ -s ${WORLDDIR} -d ${DESTDIR}/var/db/etcupdate \ -L /dev/stdout ${NO_ROOT:+-N} if [ -n "${NO_ROOT}" ]; then # Reroot etcupdate's internal METALOG to the whole tree sed -n 's,^\.,./var/db/etcupdate/current,p' \ ${DESTDIR}/var/db/etcupdate/current/METALOG | \ env -i LC_COLLATE=C sort >> ${DESTDIR}/METALOG rm ${DESTDIR}/var/db/etcupdate/current/METALOG fi echo '# Custom /etc/fstab for FreeBSD VM images' \ > ${DESTDIR}/etc/fstab if [ "${VMFS}" != zfs ]; then echo "/dev/${ROOTLABEL}/rootfs / ${VMFS} rw 1 1" \ >> ${DESTDIR}/etc/fstab fi if [ -z "${NOSWAP}" ]; then echo '/dev/gpt/swapfs none swap sw 0 0' \ >> ${DESTDIR}/etc/fstab fi metalog_add_data ./etc/fstab local hostname hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')" echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf metalog_add_data ./etc/rc.conf if [ "${VMFS}" = zfs ]; then echo "zfs_enable=\"YES\"" >> ${DESTDIR}/etc/rc.conf echo "zpool_reguid=\"zroot\"" >> ${DESTDIR}/etc/rc.conf echo "zpool_upgrade=\"zroot\"" >> ${DESTDIR}/etc/rc.conf echo "kern.geom.label.disk_ident.enable=0" >> ${DESTDIR}/boot/loader.conf echo "zfs_load=YES" >> ${DESTDIR}/boot/loader.conf metalog_add_data ./boot/loader.conf fi return 0 } vm_emulation_setup() { if [ -n "${WITHOUT_QEMU}" ]; then return 0 fi - if ! [ -z "${QEMUSTATIC}" ]; then + if [ -n "${QEMUSTATIC}" ]; then export EMULATOR=/qemu cp ${QEMUSTATIC} ${DESTDIR}/${EMULATOR} fi mkdir -p ${DESTDIR}/dev mount -t devfs devfs ${DESTDIR}/dev chroot ${DESTDIR} ${EMULATOR} /usr/bin/newaliases chroot ${DESTDIR} ${EMULATOR} /bin/sh /etc/rc.d/ldconfig forcestart cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf return 0 } vm_extra_install_base() { # Prototype. When overridden, runs extra post-installworld commands # as needed, based on the target virtual machine image or cloud # provider image target. return 0 } vm_extra_enable_services() { - if [ ! -z "${VM_RC_LIST}" ]; then + if [ -n "${VM_RC_LIST}" ]; then for _rcvar in ${VM_RC_LIST}; do echo ${_rcvar}_enable="YES" >> ${DESTDIR}/etc/rc.conf done fi if [ -z "${VMCONFIG}" -o -c "${VMCONFIG}" ]; then echo 'ifconfig_DEFAULT="DHCP inet6 accept_rtadv"' >> \ ${DESTDIR}/etc/rc.conf # Expand the filesystem to fill the disk. echo 'growfs_enable="YES"' >> ${DESTDIR}/etc/rc.conf touch ${DESTDIR}/firstboot fi return 0 } vm_extra_install_packages() { if [ -n "${WITHOUT_QEMU}" ]; then return 0 fi if [ -z "${VM_EXTRA_PACKAGES}" ]; then return 0 fi chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \ /usr/sbin/pkg bootstrap -y for p in ${VM_EXTRA_PACKAGES}; do chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \ /usr/sbin/pkg install -y ${p} done return 0 } vm_extra_install_ports() { # Prototype. When overridden, installs additional ports within the # virtual machine environment. return 0 } vm_extra_pre_umount() { # Prototype. When overridden, performs additional tasks within the # virtual machine environment prior to unmounting the filesystem. return 0 } vm_emulation_cleanup() { if [ -n "${WITHOUT_QEMU}" ]; then return 0 fi if ! [ -z "${QEMUSTATIC}" ]; then rm -f ${DESTDIR}/${EMULATOR} fi rm -f ${DESTDIR}/etc/resolv.conf umount_loop ${DESTDIR}/dev return 0 } vm_extra_pkg_rmcache() { if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \ /usr/local/sbin/pkg clean -y -a fi return 0 } buildfs() { local md tmppool case "${VMFS}" in ufs) cd ${DESTDIR} && makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \ ${VMBASE} .${NO_ROOT:+/METALOG} ;; zfs) cd ${DESTDIR} && makefs -t zfs ${MAKEFSARGS} \ -o poolname=zroot -o bootfs=zroot/ROOT/default -o rootpath=/ \ -o fs=zroot\;mountpoint=none \ -o fs=zroot/ROOT\;mountpoint=none \ -o fs=zroot/ROOT/default\;mountpoint=/\;canmount=noauto \ -o fs=zroot/home\;mountpoint=/home \ -o fs=zroot/tmp\;mountpoint=/tmp\;exec=on\;setuid=off \ -o fs=zroot/usr\;mountpoint=/usr\;canmount=off \ -o fs=zroot/usr/ports\;setuid=off \ -o fs=zroot/usr/src \ -o fs=zroot/usr/obj \ -o fs=zroot/var\;mountpoint=/var\;canmount=off \ -o fs=zroot/var/audit\;setuid=off\;exec=off \ -o fs=zroot/var/crash\;setuid=off\;exec=off \ -o fs=zroot/var/log\;setuid=off\;exec=off \ -o fs=zroot/var/mail\;atime=on \ -o fs=zroot/var/tmp\;setuid=off \ ${VMBASE} .${NO_ROOT:+/METALOG} ;; *) echo "Unexpected VMFS value '${VMFS}'" exit 1 ;; esac } umount_loop() { DIR=$1 i=0 sync while ! umount ${DIR}; do i=$(( $i + 1 )) if [ $i -ge 10 ]; then # This should never happen. But, it has happened. echo "Cannot umount(8) ${DIR}" echo "Something has gone horribly wrong." return 1 fi sleep 1 done return 0 } vm_create_disk() { local BOOTFILES BOOTPARTSOFFSET FSPARTTYPE X86GPTBOOTFILE if [ -z "${NOSWAP}" ]; then SWAPOPT="-p freebsd-swap/swapfs::${SWAPSIZE}" fi if [ -n "${VM_BOOTPARTSOFFSET}" ]; then BOOTPARTSOFFSET=":${VM_BOOTPARTSOFFSET}" fi if [ -n "${CONFIG_DRIVE}" ]; then CONFIG_DRIVE="-p freebsd/config-drive::${CONFIG_DRIVE_SIZE}" fi case "${VMFS}" in ufs) FSPARTTYPE=freebsd-ufs X86GPTBOOTFILE=i386/gptboot/gptboot ;; zfs) FSPARTTYPE=freebsd-zfs X86GPTBOOTFILE=i386/gptzfsboot/gptzfsboot ;; *) echo "Unexpected VMFS value '${VMFS}'" return 1 ;; esac echo "Creating image... Please wait." echo BOOTFILES="$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ WITH_UNIFIED_OBJDIR=yes \ make -C ${WORLDDIR}/stand -V .OBJDIR)" BOOTFILES="$(realpath ${BOOTFILES})" MAKEFSARGS="-s ${VMSIZE} -D" case "${TARGET}:${TARGET_ARCH}" in amd64:amd64 | i386:i386) ESP=yes BOOTPARTS="-b ${BOOTFILES}/i386/pmbr/pmbr \ -p freebsd-boot/bootfs:=${BOOTFILES}/${X86GPTBOOTFILE}${BOOTPARTSOFFSET}" ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}" MAKEFSARGS="$MAKEFSARGS -B little" ;; arm:armv7 | arm64:aarch64 | riscv:riscv64*) ESP=yes BOOTPARTS= ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}" MAKEFSARGS="$MAKEFSARGS -B little" ;; powerpc:powerpc*) ESP=no BOOTPARTS="-p prepboot:=${BOOTFILES}/powerpc/boot1.chrp/boot1.elf -a 1" ROOTFSPART="-p freebsd:=${VMBASE}" if [ ${TARGET_ARCH} = powerpc64le ]; then MAKEFSARGS="$MAKEFSARGS -B little" else MAKEFSARGS="$MAKEFSARGS -B big" fi ;; *) echo "vmimage.subr: unsupported target '${TARGET}:${TARGET_ARCH}'" >&2 exit 1 ;; esac if [ ${ESP} = "yes" ]; then # Create an ESP espfilename=$(mktemp /tmp/efiboot.XXXXXX) make_esp_file ${espfilename} ${fat32min} ${BOOTFILES}/efi/loader_lua/loader_lua.efi BOOTPARTS="${BOOTPARTS} -p efi/efiboot0:=${espfilename}" # Add this to fstab mkdir -p ${DESTDIR}/boot/efi echo "/dev/${ROOTLABEL}/efiboot0 /boot/efi msdosfs rw 2 2" \ >> ${DESTDIR}/etc/fstab fi echo "Building filesystem... Please wait." buildfs echo "Building final disk image... Please wait." mkimg -s ${PARTSCHEME} -f ${VMFORMAT} \ ${BOOTPARTS} \ ${SWAPOPT} \ ${CONFIG_DRIVE} \ ${ROOTFSPART} \ -o ${VMIMAGE} echo "Disk image ${VMIMAGE} created." if [ ${ESP} = "yes" ]; then rm ${espfilename} fi return 0 } vm_extra_create_disk() { return 0 } touch_firstboot() { touch ${DESTDIR}/firstboot metalog_add_data ./firstboot }