#!/bin/sh -Cefu set -Cefu _jctl() { service jail $* } _jcmd() { _jctl restart "$jail_build" || true local cmd="$*" local start="`date +%s`" echo echo "Command '$cmd'" echo echo "Start `date -r \"$start\"`" echo time -h \ env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin \ "`which jexec`" "$jail_build" sh -Ceuc "$cmd" local end="`date +%s`" local duration="$(($end - $start))" echo echo "Command '$cmd'" echo echo "Start `date -r \"$start\"`" echo "End `date -r \"$end\"`" echo echo "Duration $duration s" echo _jctl restart "$jail_build" || true } case "${0##*/}" in srcbbb) machine_type=bbb jail_build=build0 jail_install=bbbinstall ;; srchost) machine_type=host jail_build=build1 ;; esac case "${1:-}" in minimal) build_type=minimal shift ;; stable) build_type=stable case "$machine_type" in bbb) jail_build=build2 ;; esac shift ;; full) build_type=full shift ;; *) case "$machine_type" in bbb) build_type=minimal ;; *) build_type=full ;; esac ;; esac case "${1:-}" in build*) action_type=build ;; install*) action_type=install ;; *) action_type=build ;; esac src_path=/usr/src make_jobs='$((`sysctl -n hw.ncpu` * 1))' make_conf="/build/$machine_type/conf/$build_type/$action_type/make.conf" case "${1:-}" in build) _jcmd \ 'make -s -j "'$make_jobs'" -C '"'"$src_path"'" \ 'buildworld buildkernel' \ '__MAKE_CONF='"'"$make_conf"'" shift ;; build-noclean) _jcmd \ 'make -s -j "'$make_jobs'" -C '"'"$src_path"'" \ 'buildworld buildkernel' \ '__MAKE_CONF='"'"$make_conf"'" \ 'NO_CLEAN=yes' shift ;; buildkernel) _jcmd \ 'make -s -j "'$make_jobs'" -C '"'"$src_path"'" \ 'buildkernel' \ '__MAKE_CONF='"'"$make_conf"'" shift ;; install) install_dest=/install-dest install_dest_subdir="$build_type" kernel_file=boot/kernel/kernel _jctl stop "$jail_install" || true _jcmd \ '(' \ 'cd '"'"$install_dest"'" \ '&& mv -v '"'"$install_dest_subdir"'"' "'$install_dest_subdir'.`date +%s`.bak"' \ '&& mkdir '"'"$install_dest_subdir"'" \ ')' \ '&& make -s -C '"'"$src_path"'" \ 'installworld installkernel distribution' \ '__MAKE_CONF='"'"$make_conf"'" \ '&& (' \ 'cd '"'"$install_dest"'" \ '&& du -hxs '"'"$install_dest_subdir"'" \ '&& strings -f '"'"$install_dest_subdir'/'$kernel_file"'"' | fgrep '"'"'@(#)FreeBSD'"'" \ ')' _jctl start "$jail_install" || true shift ;; clean) _jcmd \ 'rm -vfr /usr/obj/* || true' shift ;; esac