]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - tools/tools/nanobsd/dhcpd/common
MFC r298881, 298882, 298883, 298885:
[FreeBSD/stable/10.git] / tools / tools / nanobsd / dhcpd / common
1 # $FreeBSD$
2
3 #-
4 # Copyright (c) 2014 Warner Losh. All Rights Reserved.
5 # Copyright (c) 2010 iXsystems, Inc., All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED.  IN NO EVENT SHALL iXsystems, Inc OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27 #
28 #
29 # This file is heavily derived from both Sam Leffler's Avilia config,
30 # as well as the BSDRP project's config file.  Neither of these have
31 # an explicit copyright/license statement, but are implicitly BSDL. This
32 # example has been taken from the FreeNAS project (an early version) and
33 # simplified to meet the needs of the example.
34 #
35
36 # NB: You want the other file
37
38 NANO_PMAKE="make -j $(sysctl -n hw.ncpu)"
39
40 NANO_CFG_BASE=$(pwd)
41 NANO_CFG_BASE=${NANO_CFG_BASE%/dhcpd}
42 NANO_SRC=$(pwd)
43 NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/dhcpd}
44 NANO_OBJ=${NANO_SRC}/../dhcpd/obj
45 # Where cust_pkg() finds packages to install
46 #XXX: Is this the right place?
47 #NANO_PORTS=$(realpath ${NANO_SRC}/../ports)
48 NANO_PORTS=/usr/ports
49 NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
50 NANO_DATADIR=${NANO_OBJ}/_.data
51 NANO_DATASIZE=40960
52 NANO_INIT_IMG2=0
53 unset MAKEOBJDIRPREFIX
54
55 # this to go into nanobsd.sh
56 NANO_PORTS=${NANO_PORTS:-/usr/ports}
57
58 customize_cmd cust_allow_ssh_root
59
60 add_etc_make_conf()
61 {
62         touch ${NANO_WORLDDIR}/etc/make.conf
63 }
64 customize_cmd add_etc_make_conf
65
66 clean_usr_local()
67 {
68         LOCAL_DIR=${NANO_WORLDDIR}/usr/local
69         pprint 2 "Clean and create world directory (${LOCAL_DIR})"
70         if rm -rf ${LOCAL_DIR}/ > /dev/null 2>&1 ; then
71                 true
72         else
73                 chflags -R noschg ${LOCAL_DIR}/
74                 rm -rf ${LOCAL_DIR}/
75         fi
76         for f in bin etc lib libdata libexec sbin share; do
77                 mkdir -p ${LOCAL_DIR}/$f
78         done
79 }
80 customize_cmd clean_usr_local
81
82 cust_install_machine_files()
83 {
84         echo "cd ${NANO_CFG_BASE}/Files"
85         cd ${NANO_CFG_BASE}/Files
86         find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${NANO_WORLDDIR}
87 }
88 customize_cmd cust_install_files
89 customize_cmd cust_install_machine_files 
90
91 buildenv()
92 {
93         cd ${NANO_SRC}
94         env __MAKE_CONF=${NANO_MAKE_CONF_BUILD} DESTDIR=${NANO_WORLDDIR} make buildenv
95 }
96
97 NANO_MAKEFS="makefs -B big \
98         -o bsize=4096,fsize=512,density=8192,optimization=space"
99 export NANO_MAKEFS
100
101 # NB: leave c++ enabled so devd can be built
102 CONF_BUILD="
103 WITHOUT_ACPI=true
104 WITHOUT_ATM=true
105 WITHOUT_AUDIT=true
106 WITHOUT_BIND_DNSSEC=true
107 WITHOUT_BIND_ETC=true
108 WITHOUT_BIND_LIBS_LWRES=true
109 WITHOUT_BLUETOOTH=true
110 WITHOUT_CALENDAR=true
111 WITHOUT_CVS=true
112 WITHOUT_DICT=true
113 WITHOUT_EXAMPLES=true
114 WITHOUT_FORTRAN=true
115 WITHOUT_GAMES=true
116 WITHOUT_GCOV=true
117 WITHOUT_GPIB=true
118 WITHOUT_HTML=true
119 WITHOUT_I4B=true
120 WITHOUT_IPFILTER=true
121 WITHOUT_IPX=true
122 WITHOUT_LIBKSE=true
123 WITHOUT_LOCALES=true
124 WITHOUT_LPR=true
125 WITHOUT_MAN=true
126 WITHOUT_NETCAT=true
127 WITHOUT_NIS=true
128 WITHOUT_NLS=true
129 WITHOUT_NS_CACHING=true
130 WITHOUT_OBJC=true
131 WITHOUT_PROFILE=true
132 WITHOUT_RCMDS=true
133 WITHOUT_SENDMAIL=true
134 WITHOUT_SHAREDOCS=true
135 WITHOUT_SYSCONS=true
136 WITHOUT_LIB32=true
137 "
138 CONF_INSTALL="$CONF_BUILD
139 INSTALL_NODEBUG=t
140 NOPORTDOCS=t
141 NO_INSTALL_MANPAGES=t
142 "
143 # The following would help...
144 # WITHOUT_TOOLCHAIN=true                can't build ports
145 # WITHOUT_INSTALLLIB=true               libgcc.a
146 #
147 # from the build
148 # WITHOUT_INFO=true                     makeinfo
149 # WITHOUT_RCS=true
150 PKG_ONLY_MAKE_CONF="
151 WITHOUT_TOOLCHAIN=true
152 WITHOUT_INSTALLLIB=true
153 WITHOUT_INFO=true
154 WITHOUT_RCS=true
155 "
156
157 NANO_PACKAGE_ONLY=1
158
159 # install a package from a pre-built binary
160 do_add_pkg ()
161 {
162         # Need to create ${NANO_OBJ}/ports in this add_pkg_${port} function
163         set -x
164         mkdir -p ${NANO_OBJ}/ports/distfiles
165         mkdir -p ${NANO_OBJ}/ports/packages
166         mkdir -p ${NANO_WORLDDIR}/usr/ports/packages
167         mkdir -p ${NANO_WORLDDIR}/usr/ports/distfiles
168         mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \
169             ${NANO_WORLDDIR}/usr/ports/packages
170         mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \
171             ${NANO_WORLDDIR}/usr/ports/distfiles
172         CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /usr/ports/packages/All/$1.txz
173         umount ${NANO_WORLDDIR}/usr/ports/distfiles
174         umount ${NANO_WORLDDIR}/usr/ports/packages
175         rmdir ${NANO_WORLDDIR}/usr/ports/packages
176         rmdir ${NANO_WORLDDIR}/usr/ports/distfiles
177         rmdir ${NANO_WORLDDIR}/usr/ports
178         set +x
179 }
180
181 # Build a port (with the side effect of creating a package)
182 do_add_port ()
183 {
184         local port_path
185         port_path=$1
186         shift
187         set -x
188         # Need to create ${NANO_OBJ}/ports in this add_port_${port} function
189         mkdir -p ${NANO_OBJ}/ports/distfiles
190         mkdir -p ${NANO_OBJ}/ports/packages
191         mkdir -p ${NANO_PORTS}/packages
192         mkdir -p ${NANO_PORTS}/distfiles
193         mkdir -p ${NANO_WORLDDIR}/usr/src
194         mkdir -p ${NANO_WORLDDIR}/usr/ports
195         mount -t nullfs -o noatime ${NANO_SRC} ${NANO_WORLDDIR}/usr/src
196         mount -t nullfs -o noatime ${NANO_PORTS} ${NANO_WORLDDIR}/usr/ports
197         mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \
198             ${NANO_WORLDDIR}/usr/ports/packages
199         mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \
200             ${NANO_WORLDDIR}/usr/ports/distfiles
201         mkdir -p ${NANO_WORLDDIR}/dev
202         mount -t devfs devfs ${NANO_WORLDDIR}/dev
203         mkdir -p ${NANO_WORLDDIR}/usr/workdir
204         cp /etc/resolv.conf ${NANO_WORLDDIR}/etc/resolv.conf
205         # OK, a little inefficient, but likely not enough to worry about.
206         CR ldconfig /lib /usr/lib /usr/local/lib
207         CR ldconfig -R
208         CR ldconfig -r
209 # Improvement: Don't know why package-recursive don't works here
210         CR "env UNAME_p=${NANO_ARCH} TARGET=${NANO_ARCH} \
211             TARGET_ARCH=${NANO_ARCH} PORTSDIR=${NANO_PORTS} make \
212             __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \
213             WRKDIRPREFIX=/usr/workdir -C /usr/ports/$port_path \
214             package-recursive BATCH=yes $* clean FORCE_PKG_REGISTER=t"
215         rm ${NANO_WORLDDIR}/etc/resolv.conf
216         rm -rf ${NANO_WORLDDIR}/usr/obj
217         rm -rf ${NANO_WORLDDIR}/usr/workdir
218         umount ${NANO_WORLDDIR}/dev
219         umount ${NANO_WORLDDIR}/usr/ports/packages
220         umount ${NANO_WORLDDIR}/usr/ports/distfiles
221         umount ${NANO_WORLDDIR}/usr/ports
222         umount ${NANO_WORLDDIR}/usr/src
223         set +x
224 }
225
226 # Need to check if this function works with cross-compiling architecture!!!!
227 # Recursive complex fonction: Generate one function for each ports
228 add_port () {
229     local port_path=$1
230     local port=`echo $1 | sed -e 's/\//_/'`
231     shift
232     # Check if package already exist
233     # Need to:
234     # 1. check ARCH of this package!
235     # 2. Add a trap
236     cd ${NANO_PORTS}/${port_path}
237     PKG_NAME=`env PORTSDIR=${NANO_PORTS} make __MAKE_CONF=${NANO_MAKE_CONF_BUILD} package-name` 
238     if [ -f ${NANO_OBJ}/ports/packages/All/${PKG_NAME}.txz ]; then
239         # Pkg file found: Generate add_pkg_NAME function
240         eval "
241             add_pkg_${port} () {
242                 do_add_pkg ${PKG_NAME}
243             }
244             customize_cmd add_pkg_${port}
245             "
246     else
247         # No pkg file: Generate add_port_NAME function
248         eval "
249             add_port_${port} () {
250                 do_add_port ${port_path} $*
251             }
252             customize_cmd add_port_${port}
253         "
254         NANO_PACKAGE_ONLY=0
255     fi
256 }
257
258 die()
259 {
260         echo "$*"
261         exit 1
262 }
263
264 # Automatically include the packaging port here so it is always first so it
265 # builds the port and adds the package so we can add other packages.
266 add_port ports-mgmt/pkg
267
268 rp=$(realpath ${NANO_OBJ}/)
269 __a=`mount | grep ${rp} | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'`
270 if [ -n "$__a" ]; then
271     echo "unmounting $__a"
272     umount $__a
273 fi
274
275 NANO_BOOTLOADER="boot/boot0"