xref: /freebsd/tools/tools/nanobsd/dhcpd/os-base (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1c9cab7f5SWarner Losh
2c9cab7f5SWarner Losh#-
3*f86e6000SWarner Losh# Copyright (c) 2014 M. Warner Losh <imp@FreeBSD.org>
4a2732476SWarner Losh# Copyright (c) 2010-2011 iXsystems, Inc.
5c9cab7f5SWarner Losh#
6c9cab7f5SWarner Losh# Redistribution and use in source and binary forms, with or without
7c9cab7f5SWarner Losh# modification, are permitted provided that the following conditions
8c9cab7f5SWarner Losh# are met:
9c9cab7f5SWarner Losh# 1. Redistributions of source code must retain the above copyright
10c9cab7f5SWarner Losh#    notice, this list of conditions and the following disclaimer.
11c9cab7f5SWarner Losh# 2. Redistributions in binary form must reproduce the above copyright
12c9cab7f5SWarner Losh#    notice, this list of conditions and the following disclaimer in the
13c9cab7f5SWarner Losh#    documentation and/or other materials provided with the distribution.
14c9cab7f5SWarner Losh#
15c9cab7f5SWarner Losh# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16c9cab7f5SWarner Losh# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17c9cab7f5SWarner Losh# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c9cab7f5SWarner Losh# ARE DISCLAIMED.  IN NO EVENT SHALL iXsystems, Inc. OR CONTRIBUTORS BE LIABLE
19c9cab7f5SWarner Losh# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c9cab7f5SWarner Losh# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c9cab7f5SWarner Losh# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c9cab7f5SWarner Losh# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c9cab7f5SWarner Losh# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c9cab7f5SWarner Losh# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c9cab7f5SWarner Losh# SUCH DAMAGE.
26c9cab7f5SWarner Losh#
27c9cab7f5SWarner Losh# This file is heavily derived from both Sam Leffler's Avilia config,
28c9cab7f5SWarner Losh# as well as the BSDRP project's config file.  Neither of these have
29c9cab7f5SWarner Losh# an explicit copyright/license statement, but are implicitly BSDL. This
30c9cab7f5SWarner Losh# example has been taken from the FreeNAS project and simplified to meet
31c9cab7f5SWarner Losh# the needs of the example.
32c9cab7f5SWarner Losh#
33c9cab7f5SWarner Losh
34c9cab7f5SWarner Losh# Pull in common definitions.
35c9cab7f5SWarner Losh. common
36c9cab7f5SWarner Losh
37c9cab7f5SWarner LoshNANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18"
38c9cab7f5SWarner Losh
39c9cab7f5SWarner Losh# /var -> ~10MB (look through rc.initdiskless for the formula of how this
40c9cab7f5SWarner Losh# number is calculated out). Since we hope to run
41c9cab7f5SWarner LoshNANO_RAM_TMPVARSIZE=10240
42c9cab7f5SWarner Losh
43c9cab7f5SWarner LoshNANO_IMAGES=2
44c9cab7f5SWarner LoshFlashDevice generic 2g
45c9cab7f5SWarner Losh
46c9cab7f5SWarner Loshif [ "$DEBUG" = 1 ]; then
47c9cab7f5SWarner Losh	DEBUG_BUILD="
48c9cab7f5SWarner LoshDEBUG_FLAGS=		-g
49c9cab7f5SWarner Losh"
50c9cab7f5SWarner Loshelse
51c9cab7f5SWarner Losh	DEBUG_INSTALL="
52c9cab7f5SWarner LoshINSTALL_NODEBUG=	t
53c9cab7f5SWarner Losh"
54c9cab7f5SWarner Loshfi
55c9cab7f5SWarner Losh
56c9cab7f5SWarner LoshCONF_INSTALL="$CONF_BUILD
57c9cab7f5SWarner Losh${DEBUG_BUILD}
58c9cab7f5SWarner Losh"
59c9cab7f5SWarner LoshCONF_INSTALL="$CONF_INSTALL
60c9cab7f5SWarner Losh${DEBUG_INSTALL}
61c9cab7f5SWarner Losh"
62c9cab7f5SWarner Losh
63c9cab7f5SWarner Loshadd_port security/sudo
64c9cab7f5SWarner Loshadd_port ftp/curl
65c9cab7f5SWarner Losh
66c9cab7f5SWarner Loshif [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
67c9cab7f5SWarner Losh 	CONF_INSTALL="${CONF_INSTALL}
68c9cab7f5SWarner Losh${PKG_ONLY_MAKE_CONF}
69c9cab7f5SWarner Losh"
70c9cab7f5SWarner Losh	echo "Automatically building a thin image with packages"
71c9cab7f5SWarner Loshelse
72c9cab7f5SWarner Losh	echo "Automatically building a * * F A T * * image so we can build ports"
73c9cab7f5SWarner Loshfi
74c9cab7f5SWarner Losh
75c9cab7f5SWarner LoshVARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
76c9cab7f5SWarner Losh
77c9cab7f5SWarner Loshfor var in $VARS; do
78c9cab7f5SWarner Losh	val=$(eval echo "\$$var")
79c9cab7f5SWarner Losh	if [ -n "$val" ]; then
80c9cab7f5SWarner Losh		CONF_INSTALL="${CONF_INSTALL}
81c9cab7f5SWarner Losh$var=$val"
82c9cab7f5SWarner Losh	fi
83c9cab7f5SWarner Loshdone
84c9cab7f5SWarner Losh
85c9cab7f5SWarner Loshif [ "$PACKAGE_PREP_BUILD" = 1 ]; then
86c9cab7f5SWarner Losh	echo "Skipping post-package customize steps"
87c9cab7f5SWarner Losh	do_image=false
88c9cab7f5SWarner Loshelse
89c9cab7f5SWarner Losh
90c9cab7f5SWarner Loshhack_nsswitch_conf ( )
91c9cab7f5SWarner Losh{
92c9cab7f5SWarner Losh	# Remove all references to NIS in the nsswitch.conf file
93c9cab7f5SWarner Losh	# Not sure this is still needed, but FreeNAS has it...
94c9cab7f5SWarner Losh	sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf
95c9cab7f5SWarner Losh	rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak
96c9cab7f5SWarner Losh}
97c9cab7f5SWarner Loshcustomize_cmd hack_nsswitch_conf
98c9cab7f5SWarner Losh
99c9cab7f5SWarner Loshsave_build ( )
100c9cab7f5SWarner Losh{
101c9cab7f5SWarner Losh	VERSION_FILE=${NANO_WORLDDIR}/etc/version
102c9cab7f5SWarner Losh	if [ "${SVNREVISION}" = "${REVISION}" ]; then
103c9cab7f5SWarner Losh		echo "${NANO_NAME}" > "${VERSION_FILE}"
104c9cab7f5SWarner Losh	else
105c9cab7f5SWarner Losh		echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
106c9cab7f5SWarner Losh	fi
107c9cab7f5SWarner Losh}
108c9cab7f5SWarner Loshcustomize_cmd save_build
109c9cab7f5SWarner Losh
110c9cab7f5SWarner Loshremove_patch_divots ( )
111c9cab7f5SWarner Losh{
112c9cab7f5SWarner Losh	find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete
113c9cab7f5SWarner Losh}
114c9cab7f5SWarner Loshcustomize_cmd remove_patch_divots
115c9cab7f5SWarner Losh
116c9cab7f5SWarner Loshconfigure_mnt_md ( )
117c9cab7f5SWarner Losh{
118c9cab7f5SWarner Losh	mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt
119c9cab7f5SWarner Losh	echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size
120c9cab7f5SWarner Losh}
121c9cab7f5SWarner Loshcustomize_cmd configure_mnt_md
122c9cab7f5SWarner Losh
123c9cab7f5SWarner Loshshrink_md_fbsize()
124c9cab7f5SWarner Losh{
125c9cab7f5SWarner Losh	# We have a lot of little files on our memory disks. Let's decrease
126c9cab7f5SWarner Losh	# the block and frag size to fit more little files on them (this
127c9cab7f5SWarner Losh	# halves our space requirement by ~50% on /etc and /var on 8.x --
128c9cab7f5SWarner Losh	# and gives us more back on 9.x as the default block and frag size
129c9cab7f5SWarner Losh	# are 4 times larger).
130c9cab7f5SWarner Losh	sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
131c9cab7f5SWarner Losh		${NANO_WORLDDIR}/etc/rc.initdiskless
132c9cab7f5SWarner Losh}
133c9cab7f5SWarner Loshcustomize_cmd shrink_md_fbsize
134c9cab7f5SWarner Losh
135c9cab7f5SWarner Loshif [ "${DEBUG}" = 1 ]; then
136c9cab7f5SWarner Losh
137c9cab7f5SWarner Loshunmute_console_logging()
138c9cab7f5SWarner Losh{
139c9cab7f5SWarner Losh	# /var is small. Don't fill it up with messages from console.log
140c9cab7f5SWarner Losh	# because it's a chatty log.
141c9cab7f5SWarner Losh	sed -i '' -e 's/#console.info/console.info/' \
142c9cab7f5SWarner Losh			"${NANO_WORLDDIR}/etc/syslog.conf"
143c9cab7f5SWarner Losh}
144c9cab7f5SWarner Loshcustomize_cmd unmute_console_logging
145c9cab7f5SWarner Losh
146c9cab7f5SWarner Loshfi
147c9cab7f5SWarner Losh
148af5905f4SWarner Loshproduct_custom()
149c9cab7f5SWarner Losh{
150c9cab7f5SWarner Losh	gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel
151c9cab7f5SWarner Losh
152c9cab7f5SWarner Losh	# kill includes (saves 14MB)
153c9cab7f5SWarner Losh	find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f
154c9cab7f5SWarner Losh
155c9cab7f5SWarner Losh	# kill docs (saves 22MB)
156c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/local/share/doc
157c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc
158c9cab7f5SWarner Losh
159c9cab7f5SWarner Losh	# and info (2MB)
160c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/local/info
161c9cab7f5SWarner Losh
162c9cab7f5SWarner Losh	# and man pages (4.4MB)
163c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/local/man
164c9cab7f5SWarner Losh
165c9cab7f5SWarner Losh	# and examples (1.7M)
166c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/local/share/examples
167c9cab7f5SWarner Losh
168c9cab7f5SWarner Losh	# and groff_fonts junk (3MB)
169c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/share/groff_font
170c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/share/tmac
171c9cab7f5SWarner Losh	rm -rf ${NANO_WORLDDIR}/usr/share/me
172c9cab7f5SWarner Losh
173c9cab7f5SWarner Losh	# Kill all .a's and .la's that are installed (20MB+)
174c9cab7f5SWarner Losh	find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete
175c9cab7f5SWarner Losh
176c9cab7f5SWarner Losh	# magic.mgc is just a speed optimization.  Kill it for 1.7MB
177c9cab7f5SWarner Losh	rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc
178c9cab7f5SWarner Losh
179c9cab7f5SWarner Losh	# Last second tweaks
180c9cab7f5SWarner Losh	chown -R root:wheel ${NANO_WORLDDIR}/root
181c9cab7f5SWarner Losh	chmod 0755 ${NANO_WORLDDIR}/root/*
182c9cab7f5SWarner Losh	chmod 0755 ${NANO_WORLDDIR}/*
183c9cab7f5SWarner Losh	chown -R root:wheel ${NANO_WORLDDIR}/etc
184c9cab7f5SWarner Losh	chown -R root:wheel ${NANO_WORLDDIR}/boot
185c9cab7f5SWarner Losh	chown root:wheel ${NANO_WORLDDIR}/
186c9cab7f5SWarner Losh	chown root:wheel ${NANO_WORLDDIR}/usr
187c9cab7f5SWarner Losh	find ${NANO_WORLDDIR} -type f -name "*~" -delete
188c9cab7f5SWarner Losh	find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete
189c9cab7f5SWarner Losh	find ${NANO_WORLDDIR} -type f -name "*.service" -delete
190c9cab7f5SWarner Losh}
191af5905f4SWarner Loshlate_customize_cmd product_custom
192c9cab7f5SWarner Losh
193c9cab7f5SWarner Loshfi # [ $PACKAGE_PREP_BUILD = 1 ]
194