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