Deleted Added
full compact
release.sh (252846) release.sh (254293)
1#!/bin/sh
2#-
3# Copyright (c) 2013 Glen Barber
4# Copyright (c) 2011 Nathan Whitehorn
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# release.sh: check out source trees, and build release components with
29# totally clean, fresh trees.
30# Based on release/generate-release.sh written by Nathan Whitehorn
31#
1#!/bin/sh
2#-
3# Copyright (c) 2013 Glen Barber
4# Copyright (c) 2011 Nathan Whitehorn
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# release.sh: check out source trees, and build release components with
29# totally clean, fresh trees.
30# Based on release/generate-release.sh written by Nathan Whitehorn
31#
32# $FreeBSD: head/release/release.sh 252846 2013-07-05 22:04:49Z gjb $
32# $FreeBSD: head/release/release.sh 254293 2013-08-13 20:16:14Z gjb $
33#
34
35PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
36export PATH
37
38# The directory within which the release will be built.
39CHROOTDIR="/scratch"
40
41# The default svn checkout server, and svn branches for src/, doc/,
42# and ports/.
43SVNROOT="svn://svn.freebsd.org"
33#
34
35PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
36export PATH
37
38# The directory within which the release will be built.
39CHROOTDIR="/scratch"
40
41# The default svn checkout server, and svn branches for src/, doc/,
42# and ports/.
43SVNROOT="svn://svn.freebsd.org"
44SRCBRANCH="base/head"
45DOCBRANCH="doc/head"
46PORTBRANCH="ports/head"
44SRCBRANCH="base/head@rHEAD"
45DOCBRANCH="doc/head@rHEAD"
46PORTBRANCH="ports/head@rHEAD"
47
48# Sometimes one needs to checkout src with --force svn option.
49# If custom kernel configs copied to src tree before checkout, e.g.
50SRC_FORCE_CHECKOUT=
51
47
48# Sometimes one needs to checkout src with --force svn option.
49# If custom kernel configs copied to src tree before checkout, e.g.
50SRC_FORCE_CHECKOUT=
51
52# The default src/, doc/, and ports/ revisions.
53SRCREVISION="-rHEAD"
54DOCREVISION="-rHEAD"
55PORTREVISION="-rHEAD"
56
57# The default make.conf and src.conf to use. Set to /dev/null
58# by default to avoid polluting the chroot(8) environment with
59# non-default settings.
60MAKE_CONF="/dev/null"
61SRC_CONF="/dev/null"
62
63# The number of make(1) jobs, defaults to the number of CPUs available for
64# buildworld, and half of number of CPUs available for buildkernel.
52# The default make.conf and src.conf to use. Set to /dev/null
53# by default to avoid polluting the chroot(8) environment with
54# non-default settings.
55MAKE_CONF="/dev/null"
56SRC_CONF="/dev/null"
57
58# The number of make(1) jobs, defaults to the number of CPUs available for
59# buildworld, and half of number of CPUs available for buildkernel.
65WORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
66KERNEL_FLAGS="-j$(expr $(sysctl -n hw.ncpu) / 2)"
60NCPU=$(sysctl -n hw.ncpu)
61if [ ${NCPU} -gt 1 ]; then
62 WORLD_FLAGS="-j${NCPU}"
63 KERNEL_FLAGS="-j$(expr ${NCPU} / 2)"
64fi
67MAKE_FLAGS="-s"
68
69# The name of the kernel to build, defaults to GENERIC.
70KERNEL="GENERIC"
71
65MAKE_FLAGS="-s"
66
67# The name of the kernel to build, defaults to GENERIC.
68KERNEL="GENERIC"
69
72# The TARGET and TARGET_ARCH to build, defaults to the running system.
73TARGET="$(uname -p)"
74TARGET_ARCH="${TARGET}"
75
76# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling
77# ports/ checkout also forces NODOC to be set.
78NODOC=
79NOPORTS=
80MAKE_FLAGS="${MAKE_FLAGS}"
81
82get_rev_branch () {
83 # Set up the OSVERSION, BRANCH, and REVISION based on the src/ tree
84 # checked out.
85 OSVERSION=$(grep '#define __FreeBSD_version' ${CHROOTDIR}/usr/src/sys/sys/param.h | awk '{print $3}')
86 BRANCH=$(grep '^BRANCH=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
87 | awk -F\= '{print $2}' | sed -e 's,",,g')
88 REVISION=$(grep '^REVISION=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
89 | awk -F\= '{print $2}' | sed -e 's,",,g')
90 OSRELEASE="${REVISION}-${BRANCH}"
91}
92
93usage() {
94 echo "Usage: $0 [-c release.conf]"
95 exit 1
96}
97
98while getopts c: opt; do
99 case ${opt} in
100 c)
101 RELEASECONF="${OPTARG}"
102 if [ ! -e "${RELEASECONF}" ]; then
103 echo "ERROR: Configuration file ${RELEASECONF} does not exist."
104 exit 1
105 fi
106 # Source the specified configuration file for overrides
107 . ${RELEASECONF}
108 ;;
109 \?)
110 usage
111 ;;
112 esac
113done
114shift $(($OPTIND - 1))
115
116# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
117# is required to build the documentation set.
118if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
119 echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
120 echo " and NOPORTS is set."
121 NODOC=yes
122fi
123
124# If NOPORTS and/or NODOC are unset, they must not pass to make as variables.
125# The release makefile verifies definedness of NOPORTS/NODOC variables
126# instead of their values.
127DOCPORTS=
128if [ "x${NOPORTS}" != "x" ]; then
129 DOCPORTS="NOPORTS=yes "
130fi
131if [ "x${NODOC}" != "x" ]; then
132 DOCPORTS="${DOCPORTS}NODOC=yes"
133fi
134
135# The aggregated build-time flags based upon variables defined within
136# this file, unless overridden by release.conf. In most cases, these
137# will not need to be changed.
138CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
70# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling
71# ports/ checkout also forces NODOC to be set.
72NODOC=
73NOPORTS=
74MAKE_FLAGS="${MAKE_FLAGS}"
75
76get_rev_branch () {
77 # Set up the OSVERSION, BRANCH, and REVISION based on the src/ tree
78 # checked out.
79 OSVERSION=$(grep '#define __FreeBSD_version' ${CHROOTDIR}/usr/src/sys/sys/param.h | awk '{print $3}')
80 BRANCH=$(grep '^BRANCH=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
81 | awk -F\= '{print $2}' | sed -e 's,",,g')
82 REVISION=$(grep '^REVISION=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
83 | awk -F\= '{print $2}' | sed -e 's,",,g')
84 OSRELEASE="${REVISION}-${BRANCH}"
85}
86
87usage() {
88 echo "Usage: $0 [-c release.conf]"
89 exit 1
90}
91
92while getopts c: opt; do
93 case ${opt} in
94 c)
95 RELEASECONF="${OPTARG}"
96 if [ ! -e "${RELEASECONF}" ]; then
97 echo "ERROR: Configuration file ${RELEASECONF} does not exist."
98 exit 1
99 fi
100 # Source the specified configuration file for overrides
101 . ${RELEASECONF}
102 ;;
103 \?)
104 usage
105 ;;
106 esac
107done
108shift $(($OPTIND - 1))
109
110# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
111# is required to build the documentation set.
112if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
113 echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
114 echo " and NOPORTS is set."
115 NODOC=yes
116fi
117
118# If NOPORTS and/or NODOC are unset, they must not pass to make as variables.
119# The release makefile verifies definedness of NOPORTS/NODOC variables
120# instead of their values.
121DOCPORTS=
122if [ "x${NOPORTS}" != "x" ]; then
123 DOCPORTS="NOPORTS=yes "
124fi
125if [ "x${NODOC}" != "x" ]; then
126 DOCPORTS="${DOCPORTS}NODOC=yes"
127fi
128
129# The aggregated build-time flags based upon variables defined within
130# this file, unless overridden by release.conf. In most cases, these
131# will not need to be changed.
132CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
139ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
133if [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then
134 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
135else
136 ARCH_FLAGS=
137fi
140CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
141CHROOT_IMAKEFLAGS="${CONF_FILES}"
142CHROOT_DMAKEFLAGS="${CONF_FILES}"
143RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
144RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
145RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \
146 ${DOCPORTS}"
147
148# Force src checkout if configured
149FORCE_SRC_KEY=
150if [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then
151 FORCE_SRC_KEY="--force"
152fi
153
154if [ ! ${CHROOTDIR} ]; then
155 echo "Please set CHROOTDIR."
156 exit 1
157fi
158
159if [ $(id -u) -ne 0 ]; then
160 echo "Needs to be run as root."
161 exit 1
162fi
163
164set -e # Everything must succeed
165
166mkdir -p ${CHROOTDIR}/usr
167
138CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
139CHROOT_IMAKEFLAGS="${CONF_FILES}"
140CHROOT_DMAKEFLAGS="${CONF_FILES}"
141RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
142RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
143RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \
144 ${DOCPORTS}"
145
146# Force src checkout if configured
147FORCE_SRC_KEY=
148if [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then
149 FORCE_SRC_KEY="--force"
150fi
151
152if [ ! ${CHROOTDIR} ]; then
153 echo "Please set CHROOTDIR."
154 exit 1
155fi
156
157if [ $(id -u) -ne 0 ]; then
158 echo "Needs to be run as root."
159 exit 1
160fi
161
162set -e # Everything must succeed
163
164mkdir -p ${CHROOTDIR}/usr
165
168svn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src $SRCREVISION
166svn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src
169if [ "x${NODOC}" = "x" ]; then
167if [ "x${NODOC}" = "x" ]; then
170 svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc $DOCREVISION
168 svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc
171fi
172if [ "x${NOPORTS}" = "x" ]; then
169fi
170if [ "x${NOPORTS}" = "x" ]; then
173 svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports $PORTREVISION
171 svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports
174fi
175
176get_rev_branch
177
178cd ${CHROOTDIR}/usr/src
179make ${CHROOT_WMAKEFLAGS} buildworld
180make ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR}
181make ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR}
182mount -t devfs devfs ${CHROOTDIR}/dev
183trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
184
185build_doc_ports() {
186 ## Trick the ports 'run-autotools-fixup' target to do the right thing.
187 _OSVERSION=$(sysctl -n kern.osreldate)
188 if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then
189 PBUILD_FLAGS="OSVERSION=${_OSVERSION} WITHOUT_JADETEX=yes WITHOUT_X11=yes BATCH=yes"
190 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
191 ${PBUILD_FLAGS} install clean distclean
192 fi
193}
194
195# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
196# copy them to the chroot.
197if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
198 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
199 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
200fi
201if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
202 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
203 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
204fi
205
206if [ -d ${CHROOTDIR}/usr/ports ]; then
207 cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
208 build_doc_ports ${CHROOTDIR}
209fi
210
211if [ "x${RELSTRING}" = "x" ]; then
212 RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
213fi
214
215eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
216eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
217eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
218 release RELSTRING=${RELSTRING}
219eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
220 install DESTDIR=/R RELSTRING=${RELSTRING}
221
222cd ${CHROOTDIR}/R
223
224sha256 FreeBSD-* > CHECKSUM.SHA256
225md5 FreeBSD-* > CHECKSUM.MD5
172fi
173
174get_rev_branch
175
176cd ${CHROOTDIR}/usr/src
177make ${CHROOT_WMAKEFLAGS} buildworld
178make ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR}
179make ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR}
180mount -t devfs devfs ${CHROOTDIR}/dev
181trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
182
183build_doc_ports() {
184 ## Trick the ports 'run-autotools-fixup' target to do the right thing.
185 _OSVERSION=$(sysctl -n kern.osreldate)
186 if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then
187 PBUILD_FLAGS="OSVERSION=${_OSVERSION} WITHOUT_JADETEX=yes WITHOUT_X11=yes BATCH=yes"
188 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
189 ${PBUILD_FLAGS} install clean distclean
190 fi
191}
192
193# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
194# copy them to the chroot.
195if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
196 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
197 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
198fi
199if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
200 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
201 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
202fi
203
204if [ -d ${CHROOTDIR}/usr/ports ]; then
205 cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
206 build_doc_ports ${CHROOTDIR}
207fi
208
209if [ "x${RELSTRING}" = "x" ]; then
210 RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
211fi
212
213eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
214eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
215eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
216 release RELSTRING=${RELSTRING}
217eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
218 install DESTDIR=/R RELSTRING=${RELSTRING}
219
220cd ${CHROOTDIR}/R
221
222sha256 FreeBSD-* > CHECKSUM.SHA256
223md5 FreeBSD-* > CHECKSUM.MD5