]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
file: update to 5.34
[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_installworld=true
44 do_image=true
45 do_copyout_partition=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_copyout_partition=false
98                 shift
99                 ;;
100         -h)
101                 usage
102                 ;;
103         -i)
104                 do_image=false
105                 shift
106                 ;;
107         -k)
108                 do_kernel=false
109                 shift
110                 ;;
111         -n)
112                 do_clean=false
113                 shift
114                 ;;
115         -q)
116                 PPLEVEL=$(($PPLEVEL - 1))
117                 shift
118                 ;;
119         -v)
120                 PPLEVEL=$(($PPLEVEL + 1))
121                 shift
122                 ;;
123         -w)
124                 do_world=false
125                 shift
126                 ;;
127         -I)
128                 do_world=false
129                 do_kernel=false
130                 do_installworld=false
131                 do_installkernel=false
132                 do_prep_image=false
133                 do_image=true
134                 shift
135                 ;;
136         --)
137                 shift
138                 break
139         esac
140 done
141
142 if [ $# -gt 0 ] ; then
143         echo "$0: Extraneous arguments supplied"
144         usage
145 fi
146
147 #######################################################################
148 # And then it is as simple as that...
149
150 # File descriptor 3 is used for logging output, see pprint
151 exec 3>&1
152 set_defaults_and_export
153
154 if [ ! -d "${NANO_TOOLS}" ]; then
155         echo "NANO_TOOLS directory does not exist" 1>&2
156         exit 1
157 fi
158
159 if ! $do_clean; then
160         NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
161 fi
162
163 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
164
165 run_early_customize
166
167 if $do_world ; then
168         if $do_clean ; then
169                 clean_build
170         else
171                 pprint 2 "Using existing build tree (as instructed)"
172         fi
173         make_conf_build
174         build_world
175 else
176         pprint 2 "Skipping buildworld (as instructed)"
177 fi
178
179 if $do_kernel ; then
180         if ! $do_world ; then
181                 make_conf_build
182         fi
183         build_kernel
184 else
185         pprint 2 "Skipping buildkernel (as instructed)"
186 fi
187
188 if $do_installworld ; then
189     clean_world
190     make_conf_install
191     install_world
192     install_etc
193 else
194     pprint 2 "Skipping installworld (as instructed)"
195 fi
196
197 if ${do_native_xtools} ; then
198         native_xtools
199 fi
200 if ${do_prep_image} ; then
201         setup_nanobsd_etc
202 fi
203 if $do_installkernel ; then
204         install_kernel
205 else
206         pprint 2 "Skipping installkernel (as instructed)"
207 fi
208
209 if $do_prep_image ; then
210         run_customize
211         setup_nanobsd
212         prune_usr
213         run_late_customize
214         fixup_before_diskimage
215 else
216         pprint 2 "Skipping image prep (as instructed)"
217 fi
218 if $do_image ; then
219         create_diskimage
220 else
221         pprint 2 "Skipping image build (as instructed)"
222 fi
223 last_orders
224
225 pprint 1 "NanoBSD image ${NANO_NAME} completed"