]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - release/generate-release.sh
Fix multiple vulnerabilities of ntp.
[FreeBSD/releng/10.2.git] / release / generate-release.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2011 Nathan Whitehorn
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD$
28 #
29
30 # generate-release.sh: check out source trees, and build release components with
31 #  totally clean, fresh trees.
32 #
33 #  Usage: generate-release.sh svn-branch[@revision] scratch-dir
34 #
35 # Environment variables:
36 #  SVNROOTBASE: SVN base URL to FreeBSD repository (svn://svn.freebsd.org)
37 #  SVNROOTSRC:  URL to FreeBSD src tree (${SVNROOTBASE}/base)
38 #  SVNROOTDOC:  URL to FreeBSD doc tree (${SVNROOTBASE}/doc)
39 #  SVNROOTPORTS:URL to FreeBSD ports tree (${SVNROOTBASE}/ports)
40 #  BRANCHSRC:   branch name of src (svn-branch[@revision])
41 #  BRANCHDOC:   branch name of doc (head)
42 #  BRANCHPORTS: branch name of ports (head)
43 #  WORLD_FLAGS: optional flags to pass to buildworld (e.g. -j)
44 #  KERNEL_FLAGS: optional flags to pass to buildkernel (e.g. -j)
45 #
46
47 usage()
48 {
49         echo "Usage: $0 svn-branch[@revision] scratch-dir" 2>&1
50         exit 1
51 }
52
53 if [ $# -lt 2 ]; then
54         usage
55 fi
56
57 : ${SVNROOTBASE:=svn://svn.freebsd.org}
58 : ${SVNROOTSRC:=${SVNROOTBASE}/base}
59 : ${SVNROOTDOC:=${SVNROOTBASE}/doc}
60 : ${SVNROOTPORTS:=${SVNROOTBASE}/ports}
61 : ${SVNROOT:=${SVNROOTSRC}} # for backward compatibility
62 : ${SVN_CMD:=/usr/local/bin/svn}
63 BRANCHSRC=$1
64 : ${BRANCHDOC:=head}
65 : ${BRANCHPORTS:=head}
66 : ${WORLD_FLAGS:=${MAKE_FLAGS}}
67 : ${KERNEL_FLAGS:=${MAKE_FLAGS}}
68 : ${CHROOTDIR:=$2}
69  
70 if [ ! -r "${CHROOTDIR}" ]; then
71         echo "${CHROOTDIR}: scratch dir not found."
72         exit 1
73 fi
74
75 CHROOT_CMD="/usr/sbin/chroot ${CHROOTDIR}"
76 case ${TARGET} in
77 "")     ;;
78 *)      SETENV_TARGET="TARGET=$TARGET" ;;
79 esac
80 case ${TARGET_ARCH} in
81 "")     ;;
82 *)      SETENV_TARGET_ARCH="TARGET_ARCH=$TARGET_ARCH" ;;
83 esac
84 SETENV="env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin"
85 CROSSENV="${SETENV_TARGET} ${SETENV_TARGET_ARCH}"
86 WMAKE="make -C /usr/src ${WORLD_FLAGS}"
87 NWMAKE="${WMAKE} __MAKE_CONF=/dev/null SRCCONF=/dev/null"
88 KMAKE="make -C /usr/src ${KERNEL_FLAGS}"
89 RMAKE="make -C /usr/src/release"
90
91 if [ $(id -u) -ne 0 ]; then
92         echo "Needs to be run as root."
93         exit 1
94 fi
95
96 set -e # Everything must succeed
97
98 mkdir -p ${CHROOTDIR}/usr/src
99 ${SVN_CMD} co ${SVNROOT}/${BRANCHSRC} ${CHROOTDIR}/usr/src
100 ${SVN_CMD} co ${SVNROOTDOC}/${BRANCHDOC} ${CHROOTDIR}/usr/doc
101 ${SVN_CMD} co ${SVNROOTPORTS}/${BRANCHPORTS} ${CHROOTDIR}/usr/ports
102
103 ${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src ${WORLD_FLAGS} buildworld
104 ${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src installworld distribution DESTDIR=${CHROOTDIR}
105 mount -t devfs devfs ${CHROOTDIR}/dev
106 trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
107
108 if [ -d ${CHROOTDIR}/usr/doc ]; then 
109         cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
110
111         # Install docproj to build release documentation
112         ${CHROOT_CMD} /etc/rc.d/ldconfig forcerestart
113         ${CHROOT_CMD} /bin/sh -c \
114                 'make -C /usr/ports/textproc/docproj \
115                         BATCH=yes \
116                         WITHOUT_SVN=yes \
117                         WITHOUT_JADETEX=yes \
118                         WITHOUT_X11=yes \
119                         WITHOUT_PYTHON=yes \
120                         install'
121 fi
122
123 ${CHROOT_CMD} ${SETENV} ${CROSSENV} ${WMAKE} buildworld
124 ${CHROOT_CMD} ${SETENV} ${CROSSENV} ${KMAKE} buildkernel
125 ${CHROOT_CMD} ${SETENV} ${CROSSENV} ${RMAKE} release
126 ${CHROOT_CMD} ${SETENV} ${CROSSENV} ${RMAKE} install DESTDIR=/R