#/bin/bash set -eu REMOVEPERL=${REMOVEPERL:-0} PORTDIR="/usr/portage" DISTDIR="${PORTDIR}/distfiles" PORTAGE_TMPDIR="/var/tmp" if [[ $# -ne 2 ]] ; then echo "Two arguments are required." echo "" echo "arg 1: TARGETVER" echo "arg 2: TARGETMODE, Please set kernel, freebsd_userland, world." exit 1 else TARGETVER=$1 TARGETMODE=$2 fi set_profile(){ echo "Setting the ${TARGETVER} profile..." emerge --info | head -n 1 | grep clang &>/dev/null && : if [[ $? -eq 0 ]] ; then eselect profile set $(eselect profile list | grep "${TARGETVER}" | grep clang | awk '{print $1}' | sed 's:\[::g' | sed 's:\]::g' | tail -n 1) export CXX="clang++ -stdlib=libc++" else eselect profile set $(eselect profile list | grep "${TARGETVER}" | grep -v clang | awk '{print $1}' | sed 's:\[::g' | sed 's:\]::g' | tail -n 1) fi } move_makeconf(){ [[ ! -e /etc/portage ]] && mkdir -p /etc/portage if [[ -e /etc/make.conf ]] && [[ ! -e /etc/portage/make.conf ]] ; then echo "Moving the /etc/make.conf to /etc/portage..." mv /etc/make.conf /etc/portage fi gsed -i '/LDFLAGS=/d' /etc/portage/make.conf if [[ -e /etc/make.profile ]] && [[ ! -e /etc/portage/make.profile ]] ; then echo "Creating the make.profile..." ln -s ../..${PORTDIR}profiles/$(eselect profile list | grep '*' | awk '{print $2}') /etc/portage/make.profile fi } update_portage(){ local dl_portage_ver="2.3.6" echo "Updating the sys-apps/portage with a manual method..." cd /tmp if [[ -e "${DISTDIR}"/portage-${dl_portage_ver}.tar.bz2 ]] ; then cp -a "${DISTDIR}/portage-${dl_portage_ver}.tar.bz2" . else wget -q "http://dev.gentoo.org/~dolsen/releases/portage/portage-${dl_portage_ver}.tar.bz2" fi tar xjf "portage-${dl_portage_ver}.tar.bz2" cd "/tmp/portage-${dl_portage_ver}" PYTHON_TARGETS="python2_7" bin/emerge --nodeps dev-lang/python-exec eselect python set 1 PYTHON_TARGETS="python2_7" bin/emerge --nodeps sys-apps/portage --exclude sys-freebsd/* eselect python set 1 } update_bmake_command(){ echo "Updating bmake..." [[ -e /usr/local/bin/make ]] && exit 1 cd "${PORTDIR}/sys-freebsd/freebsd-ubin" && ebuild $(ls -1 freebsd-ubin-${TARGETVER}*.ebuild | tail -n 1) prepare cd "${PORTAGE_TMPDIR}"/portage/sys-freebsd/freebsd-ubin-${TARGETVER}*/work/usr.bin/bmake make cp -a make /usr/local/bin/ cd "${PORTDIR}/sys-freebsd/freebsd-ubin" && ebuild $(ls -1 freebsd-ubin-${TARGETVER}*.ebuild | tail -n 1) clean env-update source /etc/profile } update_config_command(){ echo "Updating config..." [[ -e /usr/local/sbin/config ]] && exit 1 cd "${PORTDIR}/sys-freebsd/freebsd-usbin" && ebuild $(ls -1 freebsd-usbin-${TARGETVER}*.ebuild | tail -n 1) prepare cd "${PORTAGE_TMPDIR}"/portage/sys-freebsd/freebsd-usbin-${TARGETVER}*/work/usr.sbin/config /usr/local/bin/make -m /usr/share/mk/system cp -a config /usr/local/sbin/ cd "${PORTDIR}/sys-freebsd/freebsd-usbin" && ebuild $(ls -1 freebsd-usbin-${TARGETVER}*.ebuild | tail -n 1) clean } update_minimal(){ echo "Updating the minimal packages to upgrade the Gentoo/FreeBSD..." emerge -u sys-devel/gcc-config --exclude sys-freebsd/* update_bmake_command emerge --nodeps sys-freebsd/freebsd-mk-defs update_config_command emerge -u '> /etc/portage/profile/package.use.mask echo "sys-libs/libcxxrt abi_x86_32" >> /etc/portage/profile/package.use.mask USE="internal-glib" emerge -u dev-util/pkgconfig --exclude sys-freebsd/* USE="-nls" emerge -u cmake --exclude sys-freebsd/* emerge --nodeps ' /etc/portage/package.unmask/toolchain-oldversion echo "> /etc/portage/package.unmask/toolchain-oldversion emerge -u ' /var/db/pkg/sys-freebsd/freebsd-lib-*/RDEPEND rm /var/db/pkg/sys-freebsd/freebsd-lib-*/*.ebuild echo "" > /var/db/pkg/dev-libs/glib-*/RDEPEND echo "" > /var/db/pkg/dev-libs/glib-*/DEPEND rm /var/db/pkg/dev-libs/glib-*/*.ebuild rm /var/db/pkg/sys-freebsd/freebsd-libexec-*/*.ebuild } update_freebsd_userland(){ echo "Updating the FreeBSD userland..." # Fixing the dependence issue: ls -1 /var/db/pkg/sys-freebsd/freebsd-lib-9.* &>/dev/null && : [[ $? -eq 0 ]] && fix_dependence_issue [[ -e /usr/share/misc/windrv_stub.c ]] && rm -rf /usr/share/misc/windrv_stub.c CC=gcc CXX=g++ CXXFLAGS="-O2 -pipe" USE=build emerge -u freebsd-bin freebsd-lib freebsd-mk-defs freebsd-pam-modules freebsd-sbin freebsd-share freebsd-sources freebsd-ubin freebsd-usbin emerge freebsd-share if type -P clang &> /dev/null ; then emerge dev-util/re2c emerge --nodeps '