1# $FreeBSD$ 2 3#- 4# Copyright (c) 2014 M. Warner Losh <imp@FreeBSD.org> 5# Copyright (c) 2010 iXsystems, Inc. 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# 29# This file is heavily derived from both Sam Leffler's Avilia config, 30# as well as the BSDRP project's config file. Neither of these have 31# an explicit copyright/license statement, but are implicitly BSDL. This 32# example has been taken from the FreeNAS project (an early version) and 33# simplified to meet the needs of the example. 34# 35 36# NB: You want the other file 37 38NANO_PMAKE="make -j $(sysctl -n hw.ncpu)" 39 40NANO_CFG_BASE=$(pwd) 41NANO_CFG_BASE=${NANO_CFG_BASE%/dhcpd} 42NANO_SRC=$(pwd) 43NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/dhcpd} 44NANO_OBJ=${NANO_SRC}/../nanobsd-builds/dhcpd/obj 45# Where cust_pkg() finds packages to install 46#XXX: Is this the right place? 47NANO_PORTS=$(realpath ${NANO_SRC}/../ports) 48#NANO_PORTS=/usr/ports 49NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg 50NANO_DATADIR=${NANO_OBJ}/_.data 51NANO_DATASIZE=40960 52NANO_INIT_IMG2=0 53unset MAKEOBJDIRPREFIX 54 55# this to go into nanobsd.sh 56NANO_PORTS=${NANO_PORTS:-/usr/ports} 57 58customize_cmd cust_allow_ssh_root 59 60add_etc_make_conf() 61{ 62 touch ${NANO_WORLDDIR}/etc/make.conf 63} 64customize_cmd add_etc_make_conf 65 66clean_usr_local() 67{ 68 LOCAL_DIR=${NANO_WORLDDIR}/usr/local 69 pprint 2 "Clean and create world directory (${LOCAL_DIR})" 70 if rm -rf ${LOCAL_DIR}/ > /dev/null 2>&1 ; then 71 true 72 else 73 chflags -R noschg ${LOCAL_DIR}/ 74 rm -rf ${LOCAL_DIR}/ 75 fi 76 for f in bin etc lib libdata libexec sbin share; do 77 mkdir -p ${LOCAL_DIR}/$f 78 done 79} 80customize_cmd clean_usr_local 81 82cust_install_machine_files() 83{ 84 echo "cd ${NANO_CFG_BASE}/Files" 85 cd ${NANO_CFG_BASE}/Files 86 find . -print | grep -Ev '/(CVS|\.git|\.hg|\.svn)' | cpio -dumpv ${NANO_WORLDDIR} 87} 88customize_cmd cust_install_files 89customize_cmd cust_install_machine_files 90 91buildenv() 92{ 93 cd ${NANO_SRC} 94 env __MAKE_CONF=${NANO_MAKE_CONF_BUILD} DESTDIR=${NANO_WORLDDIR} make buildenv 95} 96 97NANO_MAKEFS="makefs -B big \ 98 -o bsize=4096,fsize=512,density=8192,optimization=space" 99export NANO_MAKEFS 100 101CONF_BUILD=" 102WITHOUT_ACPI=true 103WITHOUT_AUDIT=true 104WITHOUT_BLUETOOTH=true 105WITHOUT_CALENDAR=true 106WITHOUT_DICT=true 107WITHOUT_EXAMPLES=true 108WITHOUT_GAMES=true 109WITHOUT_HTML=true 110WITHOUT_IPFILTER=true 111WITHOUT_LLVM_COV=true 112WITHOUT_LOCALES=true 113WITHOUT_LPR=true 114WITHOUT_MAN=true 115WITHOUT_NETCAT=true 116WITHOUT_NIS=true 117WITHOUT_NLS=true 118WITHOUT_NS_CACHING=true 119WITHOUT_PROFILE=true 120WITHOUT_SENDMAIL=true 121WITHOUT_SHAREDOCS=true 122WITHOUT_SYSCONS=true 123WITHOUT_LIB32=true 124" 125CONF_INSTALL="$CONF_BUILD 126INSTALL_NODEBUG=t 127NOPORTDOCS=t 128NO_INSTALL_MANPAGES=t 129" 130# The following would help... 131# WITHOUT_TOOLCHAIN=true can't build ports 132# WITHOUT_INSTALLLIB=true libgcc.a 133PKG_ONLY_MAKE_CONF=" 134WITHOUT_TOOLCHAIN=true 135WITHOUT_INSTALLLIB=true 136" 137 138NANO_PACKAGE_ONLY=1 139 140# install a package from a pre-built binary 141do_add_pkg () 142{ 143 # Need to create ${NANO_OBJ}/ports in this add_pkg_${port} function 144 set -x 145 mkdir -p ${NANO_OBJ}/ports/distfiles 146 mkdir -p ${NANO_OBJ}/ports/packages 147 mkdir -p ${NANO_WORLDDIR}/usr/ports/packages 148 mkdir -p ${NANO_WORLDDIR}/usr/ports/distfiles 149 mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \ 150 ${NANO_WORLDDIR}/usr/ports/packages 151 mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \ 152 ${NANO_WORLDDIR}/usr/ports/distfiles 153 CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /usr/ports/packages/All/$1.txz 154 umount ${NANO_WORLDDIR}/usr/ports/distfiles 155 umount ${NANO_WORLDDIR}/usr/ports/packages 156 rmdir ${NANO_WORLDDIR}/usr/ports/packages 157 rmdir ${NANO_WORLDDIR}/usr/ports/distfiles 158 rmdir ${NANO_WORLDDIR}/usr/ports 159 set +x 160} 161 162# Build a port (with the side effect of creating a package) 163do_add_port () 164{ 165 local port_path 166 port_path=$1 167 shift 168 set -x 169 # Need to create ${NANO_OBJ}/ports in this add_port_${port} function 170 mkdir -p ${NANO_OBJ}/ports/distfiles 171 mkdir -p ${NANO_OBJ}/ports/packages 172 mkdir -p ${NANO_PORTS}/packages 173 mkdir -p ${NANO_PORTS}/distfiles 174 mkdir -p ${NANO_WORLDDIR}/usr/src 175 mkdir -p ${NANO_WORLDDIR}/usr/ports 176 mount -t nullfs -o noatime ${NANO_SRC} ${NANO_WORLDDIR}/usr/src 177 mount -t nullfs -o noatime ${NANO_PORTS} ${NANO_WORLDDIR}/usr/ports 178 mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \ 179 ${NANO_WORLDDIR}/usr/ports/packages 180 mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \ 181 ${NANO_WORLDDIR}/usr/ports/distfiles 182 mkdir -p ${NANO_WORLDDIR}/dev 183 mount -t devfs devfs ${NANO_WORLDDIR}/dev 184 mkdir -p ${NANO_WORLDDIR}/usr/workdir 185 cp /etc/resolv.conf ${NANO_WORLDDIR}/etc/resolv.conf 186 # OK, a little inefficient, but likely not enough to worry about. 187 CR ldconfig /lib /usr/lib /usr/local/lib 188 CR ldconfig -R 189 CR ldconfig -r 190# Improvement: Don't know why package-recursive don't works here 191 CR "env UNAME_p=${NANO_ARCH} TARGET=${NANO_ARCH} \ 192 TARGET_ARCH=${NANO_ARCH} PORTSDIR=${NANO_PORTS} make \ 193 __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \ 194 WRKDIRPREFIX=/usr/workdir -C /usr/ports/$port_path \ 195 package-recursive BATCH=yes $* clean FORCE_PKG_REGISTER=t" 196 rm ${NANO_WORLDDIR}/etc/resolv.conf 197 rm -rf ${NANO_WORLDDIR}/usr/obj 198 rm -rf ${NANO_WORLDDIR}/usr/workdir 199 umount ${NANO_WORLDDIR}/dev 200 umount ${NANO_WORLDDIR}/usr/ports/packages 201 umount ${NANO_WORLDDIR}/usr/ports/distfiles 202 umount ${NANO_WORLDDIR}/usr/ports 203 umount ${NANO_WORLDDIR}/usr/src 204 set +x 205} 206 207# Need to check if this function works with cross-compiling architecture!!!! 208# Recursive complex fonction: Generate one function for each ports 209add_port () { 210 local port_path=$1 211 local port=`echo $1 | sed -e 's/\//_/'` 212 shift 213 # Check if package already exist 214 # Need to: 215 # 1. check ARCH of this package! 216 # 2. Add a trap 217 cd ${NANO_PORTS}/${port_path} 218 PKG_NAME=`env PORTSDIR=${NANO_PORTS} make __MAKE_CONF=${NANO_MAKE_CONF_BUILD} package-name` 219 if [ -f ${NANO_OBJ}/ports/packages/All/${PKG_NAME}.txz ]; then 220 # Pkg file found: Generate add_pkg_NAME function 221 eval " 222 add_pkg_${port} () { 223 do_add_pkg ${PKG_NAME} 224 } 225 customize_cmd add_pkg_${port} 226 " 227 else 228 # No pkg file: Generate add_port_NAME function 229 eval " 230 add_port_${port} () { 231 do_add_port ${port_path} $* 232 } 233 customize_cmd add_port_${port} 234 " 235 NANO_PACKAGE_ONLY=0 236 fi 237} 238 239die() 240{ 241 echo "$*" 242 exit 1 243} 244 245# Automatically include the packaging port here so it is always first so it 246# builds the port and adds the package so we can add other packages. 247add_port ports-mgmt/pkg 248 249rp=$(realpath ${NANO_OBJ}/) 250__a=`mount | grep ${rp} | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'` 251if [ -n "$__a" ]; then 252 echo "unmounting $__a" 253 umount $__a 254fi 255 256NANO_BOOTLOADER="boot/boot0" 257