release.sh revision 251652
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: head/release/release.sh 251652 2013-06-12 13:15:28Z 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"
44251652SgjbSRCBRANCH="base/head"
45251652SgjbDOCBRANCH="doc/head"
46251652SgjbPORTBRANCH="ports/head"
47251652Sgjb
48251652Sgjb# The default src/, doc/, and ports/ revisions.
49251652SgjbSRCREVISION="-rHEAD"
50251652SgjbDOCREVISION="-rHEAD"
51251652SgjbPORTREVISION="-rHEAD"
52251652Sgjb
53251652Sgjb# The default make.conf and src.conf to use.  Set to /dev/null
54251652Sgjb# by default to avoid polluting the chroot(8) environment with
55251652Sgjb# non-default settings.
56251652SgjbMAKE_CONF="/dev/null"
57251652SgjbSRC_CONF="/dev/null"
58251652Sgjb
59251652Sgjb# The number of make(1) jobs, defaults to the number of CPUs available for
60251652Sgjb# buildworld, and half of number of CPUs available for buildkernel.
61251652SgjbWORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
62251652SgjbKERNEL_FLAGS="-j$(expr $(sysctl -n hw.ncpu) / 2)"
63251652SgjbMAKE_FLAGS="-s"
64251652Sgjb
65251652Sgjb# The name of the kernel to build, defaults to GENERIC.
66251652SgjbKERNEL="GENERIC"
67251652Sgjb
68251652Sgjb# The TARGET and TARGET_ARCH to build, defaults to the running system.
69251652SgjbTARGET="$(uname -p)"
70251652SgjbTARGET_ARCH="${TARGET}"
71251652Sgjb
72251652Sgjb# Set to non-empty value to disable checkout of doc/ and/or ports/.  Disabling
73251652Sgjb# ports/ checkout also forces NODOC to be set.
74251652SgjbNODOC=
75251652SgjbNOPORTS=
76251652SgjbMAKE_FLAGS="${MAKE_FLAGS}"
77251652Sgjb
78251652Sgjbget_rev_branch () {
79251652Sgjb	# Set up the OSVERSION, BRANCH, and REVISION based on the src/ tree
80251652Sgjb	# checked out.
81251652Sgjb	OSVERSION=$(grep '#define __FreeBSD_version' ${CHROOTDIR}/usr/src/sys/sys/param.h | awk '{print $3}')
82251652Sgjb	BRANCH=$(grep '^BRANCH=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
83251652Sgjb		| awk -F\= '{print $2}' | sed -e 's,",,g')
84251652Sgjb	REVISION=$(grep '^REVISION=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
85251652Sgjb		| awk -F\= '{print $2}' | sed -e 's,",,g')
86251652Sgjb	OSRELEASE="${REVISION}-${BRANCH}"
87251652Sgjb}
88251652Sgjb
89251652Sgjbusage() {
90251652Sgjb	echo "Usage: $0 [-c release.conf]"
91251652Sgjb	exit 1
92251652Sgjb}
93251652Sgjb
94251652Sgjbwhile getopts c: opt; do
95251652Sgjb	case ${opt} in
96251652Sgjb	c)
97251652Sgjb		RELEASECONF="${OPTARG}"
98251652Sgjb		if [ ! -e "${RELEASECONF}" ]; then
99251652Sgjb			echo "ERROR: Configuration file ${RELEASECONF} does not exist."
100251652Sgjb			exit 1
101251652Sgjb		fi
102251652Sgjb		# Source the specified configuration file for overrides
103251652Sgjb		. ${RELEASECONF}
104251652Sgjb		;;
105251652Sgjb	\?)
106251652Sgjb		usage
107251652Sgjb		;;
108251652Sgjb	esac
109251652Sgjbdone
110251652Sgjbshift $(($OPTIND - 1))
111251652Sgjb
112251652Sgjb# The aggregated build-time flags based upon variables defined within
113251652Sgjb# this file, unless overridden by release.conf.  In most cases, these
114251652Sgjb# will not need to be changed.
115251652SgjbCONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
116251652SgjbARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
117251652SgjbCHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
118251652SgjbCHROOT_IMAKEFLAGS="${CONF_FILES}"
119251652SgjbCHROOT_DMAKEFLAGS="${CONF_FILES}"
120251652SgjbRELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
121251652SgjbRELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=${KERNEL} ${ARCH_FLAGS} ${CONF_FILES}"
122251652SgjbRELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=${KERNEL} ${CONF_FILES} \
123251652Sgjb	NODOC=${NODOC} NOPORTS=${NOPORTS}"
124251652Sgjb
125251652Sgjb# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
126251652Sgjb# is required to build the documentation set.
127251652Sgjbif [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
128251652Sgjb	echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
129251652Sgjb	echo "            and NOPORTS is set."
130251652Sgjb	NODOC=1
131251652Sgjbfi
132251652Sgjb
133251652Sgjbif [ ! ${CHROOTDIR} ]; then
134251652Sgjb	echo "Please set CHROOTDIR."
135251652Sgjb	exit 1
136251652Sgjbfi
137251652Sgjb
138251652Sgjbif [ $(id -u) -ne 0 ]; then
139251652Sgjb	echo "Needs to be run as root."
140251652Sgjb	exit 1
141251652Sgjbfi
142251652Sgjb
143251652Sgjbset -e # Everything must succeed
144251652Sgjb
145251652Sgjbmkdir -p ${CHROOTDIR}/usr
146251652Sgjb
147251652Sgjbsvn co ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src $SRCREVISION
148251652Sgjbif [ "x${NODOC}" = "x" ]; then
149251652Sgjb	svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc $DOCREVISION
150251652Sgjbfi
151251652Sgjbif [ "x${NOPORTS}" = "x" ]; then
152251652Sgjb	svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports $PORTREVISION
153251652Sgjbfi
154251652Sgjb
155251652Sgjbget_rev_branch
156251652Sgjb
157251652Sgjbcd ${CHROOTDIR}/usr/src
158251652Sgjbmake ${CHROOT_WMAKEFLAGS} buildworld
159251652Sgjbmake ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR}
160251652Sgjbmake ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR}
161251652Sgjbmount -t devfs devfs ${CHROOTDIR}/dev
162251652Sgjbtrap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
163251652Sgjb
164251652Sgjbbuild_doc_ports() {
165251652Sgjb	## Trick the ports 'run-autotools-fixup' target to do the right thing.
166251652Sgjb	_OSVERSION=$(sysctl -n kern.osreldate)
167251652Sgjb	if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" != "x" ]; then
168251652Sgjb		PBUILD_FLAGS="OSVERSION=${OSVERSION} WITHOUT_JADETEX=yes BATCH=yes"
169251652Sgjb		chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
170251652Sgjb			${PBUILD_FLAGS} install
171251652Sgjb	fi
172251652Sgjb}
173251652Sgjb
174251652Sgjbif [ -d ${CHROOTDIR}/usr/ports ]; then
175251652Sgjb	cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
176251652Sgjb	build_doc_ports ${CHROOTDIR}
177251652Sgjbfi
178251652Sgjb
179251652Sgjbif [ "x${RELSTRING}" = "x" ]; then
180251652Sgjb	RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
181251652Sgjbfi
182251652Sgjb
183251652Sgjbchroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
184251652Sgjbchroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
185251652Sgjbchroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
186251652Sgjb	release RELSTRING=${RELSTRING}
187251652Sgjbchroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
188251652Sgjb	install DESTDIR=/R RELSTRING=${RELSTRING}
189251652Sgjb
190251652Sgjbcd ${CHROOTDIR}/R
191251652Sgjb
192251652Sgjbsha256 FreeBSD-* > CHECKSUM.SHA256
193251652Sgjbmd5 FreeBSD-* > CHECKSUM.MD5
194