]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - release/release.sh
MFC r251652, r251811, r252101:
[FreeBSD/stable/9.git] / release / release.sh
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$
33 #
34
35 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
36 export PATH
37
38 # The directory within which the release will be built.
39 CHROOTDIR="/scratch"
40
41 # The default svn checkout server, and svn branches for src/, doc/,
42 # and ports/.
43 SVNROOT="svn://svn.freebsd.org"
44 SRCBRANCH="base/head"
45 DOCBRANCH="doc/head"
46 PORTBRANCH="ports/head"
47
48 # The default src/, doc/, and ports/ revisions.
49 SRCREVISION="-rHEAD"
50 DOCREVISION="-rHEAD"
51 PORTREVISION="-rHEAD"
52
53 # The default make.conf and src.conf to use.  Set to /dev/null
54 # by default to avoid polluting the chroot(8) environment with
55 # non-default settings.
56 MAKE_CONF="/dev/null"
57 SRC_CONF="/dev/null"
58
59 # The number of make(1) jobs, defaults to the number of CPUs available for
60 # buildworld, and half of number of CPUs available for buildkernel.
61 WORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
62 KERNEL_FLAGS="-j$(expr $(sysctl -n hw.ncpu) / 2)"
63 MAKE_FLAGS="-s"
64
65 # The name of the kernel to build, defaults to GENERIC.
66 KERNEL="GENERIC"
67
68 # The TARGET and TARGET_ARCH to build, defaults to the running system.
69 TARGET="$(uname -p)"
70 TARGET_ARCH="${TARGET}"
71
72 # Set to non-empty value to disable checkout of doc/ and/or ports/.  Disabling
73 # ports/ checkout also forces NODOC to be set.
74 NODOC=
75 NOPORTS=
76 MAKE_FLAGS="${MAKE_FLAGS}"
77
78 get_rev_branch () {
79         # Set up the OSVERSION, BRANCH, and REVISION based on the src/ tree
80         # checked out.
81         OSVERSION=$(grep '#define __FreeBSD_version' ${CHROOTDIR}/usr/src/sys/sys/param.h | awk '{print $3}')
82         BRANCH=$(grep '^BRANCH=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
83                 | awk -F\= '{print $2}' | sed -e 's,",,g')
84         REVISION=$(grep '^REVISION=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
85                 | awk -F\= '{print $2}' | sed -e 's,",,g')
86         OSRELEASE="${REVISION}-${BRANCH}"
87 }
88
89 usage() {
90         echo "Usage: $0 [-c release.conf]"
91         exit 1
92 }
93
94 while getopts c: opt; do
95         case ${opt} in
96         c)
97                 RELEASECONF="${OPTARG}"
98                 if [ ! -e "${RELEASECONF}" ]; then
99                         echo "ERROR: Configuration file ${RELEASECONF} does not exist."
100                         exit 1
101                 fi
102                 # Source the specified configuration file for overrides
103                 . ${RELEASECONF}
104                 ;;
105         \?)
106                 usage
107                 ;;
108         esac
109 done
110 shift $(($OPTIND - 1))
111
112 # The aggregated build-time flags based upon variables defined within
113 # this file, unless overridden by release.conf.  In most cases, these
114 # will not need to be changed.
115 CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
116 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
117 CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
118 CHROOT_IMAKEFLAGS="${CONF_FILES}"
119 CHROOT_DMAKEFLAGS="${CONF_FILES}"
120 RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
121 RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=${KERNEL} ${ARCH_FLAGS} ${CONF_FILES}"
122 RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=${KERNEL} ${CONF_FILES} \
123         NODOC=${NODOC} NOPORTS=${NOPORTS}"
124
125 # If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
126 # is required to build the documentation set.
127 if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
128         echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
129         echo "            and NOPORTS is set."
130         NODOC=1
131 fi
132
133 if [ ! ${CHROOTDIR} ]; then
134         echo "Please set CHROOTDIR."
135         exit 1
136 fi
137
138 if [ $(id -u) -ne 0 ]; then
139         echo "Needs to be run as root."
140         exit 1
141 fi
142
143 set -e # Everything must succeed
144
145 mkdir -p ${CHROOTDIR}/usr
146
147 svn co ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src $SRCREVISION
148 if [ "x${NODOC}" = "x" ]; then
149         svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc $DOCREVISION
150 fi
151 if [ "x${NOPORTS}" = "x" ]; then
152         svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports $PORTREVISION
153 fi
154
155 get_rev_branch
156
157 cd ${CHROOTDIR}/usr/src
158 make ${CHROOT_WMAKEFLAGS} buildworld
159 make ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR}
160 make ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR}
161 mount -t devfs devfs ${CHROOTDIR}/dev
162 trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
163
164 build_doc_ports() {
165         ## Trick the ports 'run-autotools-fixup' target to do the right thing.
166         _OSVERSION=$(sysctl -n kern.osreldate)
167         if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" != "x" ]; then
168                 PBUILD_FLAGS="OSVERSION=${_OSVERSION} WITHOUT_JADETEX=yes BATCH=yes"
169                 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
170                         ${PBUILD_FLAGS} install
171         fi
172 }
173
174 # If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
175 # copy them to the chroot.
176 if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
177         mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
178         cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
179 fi
180 if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
181         mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
182         cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
183 fi
184
185 if [ -d ${CHROOTDIR}/usr/ports ]; then
186         cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
187         build_doc_ports ${CHROOTDIR}
188 fi
189
190 if [ "x${RELSTRING}" = "x" ]; then
191         RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
192 fi
193
194 chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
195 chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
196 chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
197         release RELSTRING=${RELSTRING}
198 chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
199         install DESTDIR=/R RELSTRING=${RELSTRING}
200
201 cd ${CHROOTDIR}/R
202
203 sha256 FreeBSD-* > CHECKSUM.SHA256
204 md5 FreeBSD-* > CHECKSUM.MD5