xref: /freebsd/tools/tools/nanobsd/dhcpd/os-base (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1
2#-
3# Copyright (c) 2014 M. Warner Losh <imp@FreeBSD.org>
4# Copyright (c) 2010-2011 iXsystems, Inc.
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 iXsystems, Inc. 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# This file is heavily derived from both Sam Leffler's Avilia config,
28# as well as the BSDRP project's config file.  Neither of these have
29# an explicit copyright/license statement, but are implicitly BSDL. This
30# example has been taken from the FreeNAS project and simplified to meet
31# the needs of the example.
32#
33
34# Pull in common definitions.
35. common
36
37NANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18"
38
39# /var -> ~10MB (look through rc.initdiskless for the formula of how this
40# number is calculated out). Since we hope to run
41NANO_RAM_TMPVARSIZE=10240
42
43NANO_IMAGES=2
44FlashDevice generic 2g
45
46if [ "$DEBUG" = 1 ]; then
47	DEBUG_BUILD="
48DEBUG_FLAGS=		-g
49"
50else
51	DEBUG_INSTALL="
52INSTALL_NODEBUG=	t
53"
54fi
55
56CONF_INSTALL="$CONF_BUILD
57${DEBUG_BUILD}
58"
59CONF_INSTALL="$CONF_INSTALL
60${DEBUG_INSTALL}
61"
62
63add_port security/sudo
64add_port ftp/curl
65
66if [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
67 	CONF_INSTALL="${CONF_INSTALL}
68${PKG_ONLY_MAKE_CONF}
69"
70	echo "Automatically building a thin image with packages"
71else
72	echo "Automatically building a * * F A T * * image so we can build ports"
73fi
74
75VARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
76
77for var in $VARS; do
78	val=$(eval echo "\$$var")
79	if [ -n "$val" ]; then
80		CONF_INSTALL="${CONF_INSTALL}
81$var=$val"
82	fi
83done
84
85if [ "$PACKAGE_PREP_BUILD" = 1 ]; then
86	echo "Skipping post-package customize steps"
87	do_image=false
88else
89
90hack_nsswitch_conf ( )
91{
92	# Remove all references to NIS in the nsswitch.conf file
93	# Not sure this is still needed, but FreeNAS has it...
94	sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf
95	rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak
96}
97customize_cmd hack_nsswitch_conf
98
99save_build ( )
100{
101	VERSION_FILE=${NANO_WORLDDIR}/etc/version
102	if [ "${SVNREVISION}" = "${REVISION}" ]; then
103		echo "${NANO_NAME}" > "${VERSION_FILE}"
104	else
105		echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
106	fi
107}
108customize_cmd save_build
109
110remove_patch_divots ( )
111{
112	find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete
113}
114customize_cmd remove_patch_divots
115
116configure_mnt_md ( )
117{
118	mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt
119	echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size
120}
121customize_cmd configure_mnt_md
122
123shrink_md_fbsize()
124{
125	# We have a lot of little files on our memory disks. Let's decrease
126	# the block and frag size to fit more little files on them (this
127	# halves our space requirement by ~50% on /etc and /var on 8.x --
128	# and gives us more back on 9.x as the default block and frag size
129	# are 4 times larger).
130	sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
131		${NANO_WORLDDIR}/etc/rc.initdiskless
132}
133customize_cmd shrink_md_fbsize
134
135if [ "${DEBUG}" = 1 ]; then
136
137unmute_console_logging()
138{
139	# /var is small. Don't fill it up with messages from console.log
140	# because it's a chatty log.
141	sed -i '' -e 's/#console.info/console.info/' \
142			"${NANO_WORLDDIR}/etc/syslog.conf"
143}
144customize_cmd unmute_console_logging
145
146fi
147
148product_custom()
149{
150	gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel
151
152	# kill includes (saves 14MB)
153	find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f
154
155	# kill docs (saves 22MB)
156	rm -rf ${NANO_WORLDDIR}/usr/local/share/doc
157	rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc
158
159	# and info (2MB)
160	rm -rf ${NANO_WORLDDIR}/usr/local/info
161
162	# and man pages (4.4MB)
163	rm -rf ${NANO_WORLDDIR}/usr/local/man
164
165	# and examples (1.7M)
166	rm -rf ${NANO_WORLDDIR}/usr/local/share/examples
167
168	# and groff_fonts junk (3MB)
169	rm -rf ${NANO_WORLDDIR}/usr/share/groff_font
170	rm -rf ${NANO_WORLDDIR}/usr/share/tmac
171	rm -rf ${NANO_WORLDDIR}/usr/share/me
172
173	# Kill all .a's and .la's that are installed (20MB+)
174	find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete
175
176	# magic.mgc is just a speed optimization.  Kill it for 1.7MB
177	rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc
178
179	# Last second tweaks
180	chown -R root:wheel ${NANO_WORLDDIR}/root
181	chmod 0755 ${NANO_WORLDDIR}/root/*
182	chmod 0755 ${NANO_WORLDDIR}/*
183	chown -R root:wheel ${NANO_WORLDDIR}/etc
184	chown -R root:wheel ${NANO_WORLDDIR}/boot
185	chown root:wheel ${NANO_WORLDDIR}/
186	chown root:wheel ${NANO_WORLDDIR}/usr
187	find ${NANO_WORLDDIR} -type f -name "*~" -delete
188	find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete
189	find ${NANO_WORLDDIR} -type f -name "*.service" -delete
190}
191late_customize_cmd product_custom
192
193fi # [ $PACKAGE_PREP_BUILD = 1 ]
194