]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
MFV r284234:
[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 if $do_world ; then
143         if $do_clean ; then
144                 clean_build
145         else
146                 pprint 2 "Using existing build tree (as instructed)"
147         fi
148         make_conf_build
149         build_world
150 else
151         pprint 2 "Skipping buildworld (as instructed)"
152 fi
153
154 if $do_kernel ; then
155         if ! $do_world ; then
156                 make_conf_build
157         fi
158         build_kernel
159 else
160         pprint 2 "Skipping buildkernel (as instructed)"
161 fi
162
163 clean_world
164 make_conf_install
165 install_world
166 install_etc
167 if $do_native_xtools ; then
168         native_xtools
169 fi
170 setup_nanobsd_etc
171 if $do_installkernel ; then
172         install_kernel
173 else
174         pprint 2 "Skipping installkernel (as instructed)"
175 fi
176
177 run_customize
178 setup_nanobsd
179 prune_usr
180 run_late_customize
181 if $do_image ; then
182         create_diskimage
183 else
184         pprint 2 "Skipping image build (as instructed)"
185 fi
186 last_orders
187
188 pprint 1 "NanoBSD image ${NANO_NAME} completed"