sys-apps/portage: use an existing host for Prefix rsync
[gentoo.git] / sys-apps / portage / portage-2.2.27.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 PYTHON_COMPAT=(
8         pypy
9         python3_3 python3_4 python3_5
10         python2_7
11 )
12 PYTHON_REQ_USE='bzip2(+)'
13
14 inherit distutils-r1 multilib
15
16 DESCRIPTION="Portage is the package management and distribution system for Gentoo"
17 HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Portage"
18
19 LICENSE="GPL-2"
20 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
21 SLOT="0"
22 IUSE="build doc epydoc +ipc linguas_ru selinux xattr"
23
24 DEPEND="!build? ( $(python_gen_impl_dep 'ssl(+)') )
25         >=app-arch/tar-1.27
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).
37 RDEPEND="
38         >=app-arch/tar-1.27
39         dev-lang/python-exec:2
40         !build? (
41                 >=sys-apps/sed-4.0.5
42                 app-shells/bash:0[readline]
43                 >=app-admin/eselect-1.2
44         )
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}]' \
53                         python2_7 pypy)
54         ) )
55         !<app-admin/logrotate-3.8.0"
56 PDEPEND="
57         !build? (
58                 >=net-misc/rsync-2.6.4
59                 userland_GNU? ( >=sys-apps/coreutils-6.4 )
60         )"
61 # coreutils-6.4 rdep is for date format in emerge-webrsync #164532
62 # NOTE: FEATURES=installsources requires debugedit and rsync
63
64 REQUIRED_USE="epydoc? ( $(python_gen_useflags 'python2*') )"
65
66 SRC_ARCHIVES="https://dev.gentoo.org/~dolsen/releases/portage"
67
68 prefix_src_archives() {
69         local x y
70         for x in ${@}; do
71                 for y in ${SRC_ARCHIVES}; do
72                         echo ${y}/${x}
73                 done
74         done
75 }
76
77 TARBALL_PV=${PV}
78 SRC_URI="mirror://gentoo/${PN}-${TARBALL_PV}.tar.bz2
79         $(prefix_src_archives ${PN}-${TARBALL_PV}.tar.bz2)"
80
81 pkg_setup() {
82         use epydoc && DISTUTILS_ALL_SUBPHASE_IMPLS=( python2.7 )
83 }
84
85 python_prepare_all() {
86         distutils-r1_python_prepare_all
87
88         if ! use ipc ; then
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"
93         fi
94
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"
99         fi
100
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"
111
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" || \
117                                         die "sed failed"
118                         fi
119                 done < <(find . -type f -print0)
120
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"
125
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"
132
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"
136         fi
137
138         cd "${S}/cnf" || die
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"
142         else
143                 eerror ""
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."
146                 eerror ""
147         fi
148 }
149
150 python_compile_all() {
151         local targets=()
152         use doc && targets+=( docbook )
153         use epydoc && targets+=( epydoc )
154
155         if [[ ${targets[@]} ]]; then
156                 esetup.py "${targets[@]}"
157         fi
158 }
159
160 python_test() {
161         esetup.py test
162 }
163
164 python_install() {
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" \
175                 "${@}"
176 }
177
178 python_install_all() {
179         distutils-r1_python_install_all
180
181         local targets=()
182         use doc && targets+=( install_docbook )
183         use epydoc && targets+=( install_epydoc )
184
185         # install docs
186         if [[ ${targets[@]} ]]; then
187                 esetup.py "${targets[@]}"
188         fi
189
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"
194         dodir /usr/sbin
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!"
198         done
199 }
200
201 pkg_preinst() {
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"
210                 #fi
211         #fi
212
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}
220         fi
221
222         if has_version "<${CATEGORY}/${PN}-2.1.13" || \
223                 {
224                         has_version ">=${CATEGORY}/${PN}-2.2_rc0" && \
225                         has_version "<${CATEGORY}/${PN}-2.2.0_alpha189"
226                 } ; then
227                 USERPRIV_UPGRADE=true
228                 USERSYNC_UPGRADE=true
229                 REPOS_CONF_UPGRADE=true
230                 REPOS_CONF_SYNC=
231                 type -P portageq >/dev/null 2>&1 && \
232                         REPOS_CONF_SYNC=$("$(type -P portageq)" envvar SYNC)
233         else
234                 USERPRIV_UPGRADE=false
235                 USERSYNC_UPGRADE=false
236                 REPOS_CONF_UPGRADE=false
237         fi
238 }
239
240 get_ownership() {
241         case ${USERLAND} in
242                 BSD)
243                         stat -f '%Su:%Sg' "${1}"
244                         ;;
245                 *)
246                         stat -c '%U:%G' "${1}"
247                         ;;
248         esac
249 }
250
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%/*}
257         local i=0
258         while true ; do
259                 local filename=$(
260                         echo -n "${dirname}/._cfg"
261                         printf "%04d" ${i}
262                         echo -n "_${basename}"
263                 )
264                 [[ -e ${filename} ]] || break
265                 (( i++ ))
266         done
267         echo "${filename}"
268 }
269
270 pkg_postinst() {
271
272         if ${REPOS_CONF_UPGRADE} ; then
273                 einfo "Generating repos.conf"
274                 local repo_name=
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##* }
280                 fi
281                 local sync_type=
282                 [[ ${REPOS_CONF_SYNC} == git://* ]] && sync_type=git
283
284                 if [[ ${REPOS_CONF_SYNC} == cvs://* ]]; then
285                         sync_type=cvs
286                         REPOS_CONF_SYNC=${REPOS_CONF_SYNC#cvs://}
287                 fi
288
289                 cat <<-EOF > "${T}/repos.conf"
290                 [DEFAULT]
291                 main-repo = ${repo_name:-gentoo}
292
293                 [${repo_name:-gentoo}]
294                 location = ${PORTDIR:-${EPREFIX}/usr/portage}
295                 sync-type = ${sync_type:-rsync}
296                 sync-uri = ${REPOS_CONF_SYNC}
297                 EOF
298
299                 [[ ${sync_type} == cvs ]] && echo "sync-cvs-repo = $(<"${PORTDIR}/CVS/Repository")" >> "${T}/repos.conf"
300
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
304                 fi
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}")"
310
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
315                         done
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"
320
321                         # Set PORTDIR for backward compatibility with various tools:
322                         #   gentoo-bashcomp - bug #478444
323                         #   euse - bug #474574
324                         #   euses and ufed - bug #478318
325                         PORTDIR="${EPREFIX}/usr/portage"
326                         EOF
327                         mkdir -p "${dest%/*}"
328                         mv "${T}/make.conf" "$(new_config_protect "${dest}")"
329                 fi
330         fi
331
332         local distdir=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}
333
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}" {} +
342                 fi
343         fi
344
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 {} +
355                 fi
356         fi
357
358         einfo ""
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."
365         einfo ""
366 }