#!/bin/sh BASH_VER=4.3 PYTHON_VER=2.7.10 PORTAGE_VER=2.2.8 usage() { exec cat </dev/null) v() { eval echo \"\$$1\" ; } for v in ${ALL_VARS} ; do # See if the var has been set yet. if [ -n "$(v ${v})" ] ; then continue fi # Try to read it ourselves. for f in /etc/portage/make.conf /etc/make.conf ; do [ -e ${f} ] || continue eval ${v}=\"$(. "${f}" 2>/dev/null ; v ${v})\" done done for v in ${CRITICAL_VARS} ; do if [ -z "$(v ${v})" ] ; then echo "Please set ${v}" exit 1 fi done : ${MAKEOPTS:=${MAKEFLAGS:--j$(getconf _NPROCESSORS_ONLN 2>/dev/null)}} : ${PORTDIR:=/usr/portage} : ${DISTDIR:=${PORTDIR}/distfiles} : ${PORTAGE_TMPDIR:=/var/tmp} export ${ALL_VARS} } die() { [ $# -gt 0 ] && cat "$1" exit 1 } econf() { set -- \ "${ECONF_SOURCE:-.}/configure" \ --prefix=/usr \ --build=${CHOST} \ --host=${CHOST} \ --mandir=/usr/share/man \ --infodir=/usr/share/info \ --datadir=/usr/share \ --sysconfdir=/etc \ --infodir='${prefix}'/share/info \ --mandir='${prefix}'/share/man \ --localstatedir=/var/lib \ "$@" echo "$@" "$@" >.config.log 2>&1 || die .config.log } emake() { set -- make ${MAKEOPTS} "$@" echo "$@" "$@" >.build.log 2>&1 || die .build.log } src_fetch() { PN=$1 PV=$2 P="${PN}-${PV}" # The output might have $PV in it. eval A=\""$3"\" echo echo "bootstrapping ${P}" if [ ! -e "${DISTDIR}/${A}" ] ; then # The URL might have $PV in it. eval wget -P \'"${DISTDIR}"\' \""$4/${A}"\" fi } src_unpack() { export S="${PORTAGE_TMPDIR}/${P}" rm -rf "${S}" mkdir -p "${S}" cd "${S}" case ${A} in *bz2) tar -jxf "${DISTDIR}"/${A} || die ;; *gz) tar -zxf "${DISTDIR}"/${A} || die ;; *) die ;; esac cd "${S}"/*/ S=${PWD} } ###################### # bootstrap bash ###################### bootstrap_bash() { V=$(bash -c 'echo ${BASH_VERSINFO[0]}' 2>/dev/null) if [ "${V}" -ge 4 ] ; then echo echo "bash seems to be up-to-date; skipping" return 0 fi src_fetch bash ${BASH_VER} '${P}.tar.gz' http://ftp.gnu.org/gnu/bash src_unpack econf emake # Make sure it's an "atomic" update otherwise we'll get ETXTBSY. cp -a bash /bin/.bash mv /bin/.bash /bin/bash } ###################### # bootstrap python ###################### bootstrap_python() { if [ -x /usr/bin/python ] ; then echo echo "python seems to be up-to-date; skipping" echo "rm /usr/bin/python to force" return 0 fi src_fetch python ${PYTHON_VER} 'Python-${PV}.tgz' 'http://www.python.org/ftp/python/${PV%_*}' src_unpack export PYTHON_DISABLE_MODULES="readline pyexpat dbm gdbm bsddb _curses _curses_panel _tkinter" export PYTHON_DISABLE_SSL=1 export OPT="${CFLAGS}" econf \ --enable-unicode=ucs4 \ --with-fpectl \ --enable-shared \ --disable-ipv6 \ --with-threads \ --with-cxx=no emake emake altinstall ln -s python`expr substr ${PV} 1 3` /usr/bin/python } ###################### # bootstrap portage ###################### bootstrap_portage() { if [ -x /usr/bin/emerge ] ; then echo echo "emerge seems to be up-to-date; skipping" echo "rm /usr/bin/emerge to force" return 0 fi src_fetch portage ${PORTAGE_VER} '${P}.tar.bz2' http://distfiles.gentoo.org/distfiles src_unpack dodir() { mkdir -p "$@" ; } keepdir() { dodir "$@" ; } insinto() { INSDESTTREE=$1 ; } doins() { cp -a "$@" "$INSDESTTREE/" || die ; } newins() { cp -a "$1" "$INSDESTTREE/$2" || die ; } exeinto() { EXEDESTTREE=$1 ; } doexe() { install -m 755 "$@" "$EXEDESTTREE/" ; } get_libdir() { echo lib ; } dosym() { ln -sf "$@" || die ; } dodoc() { :; } src_install() { local libdir=$(get_libdir) local portage_base="/usr/${libdir}/portage" local portage_share_config=/usr/share/portage/config cd "${S}"/cnf insinto /etc doins etc-update.conf dispatch-conf.conf || die insinto "$portage_share_config" doins "$S/cnf/make.globals" || die if [ -f "make.conf.${ARCH}".diff ]; then patch make.conf "make.conf.${ARCH}".diff || \ die "Failed to patch make.conf.example" newins make.conf make.conf.example || die else eerror "" eerror "Portage does not have an arch-specific configuration for this arch." eerror "Please notify the arch maintainer about this issue. Using generic." eerror "" newins make.conf make.conf.example || die fi dosym ..${portage_share_config}/make.globals /etc/make.globals insinto /etc/logrotate.d doins "${S}"/cnf/logrotate.d/elog-save-summary || die # BSD and OSX need a sed wrapper so that find/xargs work properly if use userland_GNU; then rm "${S}"/bin/ebuild-helpers/sed || die "Failed to remove sed wrapper" fi local x symlinks files cd "$S" || die "cd failed" for x in $(find bin -type d) ; do exeinto $portage_base/$x || die "exeinto failed" cd "$S"/$x || die "cd failed" files=$(find . -mindepth 1 -maxdepth 1 -type f ! -type l) if [ -n "$files" ] ; then doexe $files || die "doexe failed" fi symlinks=$(find . -mindepth 1 -maxdepth 1 -type l) if [ -n "$symlinks" ] ; then cp -P $symlinks "$D$portage_base/$x" || die "cp failed" fi done cd "$S" || die "cd failed" for x in $(find pym/* -type d ! -path "pym/portage/tests*") ; do insinto $portage_base/$x || die "insinto failed" cd "$S"/$x || die "cd failed" # __pycache__ directories contain no py files [[ "*.py" != $(echo *.py) ]] || continue doins *.py || die "doins failed" symlinks=$(find . -mindepth 1 -maxdepth 1 -type l) if [ -n "$symlinks" ] ; then cp -P $symlinks "$D$portage_base/$x" || die "cp failed" fi done # We install some minimal tests for use as a preinst sanity check. # These tests must be able to run without a full source tree and # without relying on a previous portage instance being installed. cd "$S" || die "cd failed" exeinto $portage_base/pym/portage/tests || die doexe pym/portage/tests/runTests || die insinto $portage_base/pym/portage/tests || die doins pym/portage/tests/*.py || die insinto $portage_base/pym/portage/tests/lint || die doins pym/portage/tests/lint/*.py || die doins pym/portage/tests/lint/__test__ || die # Symlinks to directories cause up/downgrade issues and the use of these # modules outside of portage is probably negligible. for x in "${D}${portage_base}/pym/"{cache,elog_modules} ; do [ ! -L "${x}" ] && continue die "symlink to directory will cause upgrade/downgrade issues: '${x}'" done doman "${S}"/man/*.[0-9] if use linguas_pl; then doman -i18n=pl "${S_PL}"/man/pl/*.[0-9] doman -i18n=pl_PL.UTF-8 "${S_PL}"/man/pl_PL.UTF-8/*.[0-9] fi dodoc "${S}"/{ChangeLog,NEWS,RELEASE-NOTES} use doc && dohtml -r "${S}"/doc/* use epydoc && dohtml -r "${WORKDIR}"/api dodir /usr/bin for x in ebuild egencache emerge portageq quickpkg repoman ; do dosym ../${libdir}/portage/bin/${x} /usr/bin/${x} done dodir /usr/sbin local my_syms="archive-conf dispatch-conf emaint emerge-webrsync env-update etc-update fixpackages regenworld" local x for x in ${my_syms}; do dosym ../${libdir}/portage/bin/${x} /usr/sbin/${x} done dosym env-update /usr/sbin/update-env dosym etc-update /usr/sbin/update-etc dodir /etc/portage keepdir /etc/portage } set -x src_install set +x } ###################### # setup misc configs ###################### acct_setup() { grep -qs ^wheel: /etc/group || echo "wheel::10:root" >> /etc/group grep -qs ^portage: /etc/group || echo "portage::250:portage" >> /etc/group grep -qs ^portage: /etc/passwd || echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd } main() { if [ $# -ne 0 ] ; then usage fi env_init echo for v in ${ALL_VARS} ; do printf "%-20s = %s\n" "${v}" "$(v ${v})" done echo echo "Going to try to boostrap bash / python / portage if needed." echo "Bash ${BASH_VER}" echo "Python ${PYTHON_VER}" echo "Portage ${PORTAGE_VER}" echo echo "Press return to continue or CTRL+C to abort ..." read reply mkdir -p "${DISTDIR}" bootstrap_bash bootstrap_python bootstrap_portage acct_setup } main "$@"