1264656Simp# $FreeBSD$
2264656Simp
3264656Simp#-
4264656Simp# Copyright (c) 2014 Warner Losh. All Rights Reserved.
5264656Simp# Copyright (c) 2010-2011 iXsystems, Inc., All rights reserved.
6264656Simp#
7264656Simp# Redistribution and use in source and binary forms, with or without
8264656Simp# modification, are permitted provided that the following conditions
9264656Simp# are met:
10264656Simp# 1. Redistributions of source code must retain the above copyright
11264656Simp#    notice, this list of conditions and the following disclaimer.
12264656Simp# 2. Redistributions in binary form must reproduce the above copyright
13264656Simp#    notice, this list of conditions and the following disclaimer in the
14264656Simp#    documentation and/or other materials provided with the distribution.
15264656Simp#
16264656Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17264656Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18264656Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19264656Simp# ARE DISCLAIMED.  IN NO EVENT SHALL iXsystems, Inc. OR CONTRIBUTORS BE LIABLE
20264656Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21264656Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22264656Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23264656Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24264656Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25264656Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26264656Simp# SUCH DAMAGE.
27264656Simp#
28264656Simp# This file is heavily derived from both Sam Leffler's Avilia config,
29264656Simp# as well as the BSDRP project's config file.  Neither of these have
30264656Simp# an explicit copyright/license statement, but are implicitly BSDL. This
31264656Simp# example has been taken from the FreeNAS project and simplified to meet
32264656Simp# the needs of the example.
33264656Simp#
34264656Simp
35264656Simp# Pull in common definitions.
36264656Simp. common
37264656Simp
38264656SimpNANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18"
39264656Simp
40264656Simp# /var -> ~10MB (look through rc.initdiskless for the formula of how this
41264656Simp# number is calculated out). Since we hope to run 
42264656SimpNANO_RAM_TMPVARSIZE=10240
43264656Simp
44264656SimpNANO_IMAGES=2
45264656SimpFlashDevice generic 2g
46264656Simp
47264656Simpif [ "$DEBUG" = 1 ]; then
48264656Simp	DEBUG_BUILD="
49264656SimpDEBUG_FLAGS=		-g
50264656Simp"
51264656Simpelse
52264656Simp	DEBUG_INSTALL="
53264656SimpINSTALL_NODEBUG=	t
54264656Simp"
55264656Simpfi
56264656Simp
57264656SimpCONF_INSTALL="$CONF_BUILD
58264656Simp${DEBUG_BUILD}
59264656Simp"
60264656SimpCONF_INSTALL="$CONF_INSTALL
61264656Simp${DEBUG_INSTALL}
62264656Simp"
63264656Simp
64264656Simpadd_port security/sudo
65264656Simpadd_port ftp/curl
66264656Simp
67264656Simpif [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
68264656Simp 	CONF_INSTALL="${CONF_INSTALL}
69264656Simp${PKG_ONLY_MAKE_CONF}
70264656Simp"
71264656Simp	echo "Automatically building a thin image with packages"
72264656Simpelse
73264656Simp	echo "Automatically building a * * F A T * * image so we can build ports"
74264656Simpfi
75264656Simp
76264656SimpVARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
77264656Simp
78264656Simpfor var in $VARS; do
79264656Simp	val=$(eval echo "\$$var")
80264656Simp	if [ -n "$val" ]; then
81264656Simp		CONF_INSTALL="${CONF_INSTALL}
82264656Simp$var=$val"
83264656Simp	fi
84264656Simpdone
85264656Simp
86264656Simpif [ "$PACKAGE_PREP_BUILD" = 1 ]; then
87264656Simp	echo "Skipping post-package customize steps"
88264656Simp	do_image=false
89264656Simpelse
90264656Simp
91264656Simphack_nsswitch_conf ( )
92264656Simp{
93264656Simp	# Remove all references to NIS in the nsswitch.conf file
94264656Simp	# Not sure this is still needed, but FreeNAS has it...
95264656Simp	sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf
96264656Simp	rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak
97264656Simp}
98264656Simpcustomize_cmd hack_nsswitch_conf
99264656Simp
100264656Simpsave_build ( )
101264656Simp{
102264656Simp	VERSION_FILE=${NANO_WORLDDIR}/etc/version
103264656Simp	if [ "${SVNREVISION}" = "${REVISION}" ]; then
104264656Simp		echo "${NANO_NAME}" > "${VERSION_FILE}"
105264656Simp	else
106264656Simp		echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
107264656Simp	fi
108264656Simp}
109264656Simpcustomize_cmd save_build
110264656Simp
111264656Simpremove_patch_divots ( )
112264656Simp{
113264656Simp	find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete
114264656Simp}
115264656Simpcustomize_cmd remove_patch_divots
116264656Simp
117264656Simpconfigure_mnt_md ( )
118264656Simp{
119264656Simp	mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt
120264656Simp	echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size
121264656Simp}
122264656Simpcustomize_cmd configure_mnt_md
123264656Simp
124264656Simpshrink_md_fbsize()
125264656Simp{
126264656Simp	# We have a lot of little files on our memory disks. Let's decrease
127264656Simp	# the block and frag size to fit more little files on them (this
128264656Simp	# halves our space requirement by ~50% on /etc and /var on 8.x --
129264656Simp	# and gives us more back on 9.x as the default block and frag size
130264656Simp	# are 4 times larger).
131264656Simp	sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
132264656Simp		${NANO_WORLDDIR}/etc/rc.initdiskless
133264656Simp}
134264656Simpcustomize_cmd shrink_md_fbsize
135264656Simp
136264656Simpif [ "${DEBUG}" = 1 ]; then
137264656Simp
138264656Simpunmute_console_logging()
139264656Simp{
140264656Simp	# /var is small. Don't fill it up with messages from console.log
141264656Simp	# because it's a chatty log.
142264656Simp	sed -i '' -e 's/#console.info/console.info/' \
143264656Simp			"${NANO_WORLDDIR}/etc/syslog.conf"
144264656Simp}
145264656Simpcustomize_cmd unmute_console_logging
146264656Simp
147264656Simpfi
148264656Simp
149265166Simpproduct_custom()
150264656Simp{
151264656Simp	gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel
152264656Simp
153264656Simp	# kill includes (saves 14MB)
154264656Simp	find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f
155264656Simp
156264656Simp	# kill docs (saves 22MB)
157264656Simp	rm -rf ${NANO_WORLDDIR}/usr/local/share/doc
158264656Simp	rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc
159264656Simp
160264656Simp	# and info (2MB)
161264656Simp	rm -rf ${NANO_WORLDDIR}/usr/local/info
162264656Simp
163264656Simp	# and man pages (4.4MB)
164264656Simp	rm -rf ${NANO_WORLDDIR}/usr/local/man
165264656Simp
166264656Simp	# and examples (1.7M)
167264656Simp	rm -rf ${NANO_WORLDDIR}/usr/local/share/examples
168264656Simp
169264656Simp	# and groff_fonts junk (3MB)
170264656Simp	rm -rf ${NANO_WORLDDIR}/usr/share/groff_font
171264656Simp	rm -rf ${NANO_WORLDDIR}/usr/share/tmac
172264656Simp	rm -rf ${NANO_WORLDDIR}/usr/share/me
173264656Simp
174264656Simp	# Kill all .a's and .la's that are installed (20MB+)
175264656Simp	find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete
176264656Simp
177264656Simp	# magic.mgc is just a speed optimization.  Kill it for 1.7MB
178264656Simp	rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc
179264656Simp
180264656Simp	# Last second tweaks
181264656Simp	chown -R root:wheel ${NANO_WORLDDIR}/root
182264656Simp	chmod 0755 ${NANO_WORLDDIR}/root/*
183264656Simp	chmod 0755 ${NANO_WORLDDIR}/*
184264656Simp	chown -R root:wheel ${NANO_WORLDDIR}/etc
185264656Simp	chown -R root:wheel ${NANO_WORLDDIR}/boot
186264656Simp	chown root:wheel ${NANO_WORLDDIR}/
187264656Simp	chown root:wheel ${NANO_WORLDDIR}/usr
188264656Simp	find ${NANO_WORLDDIR} -type f -name "*~" -delete
189264656Simp	find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete
190264656Simp	find ${NANO_WORLDDIR} -type f -name "*.service" -delete
191264656Simp}
192265166Simplate_customize_cmd product_custom
193264656Simp
194264656Simpfi # [ $PACKAGE_PREP_BUILD = 1 ]
195