]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
zfs: merge openzfs/zfs@9cd71c860 (master)
[FreeBSD/FreeBSD.git] / tools / tools / nanobsd / nanobsd.sh
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
30 set -e
31
32 nanobsd_sh=`realpath $0`
33 topdir=`dirname ${nanobsd_sh}`
34 . "${topdir}/defaults.sh"
35
36 #######################################################################
37 # Parse arguments
38
39 do_clean=true
40 do_kernel=true
41 do_installkernel=true
42 do_world=true
43 do_code=true
44 do_installworld=true
45 do_image=true
46 do_native_xtools=false
47 do_prep_image=true
48
49 # Pull in legacy stuff for now automatically
50 . "${topdir}/legacy.sh"
51
52 set +e
53 args=`getopt BKXWbc:fhiIknqvw $*`
54 if [ $? -ne 0 ] ; then
55         usage
56         exit 2
57 fi
58 set -e
59
60 set -- $args
61 for i
62 do
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
141 done
142
143 if [ $# -gt 0 ] ; then
144         echo "$0: Extraneous arguments supplied"
145         usage
146 fi
147
148 #######################################################################
149 # And then it is as simple as that...
150
151 # File descriptor 3 is used for logging output, see pprint
152 exec 3>&1
153 set_defaults_and_export
154
155 if [ ! -d "${NANO_TOOLS}" ]; then
156         echo "NANO_TOOLS directory does not exist" 1>&2
157         exit 1
158 fi
159
160 if ! $do_clean; then
161         NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
162 fi
163
164 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
165
166 run_early_customize
167
168 if $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
176 else
177         pprint 2 "Skipping buildworld (as instructed)"
178 fi
179
180 if $do_kernel ; then
181         if ! $do_world ; then
182                 make_conf_build
183         fi
184         build_kernel
185 else
186         pprint 2 "Skipping buildkernel (as instructed)"
187 fi
188
189 if $do_installworld ; then
190     clean_world
191     make_conf_install
192     install_world
193     install_etc
194 else
195     pprint 2 "Skipping installworld (as instructed)"
196 fi
197
198 if ${do_native_xtools} ; then
199         native_xtools
200 fi
201 if ${do_prep_image} ; then
202         setup_nanobsd_etc
203 fi
204 if $do_installkernel ; then
205         install_kernel
206 else
207         pprint 2 "Skipping installkernel (as instructed)"
208 fi
209
210 if $do_prep_image ; then
211         run_customize
212         setup_nanobsd
213         prune_usr
214         run_late_customize
215         fixup_before_diskimage
216 else
217         pprint 2 "Skipping image prep (as instructed)"
218 fi
219 if $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
227 else
228         pprint 2 "Skipping code and image build (as instructed)"
229 fi
230 last_orders
231
232 pprint 1 "NanoBSD image ${NANO_NAME} completed"