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