1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 python3_3 python3_4 python3_5
12 PYTHON_REQ_USE='bzip2(+)'
14 inherit distutils-r1 multilib
16 DESCRIPTION="Portage is the package management and distribution system for Gentoo"
17 HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Portage"
20 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
22 IUSE="build doc epydoc +ipc linguas_ru selinux xattr"
24 DEPEND="!build? ( $(python_gen_impl_dep 'ssl(+)') )
26 dev-lang/python-exec:2
27 >=sys-apps/sed-4.0.5 sys-devel/patch
28 doc? ( app-text/xmlto ~app-text/docbook-xml-dtd-4.4 )
29 epydoc? ( >=dev-python/epydoc-2.0[$(python_gen_usedep 'python2*')] )"
30 # Require sandbox-2.2 for bug #288863.
31 # For xattr, we can spawn getfattr and setfattr from sys-apps/attr, but that's
32 # quite slow, so it's not considered in the dependencies as an alternative to
33 # to python-3.3 / pyxattr. Also, xattr support is only tested with Linux, so
34 # for now, don't pull in xattr deps for other kernels.
35 # For whirlpool hash, require python[ssl] (bug #425046).
36 # For compgen, require bash[readline] (bug #445576).
39 dev-lang/python-exec:2
42 app-shells/bash:0[readline]
43 >=app-admin/eselect-1.2
45 elibc_FreeBSD? ( sys-freebsd/freebsd-bin )
46 elibc_glibc? ( >=sys-apps/sandbox-2.2 )
47 elibc_uclibc? ( >=sys-apps/sandbox-2.2 )
48 >=app-misc/pax-utils-0.1.17
49 selinux? ( >=sys-libs/libselinux-2.0.94[python,${PYTHON_USEDEP}] )
50 xattr? ( kernel_linux? (
51 >=sys-apps/install-xattr-0.3
52 $(python_gen_cond_dep 'dev-python/pyxattr[${PYTHON_USEDEP}]' \
55 !<app-admin/logrotate-3.8.0"
58 >=net-misc/rsync-2.6.4
59 userland_GNU? ( >=sys-apps/coreutils-6.4 )
61 # coreutils-6.4 rdep is for date format in emerge-webrsync #164532
62 # NOTE: FEATURES=installsources requires debugedit and rsync
64 REQUIRED_USE="epydoc? ( $(python_gen_useflags 'python2*') )"
66 SRC_ARCHIVES="https://dev.gentoo.org/~dolsen/releases/portage"
68 prefix_src_archives() {
71 for y in ${SRC_ARCHIVES}; do
78 SRC_URI="mirror://gentoo/${PN}-${TARBALL_PV}.tar.bz2
79 $(prefix_src_archives ${PN}-${TARBALL_PV}.tar.bz2)"
82 use epydoc && DISTUTILS_ALL_SUBPHASE_IMPLS=( python2.7 )
85 python_prepare_all() {
86 distutils-r1_python_prepare_all
89 einfo "Disabling ipc..."
90 sed -e "s:_enable_ipc_daemon = True:_enable_ipc_daemon = False:" \
91 -i pym/_emerge/AbstractEbuildProcess.py || \
92 die "failed to patch AbstractEbuildProcess.py"
95 if use xattr && use kernel_linux ; then
96 einfo "Adding FEATURES=xattr to make.globals ..."
97 echo -e '\nFEATURES="${FEATURES} xattr"' >> cnf/make.globals \
98 || die "failed to append to make.globals"
101 if [[ -n ${EPREFIX} ]] ; then
102 einfo "Setting portage.const.EPREFIX ..."
103 sed -e "s|^\(SANDBOX_BINARY[[:space:]]*=[[:space:]]*\"\)\(/usr/bin/sandbox\"\)|\\1${EPREFIX}\\2|" \
104 -e "s|^\(FAKEROOT_BINARY[[:space:]]*=[[:space:]]*\"\)\(/usr/bin/fakeroot\"\)|\\1${EPREFIX}\\2|" \
105 -e "s|^\(BASH_BINARY[[:space:]]*=[[:space:]]*\"\)\(/bin/bash\"\)|\\1${EPREFIX}\\2|" \
106 -e "s|^\(MOVE_BINARY[[:space:]]*=[[:space:]]*\"\)\(/bin/mv\"\)|\\1${EPREFIX}\\2|" \
107 -e "s|^\(PRELINK_BINARY[[:space:]]*=[[:space:]]*\"\)\(/usr/sbin/prelink\"\)|\\1${EPREFIX}\\2|" \
108 -e "s|^\(EPREFIX[[:space:]]*=[[:space:]]*\"\).*|\\1${EPREFIX}\"|" \
109 -i pym/portage/const.py || \
110 die "Failed to patch portage.const.EPREFIX"
112 einfo "Prefixing shebangs ..."
113 while read -r -d $'\0' ; do
114 local shebang=$(head -n1 "$REPLY")
115 if [[ ${shebang} == "#!"* && ! ${shebang} == "#!${EPREFIX}/"* ]] ; then
116 sed -i -e "1s:.*:#!${EPREFIX}${shebang:2}:" "$REPLY" || \
119 done < <(find . -type f -print0)
121 einfo "Adjusting make.globals ..."
122 sed -e "s|\(/usr/portage\)|${EPREFIX}\\1|" \
123 -e "s|^\(PORTAGE_TMPDIR=\"\)\(/var/tmp\"\)|\\1${EPREFIX}\\2|" \
124 -i cnf/make.globals || die "sed failed"
126 einfo "Adjusting repos.conf ..."
127 sed -e "s|^\(main-repo = \).*|\\1gentoo_prefix|" \
128 -e "s|^\\[gentoo\\]|[gentoo_prefix]|" \
129 -e "s|^\(location = \)\(/usr/portage\)|\\1${EPREFIX}\\2|" \
130 -e "s|^\(sync-uri = \).*|\\1rsync://rsync.prefix.bitzolder.nl/gentoo-portage-prefix|" \
131 -i cnf/repos.conf || die "sed failed"
133 einfo "Adding FEATURES=force-prefix to make.globals ..."
134 echo -e '\nFEATURES="${FEATURES} force-prefix"' >> cnf/make.globals \
135 || die "failed to append to make.globals"
139 if [ -f "make.conf.example.${ARCH}".diff ]; then
140 patch make.conf.example "make.conf.example.${ARCH}".diff || \
141 die "Failed to patch make.conf.example"
144 eerror "Portage does not have an arch-specific configuration for this arch."
145 eerror "Please notify the arch maintainer about this issue. Using generic."
150 python_compile_all() {
152 use doc && targets+=( docbook )
153 use epydoc && targets+=( epydoc )
155 if [[ ${targets[@]} ]]; then
156 esetup.py "${targets[@]}"
165 # Install sbin scripts to bindir for python-exec linking
166 # they will be relocated in pkg_preinst()
167 distutils-r1_python_install \
168 --system-prefix="${EPREFIX}/usr" \
169 --bindir="$(python_get_scriptdir)" \
170 --docdir="${EPREFIX}/usr/share/doc/${PF}" \
171 --htmldir="${EPREFIX}/usr/share/doc/${PF}/html" \
172 --portage-bindir="${EPREFIX}/usr/lib/portage/${EPYTHON}" \
173 --sbindir="$(python_get_scriptdir)" \
174 --sysconfdir="${EPREFIX}/etc" \
178 python_install_all() {
179 distutils-r1_python_install_all
182 use doc && targets+=( install_docbook )
183 use epydoc && targets+=( install_epydoc )
186 if [[ ${targets[@]} ]]; then
187 esetup.py "${targets[@]}"
190 # Due to distutils/python-exec limitations
191 # these must be installed to /usr/bin.
192 local sbin_relocations='archive-conf dispatch-conf emaint env-update etc-update fixpackages regenworld'
193 einfo "Moving admin scripts to the correct directory"
195 for target in ${sbin_relocations}; do
196 einfo "Moving /usr/bin/${target} to /usr/sbin/${target}"
197 mv "${ED}usr/bin/${target}" "${ED}usr/sbin/${target}" || die "sbin scripts move failed!"
202 # comment out sanity test until it is fixed to work
203 # with the new PORTAGE_PYM_PATH
204 #if [[ $ROOT == / ]] ; then
205 ## Run some minimal tests as a sanity check.
206 #local test_runner=$(find "${ED}" -name runTests)
207 #if [[ -n $test_runner && -x $test_runner ]] ; then
208 #einfo "Running preinst sanity tests..."
209 #"$test_runner" || die "preinst sanity tests failed"
213 # elog dir must exist to avoid logrotate error for bug #415911.
214 # This code runs in preinst in order to bypass the mapping of
215 # portage:portage to root:root which happens after src_install.
216 keepdir /var/log/portage/elog
217 # This is allowed to fail if the user/group are invalid for prefix users.
218 if chown portage:portage "${ED}"var/log/portage{,/elog} 2>/dev/null ; then
219 chmod g+s,ug+rwx "${ED}"var/log/portage{,/elog}
222 if has_version "<${CATEGORY}/${PN}-2.1.13" || \
224 has_version ">=${CATEGORY}/${PN}-2.2_rc0" && \
225 has_version "<${CATEGORY}/${PN}-2.2.0_alpha189"
227 USERPRIV_UPGRADE=true
228 USERSYNC_UPGRADE=true
229 REPOS_CONF_UPGRADE=true
231 type -P portageq >/dev/null 2>&1 && \
232 REPOS_CONF_SYNC=$("$(type -P portageq)" envvar SYNC)
234 USERPRIV_UPGRADE=false
235 USERSYNC_UPGRADE=false
236 REPOS_CONF_UPGRADE=false
243 stat -f '%Su:%Sg' "${1}"
246 stat -c '%U:%G' "${1}"
251 new_config_protect() {
252 # Generate a ._cfg file even if the target file
253 # does not exist, ensuring that the user will
254 # notice the config change.
255 local basename=${1##*/}
256 local dirname=${1%/*}
260 echo -n "${dirname}/._cfg"
262 echo -n "_${basename}"
264 [[ -e ${filename} ]] || break
272 if ${REPOS_CONF_UPGRADE} ; then
273 einfo "Generating repos.conf"
275 [[ -f ${PORTDIR}/profiles/repo_name ]] && \
276 repo_name=$(< "${PORTDIR}/profiles/repo_name")
277 if [[ -z ${REPOS_CONF_SYNC} ]] ; then
278 REPOS_CONF_SYNC=$(grep "^sync-uri =" "${EROOT:-${ROOT}}usr/share/portage/config/repos.conf")
279 REPOS_CONF_SYNC=${REPOS_CONF_SYNC##* }
282 [[ ${REPOS_CONF_SYNC} == git://* ]] && sync_type=git
284 if [[ ${REPOS_CONF_SYNC} == cvs://* ]]; then
286 REPOS_CONF_SYNC=${REPOS_CONF_SYNC#cvs://}
289 cat <<-EOF > "${T}/repos.conf"
291 main-repo = ${repo_name:-gentoo}
293 [${repo_name:-gentoo}]
294 location = ${PORTDIR:-${EPREFIX}/usr/portage}
295 sync-type = ${sync_type:-rsync}
296 sync-uri = ${REPOS_CONF_SYNC}
299 [[ ${sync_type} == cvs ]] && echo "sync-cvs-repo = $(<"${PORTDIR}/CVS/Repository")" >> "${T}/repos.conf"
301 local dest=${EROOT:-${ROOT}}etc/portage/repos.conf
302 if [[ ! -f ${dest} ]] && mkdir -p "${dest}" 2>/dev/null ; then
303 dest=${EROOT:-${ROOT}}etc/portage/repos.conf/${repo_name:-gentoo}.conf
305 # Don't install the config update if the desired repos.conf directory
306 # and config file exist, since users may accept it blindly and break
307 # their config (bug #478726).
308 [[ -e ${EROOT:-${ROOT}}etc/portage/repos.conf/${repo_name:-gentoo}.conf ]] || \
309 mv "${T}/repos.conf" "$(new_config_protect "${dest}")"
311 if [[ ${PORTDIR} == ${EPREFIX}/usr/portage ]] ; then
312 einfo "Generating make.conf PORTDIR setting for backward compatibility"
313 for dest in "${EROOT:-${ROOT}}etc/make.conf" "${EROOT:-${ROOT}}etc/portage/make.conf" ; do
314 [[ -e ${dest} ]] && break
316 [[ -d ${dest} ]] && dest=${dest}/portdir.conf
317 rm -rf "${T}/make.conf"
318 [[ -f ${dest} ]] && cat "${dest}" > "${T}/make.conf"
319 cat <<-EOF >> "${T}/make.conf"
321 # Set PORTDIR for backward compatibility with various tools:
322 # gentoo-bashcomp - bug #478444
324 # euses and ufed - bug #478318
325 PORTDIR="${EPREFIX}/usr/portage"
327 mkdir -p "${dest%/*}"
328 mv "${T}/make.conf" "$(new_config_protect "${dest}")"
332 local distdir=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}
334 if ${USERSYNC_UPGRADE} && \
335 [[ -d ${PORTDIR} && -w ${PORTDIR} ]] ; then
336 local ownership=$(get_ownership "${PORTDIR}")
337 if [[ -n ${ownership} ]] ; then
338 einfo "Adjusting PORTDIR permissions for usersync"
339 find "${PORTDIR}" -path "${distdir%/}" -prune -o \
340 ! \( -user "${ownership%:*}" -a -group "${ownership#*:}" \) \
341 -exec chown "${ownership}" {} +
345 # Do this last, since it could take a long time if there
346 # are lots of live sources, and the user may be tempted
347 # to kill emerge while it is running.
348 if ${USERPRIV_UPGRADE} && \
349 [[ -d ${distdir} && -w ${distdir} ]] ; then
350 local ownership=$(get_ownership "${distdir}")
351 if [[ ${ownership#*:} == portage ]] ; then
352 einfo "Adjusting DISTDIR permissions for userpriv"
353 find "${distdir}" -mindepth 1 -maxdepth 1 -type d -uid 0 \
354 -exec chown -R portage:portage {} +
359 einfo "This release of portage contains the new repoman code base"
360 einfo "This code base is still being developed. So its API's are"
361 einfo "not to be considered stable and are subject to change."
362 einfo "The code released has been tested and considered ready for use."
363 einfo "This however does not guarantee it to be completely bug free."
364 einfo "Please report any bugs you may encounter."