2009-10-18 09:17:26 +00:00
|
|
|
#-
|
2011-07-01 15:48:29 +00:00
|
|
|
# Copyright (c) 2008-2011 Juan Romero Pardines.
|
2009-10-18 09:17:26 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
2011-07-03 08:20:15 +00:00
|
|
|
#
|
|
|
|
# Install a required package dependency, like:
|
|
|
|
#
|
2011-10-24 19:24:43 +00:00
|
|
|
# xbps-bin -Ay install "pattern"
|
2011-07-03 08:20:15 +00:00
|
|
|
#
|
2011-06-30 08:23:48 +00:00
|
|
|
install_pkg_from_repos()
|
|
|
|
{
|
2011-11-10 13:33:59 +00:00
|
|
|
local rval tmplogf tmpdepf
|
2011-10-14 17:08:56 +00:00
|
|
|
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_normal "$pkgver: installing '$1'... "
|
|
|
|
|
2011-11-08 10:56:17 +00:00
|
|
|
case "${XBPS_VERSION}" in
|
2011-10-31 03:04:31 +00:00
|
|
|
0.1[1-9].[0-9]*)
|
|
|
|
_pkgdepname=$($XBPS_PKGDB_CMD getpkgdepname "$1")
|
2011-11-01 11:09:06 +00:00
|
|
|
$XBPS_REPO_CMD -oversion show ${_pkgdepname} >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_normal_append "not found, building from source...\n"
|
|
|
|
return 2
|
|
|
|
fi
|
2011-10-31 03:04:31 +00:00
|
|
|
_pkgver=$($XBPS_REPO_CMD} -oversion show ${_pkgdepname})
|
2011-11-10 13:33:59 +00:00
|
|
|
msg_normal_append "found ${_pkgver} "
|
|
|
|
$XBPS_PKGDB_CMD pkgmatch "${_pkgdepname}-${_pkgver}" "${1}"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
_repoloc=$($XBPS_REPO_CMD} -orepository show ${_pkgdepname})
|
|
|
|
msg_normal_append "(${_repoloc})\n"
|
|
|
|
else
|
|
|
|
msg_normal_append "not matched, building from source...\n"
|
|
|
|
return 2
|
|
|
|
fi
|
2011-10-31 03:04:31 +00:00
|
|
|
;;
|
|
|
|
*) msg_normal_append "\n";;
|
|
|
|
esac
|
2011-10-14 17:08:56 +00:00
|
|
|
|
2011-10-24 11:58:59 +00:00
|
|
|
tmplogf=$(mktemp)
|
2011-11-10 13:33:59 +00:00
|
|
|
$FAKEROOT_CMD $FAKEROOT_CMD_ARGS $XBPS_BIN_CMD -Ay install ${_pkgdepname} >$tmplogf 2>&1
|
2011-06-30 08:23:48 +00:00
|
|
|
rval=$?
|
2011-07-02 23:27:55 +00:00
|
|
|
if [ $rval -ne 0 -a $rval -ne 6 ]; then
|
|
|
|
# xbps-bin can return:
|
|
|
|
#
|
|
|
|
# SUCCESS (0): package installed successfully.
|
|
|
|
# ENOENT (2): package missing in repositories.
|
|
|
|
# EEXIST (6): package already installed.
|
|
|
|
# ENODEV (19): package depends on missing dependencies.
|
|
|
|
#
|
2011-10-04 20:01:12 +00:00
|
|
|
# Any other error returned is critical.
|
2011-07-04 19:29:11 +00:00
|
|
|
autoremove_pkg_dependencies $KEEP_AUTODEPS
|
2011-10-24 19:24:43 +00:00
|
|
|
msg_red "$pkgver: failed to install '$1' dependency! (error $rval)\n"
|
2011-10-24 11:58:59 +00:00
|
|
|
cat $tmplogf && rm -f $tmplogf
|
2011-10-04 20:01:12 +00:00
|
|
|
msg_error "Please see above for the real error, exiting...\n"
|
2011-06-30 08:23:48 +00:00
|
|
|
fi
|
2011-10-24 11:58:59 +00:00
|
|
|
rm -f $tmplogf
|
2011-06-30 08:23:48 +00:00
|
|
|
|
|
|
|
return $rval
|
|
|
|
}
|
|
|
|
|
2011-07-01 15:48:29 +00:00
|
|
|
autoremove_pkg_dependencies()
|
2011-06-30 08:23:48 +00:00
|
|
|
{
|
2011-07-14 22:15:09 +00:00
|
|
|
local cmd curpkgname f
|
2011-06-30 08:23:48 +00:00
|
|
|
|
2011-07-04 19:29:11 +00:00
|
|
|
[ -n "$1" ] && return 0
|
2011-07-04 17:07:08 +00:00
|
|
|
|
2011-11-08 10:56:17 +00:00
|
|
|
cmd="${FAKEROOT_CMD} ${FAKEROOT_CMD_ARGS} ${XBPS_BIN_CMD}"
|
2011-06-30 08:23:48 +00:00
|
|
|
|
|
|
|
# If XBPS_PREFER_BINPKG_DEPS is set, we should remove those
|
|
|
|
# package dependencies installed by the target package, do it.
|
|
|
|
#
|
2011-07-06 06:16:56 +00:00
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$bootstrap" ]; then
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_normal "$pkgver: removing automatically installed dependencies ...\n"
|
2011-07-01 15:48:29 +00:00
|
|
|
# Autoremove installed binary packages.
|
2011-06-30 08:23:48 +00:00
|
|
|
${cmd} -y reconfigure all && ${cmd} -Rpyf autoremove 2>&1 >/dev/null
|
2011-07-01 15:48:29 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_red "$pkgver: failed to remove automatic dependencies!\n"
|
2011-07-02 23:27:55 +00:00
|
|
|
exit 1
|
2011-07-01 15:48:29 +00:00
|
|
|
fi
|
2011-06-30 08:23:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
|
|
|
# Recursive function that installs all direct and indirect
|
|
|
|
# dependencies of a package.
|
|
|
|
#
|
|
|
|
install_pkg_deps()
|
|
|
|
{
|
|
|
|
local curpkg="$1"
|
2011-11-08 10:56:17 +00:00
|
|
|
local curpkgname=$(${XBPS_PKGDB_CMD} getpkgdepname "$1")
|
|
|
|
local saved_prevpkg=$(${XBPS_PKGDB_CMD} getpkgdepname "$2")
|
|
|
|
local j jver jname reqver
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2010-05-12 15:23:35 +00:00
|
|
|
[ -z "$curpkg" -o -z "$curpkgname" ] && return 2
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
if [ -n "$prev_pkg" ]; then
|
|
|
|
curpkg=$prev_pkg
|
2009-11-07 04:01:00 +00:00
|
|
|
curpkgname="$(${XBPS_PKGDB_CMD} getpkgdepname ${curpkg})"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
|
2011-07-01 15:48:29 +00:00
|
|
|
check_pkgdep_matched "$curpkg"
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
|
2010-05-13 22:07:47 +00:00
|
|
|
if [ -z "$saved_prevpkg" -a -n "${_ORIGINPKG}" ]; then
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_normal "Installing ${_ORIGINPKG} dependency: '$curpkg'.\n"
|
2010-05-13 22:07:47 +00:00
|
|
|
else
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_normal "Installing $saved_prevpkg dependency: '$curpkg'.\n"
|
2010-05-13 22:07:47 +00:00
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2010-05-12 15:23:35 +00:00
|
|
|
setup_tmpl "$curpkgname"
|
2009-10-18 09:17:26 +00:00
|
|
|
check_build_depends_pkg
|
|
|
|
if [ $? -eq 0 ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_normal "Package '$curpkgname' requires:\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
for j in ${build_depends}; do
|
2009-11-07 04:01:00 +00:00
|
|
|
jname="$(${XBPS_PKGDB_CMD} getpkgdepname ${j})"
|
|
|
|
jver="$($XBPS_PKGDB_CMD version ${jname})"
|
|
|
|
check_pkgdep_matched "${j}"
|
|
|
|
if [ $? -eq 0 ]; then
|
2010-05-13 22:07:47 +00:00
|
|
|
echo " ${j}: found '$jname-$jver'."
|
2009-11-07 04:01:00 +00:00
|
|
|
else
|
|
|
|
echo " ${j}: not found."
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-11-08 10:56:17 +00:00
|
|
|
for j in ${build_depends}; do
|
2011-07-01 15:48:29 +00:00
|
|
|
prev_pkg="$j"
|
2011-07-06 06:16:56 +00:00
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$bootstrap" ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
install_pkg_from_repos "${j}"
|
2011-07-01 15:48:29 +00:00
|
|
|
if [ $? -eq 255 ]; then
|
|
|
|
# xbps-bin returned unexpected error
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_red "$saved_prevpkg: failed to install '$j'\n"
|
2011-07-01 15:48:29 +00:00
|
|
|
elif [ $? -eq 0 ]; then
|
|
|
|
# package installed successfully.
|
|
|
|
:
|
|
|
|
continue
|
|
|
|
fi
|
2011-10-28 09:22:30 +00:00
|
|
|
else
|
|
|
|
#
|
|
|
|
# Iterate again, this will check if there are more
|
|
|
|
# required deps for current pkg.
|
|
|
|
#
|
|
|
|
install_pkg_deps "${j}" "${curpkg}"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
if [ -n "$saved_prevpkg" ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_red "$saved_prevpkg: failed to install '$curpkg'\n"
|
2011-10-28 09:22:30 +00:00
|
|
|
else
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_red "${_ORIGINPKG}: failed to install '$curpkg'\n"
|
2011-10-28 09:22:30 +00:00
|
|
|
fi
|
|
|
|
return 1
|
2011-07-01 15:48:29 +00:00
|
|
|
fi
|
2010-05-12 15:23:35 +00:00
|
|
|
fi
|
2009-11-07 04:01:00 +00:00
|
|
|
done
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2011-07-06 06:16:56 +00:00
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$bootstrap" ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
install_pkg_from_repos "${curpkg}"
|
2010-01-16 01:11:44 +00:00
|
|
|
if [ $? -eq 255 ]; then
|
|
|
|
# xbps-bin returned unexpected error
|
|
|
|
return $?
|
2011-07-02 20:53:03 +00:00
|
|
|
elif [ $? -eq 2 ]; then
|
2010-01-16 01:11:44 +00:00
|
|
|
# Package not found, build from source.
|
2010-05-12 15:23:35 +00:00
|
|
|
install_pkg "${curpkgname}"
|
|
|
|
if [ $? -eq 1 ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_red "$saved_prevpkg: failed to install '$curpkg'\n"
|
2010-05-12 15:23:35 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2010-01-16 01:11:44 +00:00
|
|
|
fi
|
|
|
|
else
|
2010-05-12 15:23:35 +00:00
|
|
|
if [ -n "$saved_prevpkg" ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_normal "$saved_prevpkg: installing '$curpkg'...\n"
|
2010-05-12 15:23:35 +00:00
|
|
|
else
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_normal "${_ORIGINPKG}: installing '$curpkg'...\n"
|
2010-05-12 15:23:35 +00:00
|
|
|
fi
|
|
|
|
install_pkg "${curpkgname}"
|
|
|
|
if [ $? -eq 1 ]; then
|
2011-10-31 03:04:31 +00:00
|
|
|
msg_red "$saved_prevpkg: failed to install '$curpkg'\n"
|
2010-05-12 15:23:35 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2010-01-16 01:11:44 +00:00
|
|
|
fi
|
2010-05-12 15:23:35 +00:00
|
|
|
unset prev_pkg
|
2009-10-18 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Installs all dependencies required by a package.
|
|
|
|
#
|
|
|
|
install_dependencies_pkg()
|
|
|
|
{
|
2011-10-24 11:58:59 +00:00
|
|
|
local pkg="$1"
|
2011-10-24 19:24:43 +00:00
|
|
|
local i pkgn iver missing_deps
|
2011-10-31 03:04:31 +00:00
|
|
|
trap "msg_error 'interrupted\n'" INT
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2010-05-12 15:23:35 +00:00
|
|
|
[ -z "$pkg" ] && return 2
|
2011-07-01 15:48:29 +00:00
|
|
|
[ -z "$build_depends" ] && return 0
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2011-07-01 15:48:29 +00:00
|
|
|
INSTALLING_DEPS=1
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_normal "$pkgver: required build dependencies...\n"
|
2011-07-01 15:48:29 +00:00
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
for i in ${build_depends}; do
|
2011-10-03 19:36:42 +00:00
|
|
|
pkgn=$($XBPS_PKGDB_CMD getpkgdepname "${i}")
|
|
|
|
iver=$($XBPS_PKGDB_CMD version "${pkgn}")
|
2009-11-07 04:01:00 +00:00
|
|
|
check_pkgdep_matched "${i}"
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2010-05-13 22:07:47 +00:00
|
|
|
echo " ${i}: found '$pkgn-$iver'."
|
2009-10-18 09:17:26 +00:00
|
|
|
else
|
2010-05-13 20:22:05 +00:00
|
|
|
echo " ${i}: not found."
|
2011-10-31 03:04:31 +00:00
|
|
|
if [ -z "$missing_deps" ]; then
|
|
|
|
missing_deps="${i}"
|
|
|
|
else
|
|
|
|
missing_deps="${missing_deps} ${i}"
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-10-24 19:24:43 +00:00
|
|
|
[ -z "$missing_deps" ] && return 0
|
2011-07-04 17:07:08 +00:00
|
|
|
|
2011-07-01 15:48:29 +00:00
|
|
|
# Install direct build dependencies from binary packages.
|
2011-07-06 06:16:56 +00:00
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$bootstrap" ]; then
|
2011-07-18 14:25:18 +00:00
|
|
|
msg_normal "$pkgver: installing dependencies from repositories ...\n"
|
2011-10-31 03:04:31 +00:00
|
|
|
for i in ${missing_deps}; do
|
2011-10-29 16:49:03 +00:00
|
|
|
install_pkg_from_repos "${i}"
|
2011-11-01 11:09:06 +00:00
|
|
|
if [ $? -eq 2 ]; then
|
|
|
|
# ENOENT; install from source
|
|
|
|
install_pkg_deps "${i}" "${pkg}" || return 1
|
|
|
|
curpkgdepname="$($XBPS_PKGDB_CMD getpkgdepname ${i})"
|
|
|
|
setup_tmpl $curpkgdepname
|
|
|
|
install_pkg $curpkgdepname
|
|
|
|
setup_tmpl $($XBPS_PKGDB_CMD getpkgname ${pkg})
|
|
|
|
install_dependencies_pkg "${pkg}"
|
|
|
|
fi
|
2010-04-27 21:09:08 +00:00
|
|
|
done
|
2011-10-26 17:47:52 +00:00
|
|
|
else
|
|
|
|
# Install direct and indirect build dependencies from source.
|
2011-10-31 03:04:31 +00:00
|
|
|
for i in ${missing_deps}; do
|
2011-10-26 17:47:52 +00:00
|
|
|
install_pkg_deps "${i}" "${pkg}" || return 1
|
|
|
|
done
|
2010-04-27 21:09:08 +00:00
|
|
|
fi
|
2011-10-31 03:04:31 +00:00
|
|
|
|
|
|
|
# unregister sighandler.
|
|
|
|
trap - INT
|
2009-10-18 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2011-07-01 15:48:29 +00:00
|
|
|
# Returns 0 if pkgpattern in $1 is matched against current installed
|
|
|
|
# package, 1 otherwise.
|
2009-11-07 04:01:00 +00:00
|
|
|
#
|
|
|
|
check_pkgdep_matched()
|
|
|
|
{
|
2011-10-28 09:07:05 +00:00
|
|
|
local pkg="$1" pkgn iver
|
2009-11-07 04:01:00 +00:00
|
|
|
|
|
|
|
[ -z "$pkg" ] && return 2
|
|
|
|
|
2011-10-28 09:07:05 +00:00
|
|
|
pkgn="$($XBPS_PKGDB_CMD getpkgdepname ${pkg})"
|
|
|
|
[ -z "$pkgn" ] && return 2
|
2009-11-07 04:01:00 +00:00
|
|
|
|
2011-10-28 09:07:05 +00:00
|
|
|
iver="$($XBPS_PKGDB_CMD version $pkgn)"
|
2009-11-07 04:01:00 +00:00
|
|
|
if [ -n "$iver" ]; then
|
2011-10-28 09:07:05 +00:00
|
|
|
${XBPS_PKGDB_CMD} pkgmatch "${pkgn}-${iver}" "${pkg}"
|
2009-11-07 04:01:00 +00:00
|
|
|
[ $? -eq 1 ] && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2011-07-01 15:48:29 +00:00
|
|
|
# Returns 0 if pkgpattern in $1 is installed and greater than current
|
|
|
|
# installed package, otherwise 1.
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
|
|
|
check_installed_pkg()
|
|
|
|
{
|
2011-10-28 09:07:05 +00:00
|
|
|
local pkg="$1" pkgn iver
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
[ -z "$pkg" ] && return 2
|
|
|
|
|
2011-10-28 09:07:05 +00:00
|
|
|
pkgn="$($XBPS_PKGDB_CMD getpkgname ${pkg})"
|
|
|
|
[ -z "$pkgn" ] && return 2
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2011-10-28 09:07:05 +00:00
|
|
|
iver="$($XBPS_PKGDB_CMD version $pkgn)"
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ -n "$iver" ]; then
|
2011-10-28 09:07:05 +00:00
|
|
|
${XBPS_CMPVER_CMD} "${pkgn}-${iver}" "${pkg}"
|
2009-10-18 09:17:26 +00:00
|
|
|
[ $? -eq 0 -o $? -eq 1 ] && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2011-07-01 15:48:29 +00:00
|
|
|
# Returns 0 if pkg has build deps, 1 otherwise.
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
|
|
|
check_build_depends_pkg()
|
|
|
|
{
|
|
|
|
[ -z "$pkgname" ] && return 2
|
|
|
|
|
|
|
|
if [ -n "$build_depends" ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|