123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/bin/sh
- set -e
- NCPUS=$(sysctl hw.ncpufound | sed 's/.*=//')
- # Try to find a valid way to become root if not already
- SUDO=
- if [ -e '/etc/doas.conf' ]; then
- SUDO='/usr/bin/doas'
- elif [ -x '/usr/local/bin/sudo' ]; then
- SUDO='/usr/local/bin/sudo'
- fi
- # Bail out if not root and neither sudo or doas was found.
- _uid=$(id -u)
- if [ -z ${SUDO} -a \( ${_uid} -ne 0 \) ]; then
- echo 'Need a way to become root, neither sudo or doas found...' 1>&2
- exit 1
- elif [ ${_uid} -eq 0 ]; then
- # Clear SUDO if already root
- SUDO=
- fi
- # Find the source tree for the base system
- if [ -e /etc/mk.conf ]; then
- BSDSRCDIR=$(make -f /etc/mk.conf -V BSDSRCDIR)
- BSDOBJDIR=$(make -f /etc/mk.conf -V BSDOBJDIR)
- fi
- BSDSRCDIR=${BSDSRCDIR:=/usr/src}
- BSDOBJDIR=${BSDOBJDIR:=/usr/obj}
- START_TIME=$(date)
- cd ${BSDOBJDIR} && mkdir -p .old && ${SUDO} mv * .old && ${SUDO} rm -rf .old &
- cd ${BSDSRCDIR} && make obj
- cd ${BSDSRCDIR}/etc && ${SUDO} make DESTDIR=/ distrib-dirs
- cd ${BSDSRCDIR}
- make SUDO=${SUDO} build -j $((NCPUS * 2))
- RESULT=$?
- END_TIME=$(date)
- echo "Build started at ${START_TIME}, ended at ${END_TIME}"
- exit ${RESULT}
|