os-base revision 265166
1288253Sadrian# $FreeBSD: stable/10/tools/tools/nanobsd/dhcpd/os-base 265166 2014-05-01 00:31:19Z imp $
2288253Sadrian
3288253Sadrian#-
4288253Sadrian# Copyright (c) 2014 Warner Losh. All Rights Reserved.
5288253Sadrian# Copyright (c) 2010-2011 iXsystems, Inc., All rights reserved.
6288253Sadrian#
7288253Sadrian# Redistribution and use in source and binary forms, with or without
8288253Sadrian# modification, are permitted provided that the following conditions
9288253Sadrian# are met:
10288253Sadrian# 1. Redistributions of source code must retain the above copyright
11288253Sadrian#    notice, this list of conditions and the following disclaimer.
12288253Sadrian# 2. Redistributions in binary form must reproduce the above copyright
13288253Sadrian#    notice, this list of conditions and the following disclaimer in the
14288253Sadrian#    documentation and/or other materials provided with the distribution.
15288253Sadrian#
16288253Sadrian# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17288253Sadrian# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18288253Sadrian# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19288253Sadrian# ARE DISCLAIMED.  IN NO EVENT SHALL iXsystems, Inc. OR CONTRIBUTORS BE LIABLE
20288253Sadrian# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21288253Sadrian# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22288253Sadrian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23288253Sadrian# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24288253Sadrian# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25288253Sadrian# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26288253Sadrian# SUCH DAMAGE.
27288253Sadrian#
28288253Sadrian# This file is heavily derived from both Sam Leffler's Avilia config,
29288253Sadrian# as well as the BSDRP project's config file.  Neither of these have
30288253Sadrian# an explicit copyright/license statement, but are implicitly BSDL. This
31288253Sadrian# example has been taken from the FreeNAS project and simplified to meet
32288253Sadrian# the needs of the example.
33288253Sadrian#
34288253Sadrian
35288253Sadrian# Pull in common definitions.
36288253Sadrian. common
37288253Sadrian
38288253SadrianNANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18"
39288253Sadrian
40288253Sadrian# /var -> ~10MB (look through rc.initdiskless for the formula of how this
41288253Sadrian# number is calculated out). Since we hope to run 
42288253SadrianNANO_RAM_TMPVARSIZE=10240
43288253Sadrian
44288253SadrianNANO_IMAGES=2
45288253SadrianFlashDevice generic 2g
46289781Sadrian
47288253Sadrianif [ "$DEBUG" = 1 ]; then
48288253Sadrian	DEBUG_BUILD="
49288253SadrianDEBUG_FLAGS=		-g
50288253Sadrian"
51288253Sadrianelse
52288253Sadrian	DEBUG_INSTALL="
53289781SadrianINSTALL_NODEBUG=	t
54288253Sadrian"
55288253Sadrianfi
56288253Sadrian
57288253SadrianCONF_INSTALL="$CONF_BUILD
58288253Sadrian${DEBUG_BUILD}
59288253Sadrian"
60288253SadrianCONF_INSTALL="$CONF_INSTALL
61288253Sadrian${DEBUG_INSTALL}
62290432Sadrian"
63290432Sadrian
64289781Sadrianadd_port security/sudo
65289781Sadrianadd_port ftp/curl
66289781Sadrian
67288253Sadrianif [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
68289781Sadrian 	CONF_INSTALL="${CONF_INSTALL}
69288253Sadrian${PKG_ONLY_MAKE_CONF}
70288253Sadrian"
71288253Sadrian	echo "Automatically building a thin image with packages"
72288253Sadrianelse
73289781Sadrian	echo "Automatically building a * * F A T * * image so we can build ports"
74290432Sadrianfi
75290432Sadrian
76290432SadrianVARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
77290432Sadrian
78290432Sadrianfor var in $VARS; do
79288253Sadrian	val=$(eval echo "\$$var")
80288253Sadrian	if [ -n "$val" ]; then
81288253Sadrian		CONF_INSTALL="${CONF_INSTALL}
82288253Sadrian$var=$val"
83288253Sadrian	fi
84288253Sadriandone
85288253Sadrian
86288253Sadrianif [ "$PACKAGE_PREP_BUILD" = 1 ]; then
87289781Sadrian	echo "Skipping post-package customize steps"
88288253Sadrian	do_image=false
89288253Sadrianelse
90289781Sadrian
91288253Sadrianhack_nsswitch_conf ( )
92288253Sadrian{
93289781Sadrian	# Remove all references to NIS in the nsswitch.conf file
94289781Sadrian	# Not sure this is still needed, but FreeNAS has it...
95289781Sadrian	sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf
96290432Sadrian	rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak
97290432Sadrian}
98290432Sadriancustomize_cmd hack_nsswitch_conf
99290432Sadrian
100290432Sadriansave_build ( )
101290432Sadrian{
102289781Sadrian	VERSION_FILE=${NANO_WORLDDIR}/etc/version
103288253Sadrian	if [ "${SVNREVISION}" = "${REVISION}" ]; then
104288253Sadrian		echo "${NANO_NAME}" > "${VERSION_FILE}"
105289781Sadrian	else
106288253Sadrian		echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
107288253Sadrian	fi
108288253Sadrian}
109288253Sadriancustomize_cmd save_build
110288253Sadrian
111288253Sadrianremove_patch_divots ( )
112288253Sadrian{
113288253Sadrian	find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete
114288253Sadrian}
115288253Sadriancustomize_cmd remove_patch_divots
116288253Sadrian
117288253Sadrianconfigure_mnt_md ( )
118288253Sadrian{
119288253Sadrian	mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt
120288253Sadrian	echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size
121288253Sadrian}
122288253Sadriancustomize_cmd configure_mnt_md
123288253Sadrian
124288253Sadrianshrink_md_fbsize()
125288253Sadrian{
126288253Sadrian	# We have a lot of little files on our memory disks. Let's decrease
127288253Sadrian	# the block and frag size to fit more little files on them (this
128288253Sadrian	# halves our space requirement by ~50% on /etc and /var on 8.x --
129288253Sadrian	# and gives us more back on 9.x as the default block and frag size
130288253Sadrian	# are 4 times larger).
131288253Sadrian	sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
132288253Sadrian		${NANO_WORLDDIR}/etc/rc.initdiskless
133288253Sadrian}
134288253Sadriancustomize_cmd shrink_md_fbsize
135288253Sadrian
136288253Sadrianif [ "${DEBUG}" = 1 ]; then
137288253Sadrian
138288253Sadrianunmute_console_logging()
139288253Sadrian{
140288253Sadrian	# /var is small. Don't fill it up with messages from console.log
141288253Sadrian	# because it's a chatty log.
142288253Sadrian	sed -i '' -e 's/#console.info/console.info/' \
143288253Sadrian			"${NANO_WORLDDIR}/etc/syslog.conf"
144288253Sadrian}
145288253Sadriancustomize_cmd unmute_console_logging
146288253Sadrian
147288253Sadrianfi
148288253Sadrian
149288253Sadrianproduct_custom()
150288253Sadrian{
151288253Sadrian	gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel
152288253Sadrian
153288253Sadrian	# kill includes (saves 14MB)
154288253Sadrian	find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f
155288253Sadrian
156288253Sadrian	# kill docs (saves 22MB)
157288253Sadrian	rm -rf ${NANO_WORLDDIR}/usr/local/share/doc
158288253Sadrian	rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc
159288253Sadrian
160288253Sadrian	# and info (2MB)
161288253Sadrian	rm -rf ${NANO_WORLDDIR}/usr/local/info
162288253Sadrian
163288253Sadrian	# and man pages (4.4MB)
164289781Sadrian	rm -rf ${NANO_WORLDDIR}/usr/local/man
165289781Sadrian
166289781Sadrian	# and examples (1.7M)
167289781Sadrian	rm -rf ${NANO_WORLDDIR}/usr/local/share/examples
168289781Sadrian
169289781Sadrian	# and groff_fonts junk (3MB)
170289781Sadrian	rm -rf ${NANO_WORLDDIR}/usr/share/groff_font
171289781Sadrian	rm -rf ${NANO_WORLDDIR}/usr/share/tmac
172289781Sadrian	rm -rf ${NANO_WORLDDIR}/usr/share/me
173289781Sadrian
174289781Sadrian	# Kill all .a's and .la's that are installed (20MB+)
175289781Sadrian	find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete
176289781Sadrian
177289781Sadrian	# magic.mgc is just a speed optimization.  Kill it for 1.7MB
178289781Sadrian	rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc
179289781Sadrian
180289781Sadrian	# Last second tweaks
181289781Sadrian	chown -R root:wheel ${NANO_WORLDDIR}/root
182289781Sadrian	chmod 0755 ${NANO_WORLDDIR}/root/*
183289781Sadrian	chmod 0755 ${NANO_WORLDDIR}/*
184289781Sadrian	chown -R root:wheel ${NANO_WORLDDIR}/etc
185289781Sadrian	chown -R root:wheel ${NANO_WORLDDIR}/boot
186289781Sadrian	chown root:wheel ${NANO_WORLDDIR}/
187289781Sadrian	chown root:wheel ${NANO_WORLDDIR}/usr
188289781Sadrian	find ${NANO_WORLDDIR} -type f -name "*~" -delete
189289781Sadrian	find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete
190288253Sadrian	find ${NANO_WORLDDIR} -type f -name "*.service" -delete
191288253Sadrian}
192288253Sadrianlate_customize_cmd product_custom
193288253Sadrian
194288253Sadrianfi # [ $PACKAGE_PREP_BUILD = 1 ]
195288253Sadrian