build.sh 3.52 KB
Newer Older
Shawn Webb's avatar
Shawn Webb committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
#-
# Copyright (c) 2019 HardenedBSD
# Author: Shawn Webb <shawn.webb@hardenedbsd.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

Shawn Webb's avatar
Shawn Webb committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
clean_build() {
	(
		set -ex

		cd ${HBSD_SRC}/release
		make \
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
		    clean
	)

	return 0
}

Shawn Webb's avatar
Shawn Webb committed
41
42
43
44
45
46
build_hardenedbsd() {
	(
		set -ex

		cd ${HBSD_SRC}
		make \
Shawn Webb's avatar
Shawn Webb committed
47
		    -j ${HBSD_NJOBS} \
Shawn Webb's avatar
Shawn Webb committed
48
49
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
Shawn Webb's avatar
Shawn Webb committed
50
		    ${HBSD_NOCLEAN} \
Shawn Webb's avatar
Shawn Webb committed
51
52
		    buildworld
		make \
Shawn Webb's avatar
Shawn Webb committed
53
		    -j ${HBSD_NJOBS} \
Shawn Webb's avatar
Shawn Webb committed
54
55
56
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
		    KERNCONF=${HBSD_KERNEL} \
Shawn Webb's avatar
Shawn Webb committed
57
		    ${HBSD_NOCLEAN} \
Shawn Webb's avatar
Shawn Webb committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
		    buildkernel
	)
	return ${?}
}

build_release() {
	(
		set -ex

		cd ${HBSD_SRC}/release
		make \
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
		    clean
		make \
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
		    obj
		make \
		    TARGET=${HBSD_TARGET} \
		    TARGET_ARCH=${HBSD_TARGET_ARCH} \
		    KERNCONF=${HBSD_KERNEL} \
		    NOPORTS=1 \
		    real-release
	)
	return ${?}
}

stage_release() {
	local f
	local file
Shawn Webb's avatar
Shawn Webb committed
89
	local res
Shawn Webb's avatar
Shawn Webb committed
90

Shawn Webb's avatar
Shawn Webb committed
91
92
93
94
95
96
97
98
	mkdir -p \
	    ${HBSD_STAGEDIR} \
	    ${HBSD_PUBDIR}

	for file in $(find ${HBSD_OBJRELDIR} -maxdepth 1 \
	    -name '*.iso' \
	    -o -name '*.img' \
	    -o -name 'MANIFEST'); do
Shawn Webb's avatar
Shawn Webb committed
99
100
		f=${file##*/}
		mv ${file} ${HBSD_STAGEDIR}/${f}
Shawn Webb's avatar
Shawn Webb committed
101
102
103
104
		res=${?}
		if [ ${res} -gt 0 ]; then
			return ${res}
		fi
Shawn Webb's avatar
Shawn Webb committed
105
		xz -kc9 ${HBSD_STAGEDIR}/${f} > ${HBSD_STAGEDIR}/${f}.xz
Shawn Webb's avatar
Shawn Webb committed
106
107
108
109
		res=${?}
		if [ ${res} -gt 0 ]; then
			return ${res}
		fi
Shawn Webb's avatar
Shawn Webb committed
110
	done
Shawn Webb's avatar
Shawn Webb committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124

	# No need to compress the .txz files
	for file in $(find ${HBSD_OBJRELDIR} -maxdepth 1 \
	    -name '*.txz'); do
		f=${file##*/}
		mv ${file} ${HBSD_STAGEDIR}/${f}
		res=${?}
		if [ ${res} -gt 0 ]; then
			return ${res}
		fi
	done

	(
		cd ${HBSD_SRC}
Shawn Webb's avatar
Shawn Webb committed
125
		git rev-parse HEAD > ${HBSD_STAGEDIR}/revision.txt
Shawn Webb's avatar
Shawn Webb committed
126
127
	)

Shawn Webb's avatar
Shawn Webb committed
128
129
130
131
132
	return 0
}

sign_release() {
	(
Shawn Webb's avatar
Shawn Webb committed
133
134
		set -ex

Shawn Webb's avatar
Shawn Webb committed
135
136
137
138
139
		cd ${HBSD_STAGEDIR}
		for file in $(find . \
		    -name '*.txz' \
		    -o -name '*.img' \
		    -o -name '*.iso' \
Shawn Webb's avatar
Shawn Webb committed
140
141
142
		    -o -name '*xz' \
		    -o -name 'MANIFEST' \
		    -o -name 'revision.txt'); do
Shawn Webb's avatar
Shawn Webb committed
143
144
145
146
147
148
149
150
151
152
153
			f=${file##*/}
			sha256 ${f} >> CHECKSUMS.SHA256
			sha512 ${f} >> CHECKSUMS.SHA512
			if [ ! -z "${HBSD_GPG_KEY}" ]; then
				gpg --sign -a --detach \
				    -u ${HBSD_GPG_KEY} \
				    -o ${f}.asc \
				    ${f}
			fi
		done
	)
Shawn Webb's avatar
Shawn Webb committed
154
	return ${?}
Shawn Webb's avatar
Shawn Webb committed
155
}