]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
MFV r306669:
[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_image=true
44 do_copyout_partition=true
45 do_native_xtools=false
46
47 set +e
48 args=`getopt KXbc:fhiknqvw $*`
49 if [ $? -ne 0 ] ; then
50         usage
51         exit 2
52 fi
53 set -e
54
55 set -- $args
56 for i
57 do
58         case "$i"
59         in
60         -K)
61                 do_installkernel=false
62                 shift
63                 ;;
64         -X)
65                 do_native_xtools=true
66                 shift
67                 ;;
68         -b)
69                 do_world=false
70                 do_kernel=false
71                 shift
72                 ;;
73         -c)
74                 # Make config file path available to the config file
75                 # itself so that it can access additional files relative
76                 # to its own location.
77                 NANO_CONFIG=$2
78                 . "$2"
79                 shift
80                 shift
81                 ;;
82         -f)
83                 do_copyout_partition=false
84                 shift
85                 ;;
86         -h)
87                 usage
88                 ;;
89         -i)
90                 do_image=false
91                 shift
92                 ;;
93         -k)
94                 do_kernel=false
95                 shift
96                 ;;
97         -n)
98                 do_clean=false
99                 shift
100                 ;;
101         -q)
102                 PPLEVEL=$(($PPLEVEL - 1))
103                 shift
104                 ;;
105         -v)
106                 PPLEVEL=$(($PPLEVEL + 1))
107                 shift
108                 ;;
109         -w)
110                 do_world=false
111                 shift
112                 ;;
113         --)
114                 shift
115                 break
116         esac
117 done
118
119 if [ $# -gt 0 ] ; then
120         echo "$0: Extraneous arguments supplied"
121         usage
122 fi
123
124 #######################################################################
125 # And then it is as simple as that...
126
127 # File descriptor 3 is used for logging output, see pprint
128 exec 3>&1
129 set_defaults_and_export
130
131 if [ ! -d "${NANO_TOOLS}" ]; then
132         echo "NANO_TOOLS directory does not exist" 1>&2
133         exit 1
134 fi
135
136 if ! $do_clean; then
137         NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
138 fi
139
140 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
141
142 run_early_customize
143
144 if $do_world ; then
145         if $do_clean ; then
146                 clean_build
147         else
148                 pprint 2 "Using existing build tree (as instructed)"
149         fi
150         make_conf_build
151         build_world
152 else
153         pprint 2 "Skipping buildworld (as instructed)"
154 fi
155
156 if $do_kernel ; then
157         if ! $do_world ; then
158                 make_conf_build
159         fi
160         build_kernel
161 else
162         pprint 2 "Skipping buildkernel (as instructed)"
163 fi
164
165 clean_world
166 make_conf_install
167 install_world
168 install_etc
169 if $do_native_xtools ; then
170         native_xtools
171 fi
172 setup_nanobsd_etc
173 if $do_installkernel ; then
174         install_kernel
175 else
176         pprint 2 "Skipping installkernel (as instructed)"
177 fi
178
179 run_customize
180 setup_nanobsd
181 prune_usr
182 run_late_customize
183 fixup_before_diskimage
184 if $do_image ; then
185         create_diskimage
186 else
187         pprint 2 "Skipping image build (as instructed)"
188 fi
189 last_orders
190
191 pprint 1 "NanoBSD image ${NANO_NAME} completed"