generate-release.sh revision 246283
1219508Snwhitehorn#!/bin/sh
2219508Snwhitehorn
3219508Snwhitehorn# generate-release.sh: check out source trees, and build release components with
4219610Snwhitehorn#  totally clean, fresh trees.
5219508Snwhitehorn#
6246283Shrs#  Usage: generate-release.sh svn-branch[@revision] scratch-dir
7219508Snwhitehorn#
8219508Snwhitehorn# Environment variables:
9246283Shrs#  SVNROOTBASE: SVN base URL to FreeBSD repository (svn://svn.freebsd.org)
10246283Shrs#  SVNROOTSRC:  URL to FreeBSD src tree (${SVNROOTBASE}/base)
11246283Shrs#  SVNROOTDOC:  URL to FreeBSD doc tree (${SVNROOTBASE}/doc)
12246283Shrs#  SVNROOTPORTS:URL to FreeBSD ports tree (${SVNROOTBASE}/ports)
13246283Shrs#  BRANCHSRC:   branch name of src (svn-branch[@revision])
14246283Shrs#  BRANCHDOC:   branch name of doc (head)
15246283Shrs#  BRANCHPORTS: branch name of ports (head)
16246283Shrs#  WORLD_FLAGS: optional flags to pass to buildworld (e.g. -j)
17246283Shrs#  KERNEL_FLAGS: optional flags to pass to buildkernel (e.g. -j)
18219508Snwhitehorn#
19219508Snwhitehorn# $FreeBSD: head/release/generate-release.sh 246283 2013-02-03 10:26:24Z hrs $
20219508Snwhitehorn#
21219508Snwhitehorn
22230106Sglebiususage()
23230106Sglebius{
24246283Shrs	echo "Usage: $0 svn-branch[@revision] scratch-dir" 2>&1
25230106Sglebius	exit 1
26230106Sglebius}
27230106Sglebius
28230106Sglebiusif [ $# -lt 2 ]; then
29230106Sglebius	usage
30230106Sglebiusfi
31230106Sglebius
32246283Shrs: ${SVNROOTBASE:=svn://svn.freebsd.org}
33246283Shrs: ${SVNROOTSRC:=${SVNROOTBASE}/base}
34246283Shrs: ${SVNROOTDOC:=${SVNROOTBASE}/doc}
35246283Shrs: ${SVNROOTPORTS:=${SVNROOTBASE}/ports}
36246283Shrs: ${SVNROOT:=${SVNROOTSRC}} # for backward compatibility
37246283Shrs: ${SVN_CMD:=/usr/local/bin/svn}
38246283ShrsBRANCHSRC=$1
39246283Shrs: ${BRANCHDOC:=head}
40246283Shrs: ${BRANCHPORTS:=head}
41246283Shrs: ${WORLD_FLAGS:=${MAKE_FLAGS}}
42246283Shrs: ${KERNEL_FLAGS:=${MAKE_FLAGS}}
43246283Shrs: ${CHROOTDIR:=$2}
44246283Shrs 
45246283Shrsif [ ! -r "${CHROOTDIR}" ]; then
46246283Shrs	echo "${CHROOTDIR}: scratch dir not found."
47246283Shrs	exit 1
48246283Shrsfi
49246283Shrs
50246283ShrsCHROOT_CMD="/usr/sbin/chroot ${CHROOTDIR}"
51246283Shrscase ${TARGET} in
52246283Shrs"")	;;
53246283Shrs*)	SETENV_TARGET="TARGET=$TARGET" ;;
54246283Shrsesac
55246283Shrscase ${TARGET_ARCH} in
56246283Shrs"")	;;
57246283Shrs*)	SETENV_TARGET_ARCH="TARGET_ARCH=$TARGET_ARCH" ;;
58246283Shrsesac
59246283ShrsSETENV="env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin"
60246283ShrsCROSSENV="${SETENV_TARGET} ${SETENV_TARGET_ARCH}"
61246283ShrsWMAKE="make -C /usr/src ${WORLD_FLAGS}"
62246283ShrsNWMAKE="${WMAKE} __MAKE_CONF=/dev/null SRCCONF=/dev/null"
63246283ShrsKMAKE="make -C /usr/src ${KERNEL_FLAGS}"
64246283ShrsRMAKE="make -C /usr/src/release"
65246283Shrs
66240967Sgjbif [ $(id -u) -ne 0 ]; then
67240967Sgjb	echo "Needs to be run as root."
68240967Sgjb	exit 1
69240967Sgjbfi
70240967Sgjb
71221510Snwhitehornset -e # Everything must succeed
72221510Snwhitehorn
73246283Shrsmkdir -p ${CHROOTDIR}/usr/src
74246283Shrs${SVN_CMD} co ${SVNROOT}/${BRANCHSRC} ${CHROOTDIR}/usr/src
75246283Shrs${SVN_CMD} co ${SVNROOTDOC}/${BRANCHDOC} ${CHROOTDIR}/usr/doc
76246283Shrs${SVN_CMD} co ${SVNROOTPORTS}/${BRANCHPORTS} ${CHROOTDIR}/usr/ports
77230107Sglebius
78246283Shrs${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src ${WORLD_FLAGS} buildworld
79246283Shrs${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src installworld distribution DESTDIR=${CHROOTDIR}
80246283Shrsmount -t devfs devfs ${CHROOTDIR}/dev
81246283Shrstrap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
82230107Sglebius
83246283Shrsif [ -d ${CHROOTDIR}/usr/doc ]; then 
84246283Shrs	cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
85219508Snwhitehorn
86240586Sgjb	# Install docproj to build release documentation
87246283Shrs	${CHROOT_CMD} /bin/sh -c \
88246283Shrs		'make -C /usr/ports/textproc/docproj \
89246283Shrs			BATCH=yes \
90246283Shrs			WITHOUT_SVN=yes \
91246283Shrs			WITHOUT_JADETEX=yes \
92246283Shrs			WITHOUT_X11=yes \
93246283Shrs			WITHOUT_PYTHON=yes \
94246283Shrs			install'
95219508Snwhitehornfi
96219610Snwhitehorn
97246283Shrs${CHROOT_CMD} ${SETENV} ${CROSSENV} ${WMAKE} buildworld
98246283Shrs${CHROOT_CMD} ${SETENV} ${CROSSENV} ${KMAKE} buildkernel
99246283Shrs${CHROOT_CMD} ${SETENV} ${CROSSENV} ${RMAKE} release
100246283Shrs${CHROOT_CMD} ${SETENV} ${CROSSENV} ${RMAKE} install DESTDIR=/R
101