-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnanobsd.sh
executable file
·340 lines (294 loc) · 7.2 KB
/
nanobsd.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/bin/sh
#
# Copyright (c) 2005 Poul-Henning Kamp.
# All rights reserved.
#
# 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.
#
# $FreeBSD: releng/8.1/tools/tools/nanobsd/nanobsd.sh 206537 2010-04-13 00:57:54Z imp $
#
set -e
# Where to find the NanoBSD-NG code base
# Default: The directory the script is being run from
if [ -z "${NANO_TOOLS}" ]; then
NANO_TOOLS=`dirname $0`
echo "NANO_TOOLS set to ${NANO_TOOLS}"
fi
if [ -d ${NANO_TOOLS} ] ; then
true
else
echo "NANO_TOOLS directory does not exist: ${NANO_TOOLS}" 1>&2
exit 1
fi
#######################################################################
#
# Pull in all of the function definitions.
#
#######################################################################
for FUNC in `find ${NANO_TOOLS}/functions -type f | grep -Ev '(CVS|\.svn|\.swp)'`; do
. ${FUNC}
done
#######################################################################
#
# All set up to go...
#
#######################################################################
usage () {
(
echo "Usage: $0 [-bfiknqvw] [-a target_arch] -t target_name"
echo " -a target cpu architecture (amd64/arm/i386/sparc64)"
echo " -b suppress builds (both kernel and world)"
echo " -f suppress code slice extraction"
echo " -i suppress disk image build"
echo " -k suppress buildkernel"
echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc"
echo " -q make output more quiet"
echo " -v make output more verbose"
echo " -w suppress buildworld"
echo " -t nanobsd target to build"
) 1>&2
exit 2
}
#######################################################################
# Parse arguments
do_clean=true
do_kernel=true
do_world=true
do_image=true
do_copyout_partition=true
set +e
args=`getopt bt:a:fhiknqvw $*`
if [ $? -ne 0 ] ; then
usage
exit 2
fi
set -e
set -- $args
for i
do
case "$i"
in
-b)
do_world=false
do_kernel=false
shift
;;
-k)
do_kernel=false
shift
;;
-t)
NANO_TARGET="$2"
shift
shift
;;
-a)
NANO_ARCH="$2"
shift
shift
;;
-f)
do_copyout_partition=false
shift
;;
-h)
usage
;;
-i)
do_image=false
shift
;;
-n)
do_clean=false
shift
;;
-q)
PPLEVEL=$(($PPLEVEL - 1))
shift
;;
-v)
PPLEVEL=$(($PPLEVEL + 1))
shift
;;
-w)
do_world=false
shift
;;
--)
shift
break
esac
done
if [ $# -gt 0 ] ; then
echo "$0: Extraneous arguments supplied"
usage
fi
if [ -z "${NANO_TARGET}" ]; then
echo "$0: You must specify a build target"
usage
fi
if [ -z "${NANO_ARCH}" ]; then
NANO_ARCH=`uname -p`
fi
case "${NANO_ARCH}"
in
amd64)
;;
arm)
;;
i386)
;;
sparc64)
;;
*)
echo "$0: Target architechture is not supported"
usage
esac
trap "nano_cleanup" EXIT
#######################################################################
#
# Pull in the defaut variable settings from:
# targets/default/nanobsd.conf
#
#######################################################################
. ${NANO_TOOLS}/targets/default/nanobsd.conf
#######################################################################
#
# Process the target configuration
#
#######################################################################
if [ ! -d ${NANO_TOOLS}/targets/${NANO_TARGET} ]; then
echo "Build target not found" 1>&2
exit 1
fi
if [ ! -e ${NANO_TOOLS}/targets/${NANO_TARGET}/nanobsd.conf ]; then
echo "Build target nanobsd.conf not found" 1>&2
exit 1
fi
. ${NANO_TOOLS}/targets/${NANO_TARGET}/nanobsd.conf
if [ -e ${NANO_TOOLS}/targets/${NANO_TARGET}/${NANO_ARCH}/nanobsd.conf ]; then
. ${NANO_TOOLS}/targets/${NANO_TARGET}/${NANO_ARCH}/nanobsd.conf
fi
#######################################################################
#
# Sanity Checks for build config.
#
#######################################################################
case "${NANO_IMAGE_TYPE}"
in
disk)
;;
cd)
;;
*)
echo "NANO_IMAGE_TYPE is invalid! Valid values are disk and cd" >&2
exit 1
esac
#######################################################################
# Setup and Export Internal variables
#
test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME}.${NANO_ARCH}
test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ}
test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ}
NANO_WORLDDIR=${NANO_OBJ}/_.w
NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
if $do_clean ; then
true
else
NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
fi
# Override user's NANO_DRIVE if they specified a NANO_LABEL
if [ ! -z "${NANO_LABEL}" ]; then
NANO_DRIVE=ufs/${NANO_LABEL}
fi
export MAKEOBJDIRPREFIX
export NANO_ARCH
export NANO_CFGDIR
export NANO_CODESIZE
export NANO_CONFSIZE
export NANO_CUSTOMIZE
export NANO_DATADIR
export NANO_DATASIZE
export NANO_DRIVE
export NANO_HEADS
export NANO_IMAGES
export NANO_IMGNAME
export NANO_LABEL
export NANO_MAKE_CONF_BUILD
export NANO_MAKE_CONF_INSTALL
export NANO_MEDIASIZE
export NANO_NAME
export NANO_NEWFS
export NANO_OBJ
export NANO_PMAKE
export NANO_SECTS
export NANO_SRC
export NANO_TOOLS
export NANO_WORLDDIR
export NANO_BOOT0CFG
export NANO_BOOT2CFG
export NANO_BOOTLOADER
#######################################################################
# And then it is as simple as that...
# File descriptor 3 is used for logging output, see pprint
exec 3>&1
NANO_STARTTIME=`date +%s`
pprint 1 "NanoBSD image ${NANO_NAME} build starting"
if $do_world ; then
if $do_clean ; then
clean_build
else
pprint 2 "Using existing build tree (as instructed)"
fi
make_conf_build
build_world
else
pprint 2 "Skipping buildworld (as instructed)"
fi
if $do_kernel ; then
if ! $do_world ; then
make_conf_build
fi
build_kernel
else
pprint 2 "Skipping buildkernel (as instructed)"
fi
clean_world
make_conf_install
install_world
install_etc
setup_nanobsd_etc
install_kernel
install_files
run_command_set "${NANO_CUSTOMIZE}"
run_command_set "${NANO_PKG_POST_CMDS}"
setup_nanobsd
prune_usr
run_command_set "${NANO_LATE_CUSTOMIZE}"
if $do_image ; then
create_${NANO_ARCH}_${NANO_IMAGE_TYPE}image
else
pprint 2 "Skipping image build (as instructed)"
fi
run_command_set "${NANO_LAST_ORDERS}"
pprint 1 "NanoBSD image ${NANO_NAME} completed"