release.sh revision 260071
1251652Sgjb#!/bin/sh 2251652Sgjb#- 3251652Sgjb# Copyright (c) 2013 Glen Barber 4251652Sgjb# Copyright (c) 2011 Nathan Whitehorn 5251652Sgjb# All rights reserved. 6251652Sgjb# 7251652Sgjb# Redistribution and use in source and binary forms, with or without 8251652Sgjb# modification, are permitted provided that the following conditions 9251652Sgjb# are met: 10251652Sgjb# 1. Redistributions of source code must retain the above copyright 11251652Sgjb# notice, this list of conditions and the following disclaimer. 12251652Sgjb# 2. Redistributions in binary form must reproduce the above copyright 13251652Sgjb# notice, this list of conditions and the following disclaimer in the 14251652Sgjb# documentation and/or other materials provided with the distribution. 15251652Sgjb# 16251652Sgjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17251652Sgjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18251652Sgjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19251652Sgjb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20251652Sgjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21251652Sgjb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22251652Sgjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23251652Sgjb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24251652Sgjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25251652Sgjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26251652Sgjb# SUCH DAMAGE. 27251652Sgjb# 28251652Sgjb# release.sh: check out source trees, and build release components with 29251652Sgjb# totally clean, fresh trees. 30251652Sgjb# Based on release/generate-release.sh written by Nathan Whitehorn 31251652Sgjb# 32251652Sgjb# $FreeBSD: stable/10/release/release.sh 260071 2013-12-30 02:19:23Z gjb $ 33251652Sgjb# 34251652Sgjb 35251652SgjbPATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" 36251652Sgjbexport PATH 37251652Sgjb 38251652Sgjb# The directory within which the release will be built. 39251652SgjbCHROOTDIR="/scratch" 40251652Sgjb 41251652Sgjb# The default svn checkout server, and svn branches for src/, doc/, 42251652Sgjb# and ports/. 43251652SgjbSVNROOT="svn://svn.freebsd.org" 44254293SgjbSRCBRANCH="base/head@rHEAD" 45254293SgjbDOCBRANCH="doc/head@rHEAD" 46254293SgjbPORTBRANCH="ports/head@rHEAD" 47251652Sgjb 48252846Sgjb# Sometimes one needs to checkout src with --force svn option. 49252846Sgjb# If custom kernel configs copied to src tree before checkout, e.g. 50252846SgjbSRC_FORCE_CHECKOUT= 51252846Sgjb 52251652Sgjb# The default make.conf and src.conf to use. Set to /dev/null 53251652Sgjb# by default to avoid polluting the chroot(8) environment with 54251652Sgjb# non-default settings. 55251652SgjbMAKE_CONF="/dev/null" 56251652SgjbSRC_CONF="/dev/null" 57251652Sgjb 58251652Sgjb# The number of make(1) jobs, defaults to the number of CPUs available for 59251652Sgjb# buildworld, and half of number of CPUs available for buildkernel. 60254293SgjbNCPU=$(sysctl -n hw.ncpu) 61254293Sgjbif [ ${NCPU} -gt 1 ]; then 62254293Sgjb WORLD_FLAGS="-j${NCPU}" 63254293Sgjb KERNEL_FLAGS="-j$(expr ${NCPU} / 2)" 64254293Sgjbfi 65251652SgjbMAKE_FLAGS="-s" 66251652Sgjb 67251652Sgjb# The name of the kernel to build, defaults to GENERIC. 68251652SgjbKERNEL="GENERIC" 69251652Sgjb 70251652Sgjb# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling 71251652Sgjb# ports/ checkout also forces NODOC to be set. 72251652SgjbNODOC= 73251652SgjbNOPORTS= 74251652Sgjb 75259151Sgjb# Set to non-empty value to build dvd1.iso as part of the release. 76259151SgjbWITH_DVD= 77259151Sgjb 78251652Sgjbusage() { 79251652Sgjb echo "Usage: $0 [-c release.conf]" 80251652Sgjb exit 1 81251652Sgjb} 82251652Sgjb 83251652Sgjbwhile getopts c: opt; do 84251652Sgjb case ${opt} in 85251652Sgjb c) 86251652Sgjb RELEASECONF="${OPTARG}" 87251652Sgjb if [ ! -e "${RELEASECONF}" ]; then 88251652Sgjb echo "ERROR: Configuration file ${RELEASECONF} does not exist." 89251652Sgjb exit 1 90251652Sgjb fi 91251652Sgjb # Source the specified configuration file for overrides 92251652Sgjb . ${RELEASECONF} 93251652Sgjb ;; 94251652Sgjb \?) 95251652Sgjb usage 96251652Sgjb ;; 97251652Sgjb esac 98251652Sgjbdone 99251652Sgjbshift $(($OPTIND - 1)) 100251652Sgjb 101252846Sgjb# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree 102252846Sgjb# is required to build the documentation set. 103252846Sgjbif [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then 104252846Sgjb echo "*** NOTICE: Setting NODOC=1 since ports tree is required" 105252846Sgjb echo " and NOPORTS is set." 106252846Sgjb NODOC=yes 107252846Sgjbfi 108252846Sgjb 109252846Sgjb# If NOPORTS and/or NODOC are unset, they must not pass to make as variables. 110252846Sgjb# The release makefile verifies definedness of NOPORTS/NODOC variables 111252846Sgjb# instead of their values. 112252846SgjbDOCPORTS= 113252846Sgjbif [ "x${NOPORTS}" != "x" ]; then 114259225Sgjb DOCPORTS="NOPORTS=yes " 115252846Sgjbfi 116252846Sgjbif [ "x${NODOC}" != "x" ]; then 117259225Sgjb DOCPORTS="${DOCPORTS}NODOC=yes" 118252846Sgjbfi 119252846Sgjb 120251652Sgjb# The aggregated build-time flags based upon variables defined within 121251652Sgjb# this file, unless overridden by release.conf. In most cases, these 122251652Sgjb# will not need to be changed. 123251652SgjbCONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}" 124254293Sgjbif [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then 125254293Sgjb ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" 126254293Sgjbelse 127254293Sgjb ARCH_FLAGS= 128254293Sgjbfi 129260071SgjbCHROOT_MAKEENV="MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj" 130251652SgjbCHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}" 131251652SgjbCHROOT_IMAKEFLAGS="${CONF_FILES}" 132251652SgjbCHROOT_DMAKEFLAGS="${CONF_FILES}" 133251652SgjbRELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}" 134252846SgjbRELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}" 135252846SgjbRELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \ 136259151Sgjb ${DOCPORTS} WITH_DVD=${WITH_DVD}" 137251652Sgjb 138252846Sgjb# Force src checkout if configured 139252846SgjbFORCE_SRC_KEY= 140252846Sgjbif [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then 141259225Sgjb FORCE_SRC_KEY="--force" 142251652Sgjbfi 143251652Sgjb 144251652Sgjbif [ ! ${CHROOTDIR} ]; then 145251652Sgjb echo "Please set CHROOTDIR." 146251652Sgjb exit 1 147251652Sgjbfi 148251652Sgjb 149251652Sgjbif [ $(id -u) -ne 0 ]; then 150251652Sgjb echo "Needs to be run as root." 151251652Sgjb exit 1 152251652Sgjbfi 153251652Sgjb 154251652Sgjbset -e # Everything must succeed 155251652Sgjb 156251652Sgjbmkdir -p ${CHROOTDIR}/usr 157251652Sgjb 158254293Sgjbsvn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src 159251652Sgjbif [ "x${NODOC}" = "x" ]; then 160254293Sgjb svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc 161251652Sgjbfi 162251652Sgjbif [ "x${NOPORTS}" = "x" ]; then 163254293Sgjb svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports 164251652Sgjbfi 165251652Sgjb 166251652Sgjbcd ${CHROOTDIR}/usr/src 167260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld 168260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \ 169260071Sgjb DESTDIR=${CHROOTDIR} 170260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \ 171260071Sgjb DESTDIR=${CHROOTDIR} 172251652Sgjbmount -t devfs devfs ${CHROOTDIR}/dev 173260071Sgjbcp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf 174251652Sgjbtrap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit 175251652Sgjb 176260071Sgjb# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null), 177260071Sgjb# copy them to the chroot. 178260071Sgjbif [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then 179260071Sgjb mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF}) 180260071Sgjb cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF} 181260071Sgjbfi 182260071Sgjbif [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then 183260071Sgjb mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF}) 184260071Sgjb cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF} 185260071Sgjbfi 186260071Sgjb 187260071Sgjbif [ -d ${CHROOTDIR}/usr/ports ]; then 188257776Sgjb # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints 189257776Sgjb # is created. This is needed by ports-mgmt/pkg. 190257776Sgjb chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart 191257776Sgjb 192251652Sgjb ## Trick the ports 'run-autotools-fixup' target to do the right thing. 193251652Sgjb _OSVERSION=$(sysctl -n kern.osreldate) 194252846Sgjb if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then 195258261Sgjb PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes" 196258952Sgjb PBUILD_FLAGS="${PBUILD_FLAGS}" 197251652Sgjb chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \ 198258952Sgjb ${PBUILD_FLAGS} OPTIONS_UNSET="FOP IGOR" install clean distclean 199251652Sgjb fi 200252101Sgjbfi 201252101Sgjb 202251652Sgjbif [ "x${RELSTRING}" = "x" ]; then 203251652Sgjb RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}" 204251652Sgjbfi 205251652Sgjb 206252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld 207252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel 208252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 209251652Sgjb release RELSTRING=${RELSTRING} 210252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 211251652Sgjb install DESTDIR=/R RELSTRING=${RELSTRING} 212