xref: /freebsd/tools/tools/nanobsd/nanobsd.sh (revision 19261079)
1#!/bin/sh
2#
3# Copyright (c) 2005 Poul-Henning Kamp.
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
30set -e
31
32nanobsd_sh=`realpath $0`
33topdir=`dirname ${nanobsd_sh}`
34. "${topdir}/defaults.sh"
35
36#######################################################################
37# Parse arguments
38
39do_clean=true
40do_kernel=true
41do_installkernel=true
42do_world=true
43do_code=true
44do_installworld=true
45do_image=true
46do_native_xtools=false
47do_prep_image=true
48
49# Pull in legacy stuff for now automatically
50. "${topdir}/legacy.sh"
51
52set +e
53args=`getopt BKXWbc:fhiIknqvw $*`
54if [ $? -ne 0 ] ; then
55	usage
56	exit 2
57fi
58set -e
59
60set -- $args
61for i
62do
63	case "$i"
64	in
65	-B)
66		do_installworld=false
67		do_installkernel=false
68		shift
69		;;
70	-K)
71		do_installkernel=false
72		shift
73		;;
74	-X)
75		do_native_xtools=true
76		shift
77		;;
78	-W)
79		do_installworld=false
80		shift
81		;;
82	-b)
83		do_world=false
84		do_kernel=false
85		shift
86		;;
87	-c)
88		# Make config file path available to the config file
89		# itself so that it can access additional files relative
90		# to its own location.
91		NANO_CONFIG=$2
92		. "$2"
93		shift
94		shift
95		;;
96	-f)
97		do_code=false
98		do_image=false
99		shift
100		;;
101	-h)
102		usage
103		;;
104	-i)
105		do_image=false
106		shift
107		;;
108	-k)
109		do_kernel=false
110		shift
111		;;
112	-n)
113		do_clean=false
114		shift
115		;;
116	-q)
117		PPLEVEL=$(($PPLEVEL - 1))
118		shift
119		;;
120	-v)
121		PPLEVEL=$(($PPLEVEL + 1))
122		shift
123		;;
124	-w)
125		do_world=false
126		shift
127		;;
128	-I)
129		do_world=false
130		do_kernel=false
131		do_installworld=false
132		do_installkernel=false
133		do_prep_image=false
134		do_image=true
135		shift
136		;;
137	--)
138		shift
139		break
140	esac
141done
142
143if [ $# -gt 0 ] ; then
144	echo "$0: Extraneous arguments supplied"
145	usage
146fi
147
148#######################################################################
149# And then it is as simple as that...
150
151# File descriptor 3 is used for logging output, see pprint
152exec 3>&1
153set_defaults_and_export
154
155if [ ! -d "${NANO_TOOLS}" ]; then
156	echo "NANO_TOOLS directory does not exist" 1>&2
157	exit 1
158fi
159
160if ! $do_clean; then
161	NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
162fi
163
164pprint 1 "NanoBSD image ${NANO_NAME} build starting"
165
166run_early_customize
167
168if $do_world ; then
169	if $do_clean ; then
170		clean_build
171	else
172		pprint 2 "Using existing build tree (as instructed)"
173	fi
174	make_conf_build
175	build_world
176else
177	pprint 2 "Skipping buildworld (as instructed)"
178fi
179
180if $do_kernel ; then
181	if ! $do_world ; then
182		make_conf_build
183	fi
184	build_kernel
185else
186	pprint 2 "Skipping buildkernel (as instructed)"
187fi
188
189if $do_installworld ; then
190    clean_world
191    make_conf_install
192    install_world
193    install_etc
194else
195    pprint 2 "Skipping installworld (as instructed)"
196fi
197
198if ${do_native_xtools} ; then
199	native_xtools
200fi
201if ${do_prep_image} ; then
202	setup_nanobsd_etc
203fi
204if $do_installkernel ; then
205	install_kernel
206else
207	pprint 2 "Skipping installkernel (as instructed)"
208fi
209
210if $do_prep_image ; then
211	run_customize
212	setup_nanobsd
213	prune_usr
214	run_late_customize
215	fixup_before_diskimage
216else
217	pprint 2 "Skipping image prep (as instructed)"
218fi
219if $do_code ; then
220	calculate_partitioning
221	create_code_slice
222	if $do_image ; then
223		create_diskimage
224	else
225		pprint 2 "Skipping image build (as instructed)"
226	fi
227else
228	pprint 2 "Skipping code and image build (as instructed)"
229fi
230last_orders
231
232pprint 1 "NanoBSD image ${NANO_NAME} completed"
233