release.sh revision 257776
1101100Ssos#!/bin/sh 2114154Ssos#- 3101100Ssos# Copyright (c) 2013 Glen Barber 4101100Ssos# Copyright (c) 2011 Nathan Whitehorn 5101100Ssos# All rights reserved. 6101100Ssos# 7101100Ssos# Redistribution and use in source and binary forms, with or without 8101100Ssos# modification, are permitted provided that the following conditions 9101100Ssos# are met: 10101100Ssos# 1. Redistributions of source code must retain the above copyright 11101100Ssos# notice, this list of conditions and the following disclaimer. 12101100Ssos# 2. Redistributions in binary form must reproduce the above copyright 13101100Ssos# notice, this list of conditions and the following disclaimer in the 14101100Ssos# documentation and/or other materials provided with the distribution. 15101100Ssos# 16101100Ssos# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17101100Ssos# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18101100Ssos# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19101100Ssos# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20101100Ssos# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21101100Ssos# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22101100Ssos# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23101100Ssos# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24101100Ssos# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25101100Ssos# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26101100Ssos# SUCH DAMAGE. 27101100Ssos# 28101100Ssos# release.sh: check out source trees, and build release components with 29119418Sobrien# totally clean, fresh trees. 30119418Sobrien# Based on release/generate-release.sh written by Nathan Whitehorn 31119418Sobrien# 32101100Ssos# $FreeBSD: stable/10/release/release.sh 257776 2013-11-07 04:13:27Z gjb $ 33101100Ssos# 34101100Ssos 35101100SsosPATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" 36101100Ssosexport PATH 37101100Ssos 38101100Ssos# The directory within which the release will be built. 39114154SsosCHROOTDIR="/scratch" 40114154Ssos 41101100Ssos# The default svn checkout server, and svn branches for src/, doc/, 42101100Ssos# and ports/. 43101100SsosSVNROOT="svn://svn.freebsd.org" 44101100SsosSRCBRANCH="base/head@rHEAD" 45101100SsosDOCBRANCH="doc/head@rHEAD" 46101100SsosPORTBRANCH="ports/head@rHEAD" 47119285Simp 48119285Simp# Sometimes one needs to checkout src with --force svn option. 49101100Ssos# If custom kernel configs copied to src tree before checkout, e.g. 50101100SsosSRC_FORCE_CHECKOUT= 51101100Ssos 52114154Ssos# The default make.conf and src.conf to use. Set to /dev/null 53114154Ssos# by default to avoid polluting the chroot(8) environment with 54114154Ssos# non-default settings. 55114154SsosMAKE_CONF="/dev/null" 56114154SsosSRC_CONF="/dev/null" 57101100Ssos 58101100Ssos# The number of make(1) jobs, defaults to the number of CPUs available for 59101100Ssos# buildworld, and half of number of CPUs available for buildkernel. 60101100SsosNCPU=$(sysctl -n hw.ncpu) 61101100Ssosif [ ${NCPU} -gt 1 ]; then 62101100Ssos WORLD_FLAGS="-j${NCPU}" 63101100Ssos KERNEL_FLAGS="-j$(expr ${NCPU} / 2)" 64101100Ssosfi 65101100SsosMAKE_FLAGS="-s" 66101100Ssos 67101100Ssos# The name of the kernel to build, defaults to GENERIC. 68101100SsosKERNEL="GENERIC" 69101100Ssos 70101100Ssos# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling 71101100Ssos# ports/ checkout also forces NODOC to be set. 72101100SsosNODOC= 73101100SsosNOPORTS= 74101100Ssos 75101100Ssosusage() { 76101100Ssos echo "Usage: $0 [-c release.conf]" 77101100Ssos exit 1 78101100Ssos} 79101100Ssos 80101100Ssoswhile getopts c: opt; do 81101100Ssos case ${opt} in 82101100Ssos c) 83101100Ssos RELEASECONF="${OPTARG}" 84101100Ssos if [ ! -e "${RELEASECONF}" ]; then 85101100Ssos echo "ERROR: Configuration file ${RELEASECONF} does not exist." 86101100Ssos exit 1 87108533Sschweikh fi 88101100Ssos # Source the specified configuration file for overrides 89101100Ssos . ${RELEASECONF} 90101100Ssos ;; 91101100Ssos \?) 92136094Sstefanf usage 93136094Sstefanf ;; 94101100Ssos esac 95101100Ssosdone 96101100Ssosshift $(($OPTIND - 1)) 97101100Ssos 98101100Ssos# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree 99101100Ssos# is required to build the documentation set. 100101100Ssosif [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then 101101100Ssos echo "*** NOTICE: Setting NODOC=1 since ports tree is required" 102136094Sstefanf echo " and NOPORTS is set." 103101100Ssos NODOC=yes 104136094Sstefanffi 105101100Ssos 106101100Ssos# If NOPORTS and/or NODOC are unset, they must not pass to make as variables. 107136094Sstefanf# The release makefile verifies definedness of NOPORTS/NODOC variables 108101100Ssos# instead of their values. 109101100SsosDOCPORTS= 110101100Ssosif [ "x${NOPORTS}" != "x" ]; then 111101100Ssos DOCPORTS="NOPORTS=yes " 112101100Ssosfi 113101100Ssosif [ "x${NODOC}" != "x" ]; then 114101100Ssos DOCPORTS="${DOCPORTS}NODOC=yes" 115101100Ssosfi 116101100Ssos 117101100Ssos# The aggregated build-time flags based upon variables defined within 118101100Ssos# this file, unless overridden by release.conf. In most cases, these 119101100Ssos# will not need to be changed. 120101100SsosCONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}" 121101100Ssosif [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then 122101100Ssos ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" 123101100Ssoselse 124101100Ssos ARCH_FLAGS= 125101100Ssosfi 126101100SsosCHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}" 127101100SsosCHROOT_IMAKEFLAGS="${CONF_FILES}" 128101100SsosCHROOT_DMAKEFLAGS="${CONF_FILES}" 129101100SsosRELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}" 130101100SsosRELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}" 131101100SsosRELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \ 132101100Ssos ${DOCPORTS}" 133101100Ssos 134101100Ssos# Force src checkout if configured 135101100SsosFORCE_SRC_KEY= 136101100Ssosif [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then 137101100Ssos FORCE_SRC_KEY="--force" 138101100Ssosfi 139101100Ssos 140101100Ssosif [ ! ${CHROOTDIR} ]; then 141101100Ssos echo "Please set CHROOTDIR." 142101100Ssos exit 1 143101100Ssosfi 144101100Ssos 145101100Ssosif [ $(id -u) -ne 0 ]; then 146101100Ssos echo "Needs to be run as root." 147101100Ssos exit 1 148101100Ssosfi 149114154Ssos 150114154Ssosset -e # Everything must succeed 151114154Ssos 152114154Ssosmkdir -p ${CHROOTDIR}/usr 153114154Ssos 154101100Ssossvn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src 155101100Ssosif [ "x${NODOC}" = "x" ]; then 156101100Ssos svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc 157101100Ssosfi 158101100Ssosif [ "x${NOPORTS}" = "x" ]; then 159114154Ssos svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports 160101100Ssosfi 161114154Ssos 162166901Spisocd ${CHROOTDIR}/usr/src 163101100Ssosmake ${CHROOT_WMAKEFLAGS} buildworld 164101100Ssosmake ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR} 165101100Ssosmake ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR} 166101100Ssosmount -t devfs devfs ${CHROOTDIR}/dev 167101100Ssostrap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit 168101100Ssos 169101100Ssosbuild_doc_ports() { 170101100Ssos # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints 171101100Ssos # is created. This is needed by ports-mgmt/pkg. 172101100Ssos chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart 173102058Ssos 174114154Ssos ## Trick the ports 'run-autotools-fixup' target to do the right thing. 175102058Ssos _OSVERSION=$(sysctl -n kern.osreldate) 176102058Ssos if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then 177102058Ssos PBUILD_FLAGS="OSVERSION=${_OSVERSION} WITHOUT_JADETEX=yes WITHOUT_X11=yes BATCH=yes" 178114154Ssos chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \ 179102058Ssos ${PBUILD_FLAGS} install clean distclean 180102058Ssos fi 181102058Ssos} 182114154Ssos 183102058Ssos# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null), 184108533Sschweikh# copy them to the chroot. 185102058Ssosif [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then 186102058Ssos mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF}) 187102058Ssos cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF} 188102058Ssosfi 189114154Ssosif [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then 190101100Ssos mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF}) 191101100Ssos cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF} 192102058Ssosfi 193102058Ssos 194102058Ssosif [ -d ${CHROOTDIR}/usr/ports ]; then 195108533Sschweikh cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf 196102058Ssos build_doc_ports ${CHROOTDIR} 197102058Ssosfi 198102058Ssos 199101100Ssosif [ "x${RELSTRING}" = "x" ]; then 200114154Ssos RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}" 201101100Ssosfi 202101100Ssos 203101100Ssoseval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld 204101100Ssoseval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel 205101100Ssoseval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 206101100Ssos release RELSTRING=${RELSTRING} 207101100Ssoseval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 208102058Ssos install DESTDIR=/R RELSTRING=${RELSTRING} 209101100Ssos