#!/bin/bash set -eu TARGETVER="${TARGETVER:-11.1}" TARGETARCH="${TARGETARCH:-amd64}" OLDSTAGE3="${OLDSTAGE3:-http://distfiles.gentoo.org/experimental/bsd/freebsd/stages/amd64-fbsd-9.1/stage3-amd64-freebsd-9.1.tar.bz2}" WORKDIR="/${TARGETVER}-forcestage3/${TARGETARCH}" PORTDIR="${PORTDIR:-/usr/portage}" TMPFS=${TMPFS:-0} CLANG=${CLANG:-0} SET_MAKEOPTS=${SET_MAKEOPTS:-1} # DISTDIR will be set automatically if your environment have the emerge command. # This setting exists for vanilla FreeBSD. DISTDIR="${DISTDIR:-/usr/portage/distfiles}" [[ ${CLANG} -ne 0 ]] && WORKDIR="${WORKDIR}_clang" prepare(){ local distdir if type -P emerge &> /dev/null ; then distdir="$(emerge --info | grep DISTDIR | sed s:DISTDIR=::g | sed 's:"::g')" else distdir="${DISTDIR}" fi if [[ ! -d "${WORKDIR}" ]]; then mkdir -p "${WORKDIR}" else echo "Error: ${WORKDIR} exists." echo "Please remove the following steps:" echo "" echo "kill -9 $(ps auxw | grep ebuild-helpers/ecompressdir | grep -v grep | awk '{ print $2 }' | xargs)" echo "umount $(mount | grep ${WORKDIR} | awk '{print $3}' | xargs)" echo "umount $(mount | grep ${WORKDIR} | awk '{print $3}' | xargs)" echo "chflags -R noschg \"${WORKDIR}\" && rm -rf \"${WORKDIR}\"" exit 1 fi if [[ "${OLDSTAGE3}" =~ ^http ]]; then if [[ ! -e /tmp/$(basename ${OLDSTAGE3}) ]]; then cd /tmp if type -P wget &> /dev/null ; then wget -q "${OLDSTAGE3}" else fetch "${OLDSTAGE3}" fi fi else cp -a "${OLDSTAGE3}" /tmp fi tar xjpf /tmp/$(basename ${OLDSTAGE3}) -C "${WORKDIR}" mkdir -p "${WORKDIR}"/usr/portage/distfiles mkdir -p "${WORKDIR}"/var/tmp/portage mount -t devfs devfs "${WORKDIR}"/dev mount -t nullfs "${PORTDIR}" "${WORKDIR}"/usr/portage if [[ ! "${distdir}" =~ ${PORTDIR}.* ]]; then echo "mount DISTDIR" if [[ ! -e "${WORKDIR}"/usr/portage/distfiles ]]; then mkdir "${WORKDIR}"/usr/portage/distfiles fi mount -t nullfs "${distdir}" "${WORKDIR}"/usr/portage/distfiles fi if [[ "${TMPFS}" -ne 0 ]] ; then echo "mount TMPFS" mount -t tmpfs tmpfs "${WORKDIR}"/var/tmp/portage fi cd "${WORKDIR}" fetch https://gitweb.gentoo.org/proj/gentoo-bsd.git/plain/scripts/automatic_updater.sh cp -a /etc/resolv.conf "${WORKDIR}"/etc } chroot_update(){ if [[ -e "${WORKDIR}"/etc/make.conf ]]; then local makeconf="${WORKDIR}"/etc/make.conf else local makeconf="${WORKDIR}"/etc/portage/make.conf fi case ${SET_MAKEOPTS} in [1-9]|[1-9][0-9]) echo "MAKEOPTS=\"-j${SET_MAKEOPTS}\"" >> "${makeconf}" ;; *) exit 1 ;; esac echo 'USE="${USE} -fortran -build-kernel"' >> "${makeconf}" export EMERGE_DEFAULT_OPTS="-q" chroot "${WORKDIR}" bash /automatic_updater.sh ${TARGETVER} kernel chroot "${WORKDIR}" bash /automatic_updater.sh ${TARGETVER} freebsd_userland if [[ -e "${WORKDIR}"/usr/bin/git ]]; then chroot "${WORKDIR}" emerge -C dev-vcs/git fi REMOVEPERL=1 chroot "${WORKDIR}" bash /automatic_updater.sh ${TARGETVER} world unset EMERGE_DEFAULT_OPTS } check_ecompressdir() { # dirty solution # /dev is still mounted; performing auto-bind-umount... local PID=$(ps auxw | grep ebuild-helpers/ecompressdir | grep -v grep | awk '{ print $2 }' | xargs) if [[ -n "${PID}" ]] ; then echo "kill ecompressdir" kill -9 ${PID} && : return 0 else return 0 fi } cleanup(){ local distdir if type -P emerge &> /dev/null ; then distdir="$(emerge --info | grep DISTDIR | sed s:DISTDIR=::g | sed 's:"::g')" else distdir="${DISTDIR}" fi check_ecompressdir if [[ ! "${distdir}" =~ ${PORTDIR}.* ]]; then echo "unmount DISTDIR" umount "${WORKDIR}"/usr/portage/distfiles fi umount "${WORKDIR}"/usr/portage if [[ "${TMPFS}" -ne 0 ]] ; then umount "${WORKDIR}"/var/tmp/portage fi umount "${WORKDIR}"/dev } create_stage3(){ local tarfile cd "${WORKDIR}" if [[ ! -e /var/tmp/catalyst/builds/default ]] ; then mkdir -p /var/tmp/catalyst/builds/default fi if [[ ${CLANG} -ne 0 ]]; then tarfile="stage3-${TARGETARCH}-fbsd-${TARGETVER}-forcestage3-cl" else tarfile="stage3-${TARGETARCH}-fbsd-${TARGETVER}-forcestage3" fi echo "Compressing with tar." LANG="en_US.UTF-8" tar cjpf /var/tmp/catalyst/builds/default/"${tarfile}".tar.bz2 . echo "Complete!" echo "Set FORCESTAGE3=${tarfile}" } prepare chroot_update cleanup create_stage3