2008-12-13 04:23:16 +00:00
|
|
|
#-
|
2009-02-17 23:28:35 +00:00
|
|
|
# Copyright (c) 2008-2009 Juan Romero Pardines.
|
2008-12-13 04:23:16 +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.
|
|
|
|
#-
|
|
|
|
|
2009-02-25 05:15:20 +00:00
|
|
|
. ${XBPS_SHUTILSDIR}/builddep_funcs.sh
|
|
|
|
|
2009-02-20 03:10:55 +00:00
|
|
|
stow_pkg()
|
|
|
|
{
|
|
|
|
local pkg="$1"
|
|
|
|
local automatic="$2"
|
|
|
|
local subpkg=
|
|
|
|
|
|
|
|
for subpkg in ${subpackages}; do
|
2009-02-20 05:25:35 +00:00
|
|
|
if [ "${pkg}" != "${sourcepkg}" ] && \
|
|
|
|
[ "${pkg}" != "${sourcepkg}-${subpkg}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
check_installed_pkg ${sourcepkg}-${subpkg}-${version}
|
|
|
|
[ $? -eq 0 ] && continue
|
|
|
|
|
|
|
|
if [ ! -f $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template ]; then
|
|
|
|
msg_error "Cannot find subpackage template!"
|
|
|
|
fi
|
2009-02-20 03:10:55 +00:00
|
|
|
. $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template
|
|
|
|
pkgname=${sourcepkg}-${subpkg}
|
2009-02-20 05:25:35 +00:00
|
|
|
stow_pkg_real ${pkgname} ${automatic}
|
2009-02-20 03:10:55 +00:00
|
|
|
run_template ${sourcepkg}
|
2009-02-20 05:25:35 +00:00
|
|
|
if [ "${pkg}" = "${sourcepkg}-${subpkg}" ]; then
|
|
|
|
#
|
|
|
|
# If it's a subpackage, just remove sourcepkg from
|
|
|
|
# destdir and return, we are done.
|
|
|
|
#
|
|
|
|
rm -rf $XBPS_DESTDIR/${sourcepkg}-${version}
|
|
|
|
return $?
|
|
|
|
fi
|
2009-02-20 03:10:55 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
stow_pkg_real ${pkg} ${automatic}
|
|
|
|
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2008-12-13 04:23:16 +00:00
|
|
|
#
|
|
|
|
# Stow a package, i.e copy files from destdir into masterdir
|
|
|
|
# and register pkg into the package database.
|
|
|
|
#
|
2009-02-20 03:10:55 +00:00
|
|
|
stow_pkg_real()
|
2008-12-13 04:23:16 +00:00
|
|
|
{
|
|
|
|
local pkg="$1"
|
2009-02-17 23:28:35 +00:00
|
|
|
local automatic="$2"
|
2008-12-13 04:23:16 +00:00
|
|
|
local i=
|
2009-02-20 05:25:35 +00:00
|
|
|
local destdir=$XBPS_DESTDIR/$pkg-$version
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
[ -z "$pkg" ] && return 2
|
|
|
|
|
2008-12-22 02:06:15 +00:00
|
|
|
if [ $(id -u) -ne 0 ] && [ ! -w $XBPS_MASTERDIR ]; then
|
2008-12-21 08:13:12 +00:00
|
|
|
msg_error "cannot stow $pkg! (permission denied)"
|
|
|
|
fi
|
|
|
|
|
2008-12-13 07:44:51 +00:00
|
|
|
if [ "$build_style" = "meta-template" ]; then
|
2008-12-17 07:27:28 +00:00
|
|
|
[ ! -d $destdir ] && mkdir -p $destdir
|
2008-12-13 07:44:51 +00:00
|
|
|
fi
|
|
|
|
|
2008-12-13 04:23:16 +00:00
|
|
|
if [ -n "$stow_flag" ]; then
|
|
|
|
if [ "$pkgname" != "$pkg" ]; then
|
2009-02-20 05:25:35 +00:00
|
|
|
. $XBPS_TEMPLATESDIR/$pkg/template
|
2008-12-13 04:23:16 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-12-17 07:27:28 +00:00
|
|
|
cd $destdir || exit 1
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
# Copy files into masterdir.
|
|
|
|
for i in $(echo *); do
|
2009-02-16 20:50:02 +00:00
|
|
|
[ "$i" = "XBPS_PREPOST_INSTALL" ] && continue
|
2008-12-13 04:23:16 +00:00
|
|
|
cp -ar ${i} $XBPS_MASTERDIR
|
|
|
|
done
|
|
|
|
|
2009-02-17 23:28:35 +00:00
|
|
|
#
|
|
|
|
# Register pkg in plist file and add automatic installation
|
|
|
|
# object if requested.
|
|
|
|
#
|
|
|
|
local regpkgdb_flags=
|
|
|
|
if [ -n "$automatic" ]; then
|
|
|
|
regpkgdb_flags="-a"
|
|
|
|
fi
|
|
|
|
$XBPS_REGPKGDB_CMD $regpkgdb_flags register \
|
2009-02-20 05:25:35 +00:00
|
|
|
$pkg $version "$short_desc" || exit 1
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Run template postinstall helpers if requested.
|
|
|
|
#
|
|
|
|
for i in ${postinstall_helpers}; do
|
|
|
|
local pihf="$XBPS_HELPERSDIR/$i"
|
|
|
|
[ -f "$pihf" ] && . $pihf
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unstow a package, i.e remove its files from masterdir and
|
|
|
|
# unregister pkg from package database.
|
|
|
|
#
|
|
|
|
unstow_pkg()
|
|
|
|
{
|
|
|
|
local pkg="$1"
|
|
|
|
local f=
|
|
|
|
local ver=
|
|
|
|
|
|
|
|
[ -z $pkg ] && msg_error "template wasn't specified?"
|
|
|
|
|
2008-12-21 08:16:55 +00:00
|
|
|
if [ $(id -u) -ne 0 ] && \
|
|
|
|
[ ! -w $XBPS_MASTERDIR ]; then
|
2008-12-21 08:13:12 +00:00
|
|
|
msg_error "cannot unstow $pkg! (permission denied)"
|
|
|
|
fi
|
|
|
|
|
2008-12-13 04:23:16 +00:00
|
|
|
if [ "$pkgname" != "$pkg" ]; then
|
2009-02-03 20:35:57 +00:00
|
|
|
. $XBPS_TEMPLATESDIR/$pkg/template
|
2008-12-13 04:23:16 +00:00
|
|
|
fi
|
|
|
|
|
2008-12-19 03:18:49 +00:00
|
|
|
ver=$($XBPS_REGPKGDB_CMD version $pkg)
|
2008-12-13 04:23:16 +00:00
|
|
|
if [ -z "$ver" ]; then
|
|
|
|
msg_error "$pkg is not installed."
|
|
|
|
fi
|
|
|
|
|
2009-02-20 05:25:35 +00:00
|
|
|
cd $XBPS_PKGMETADIR/$pkg || exit 1
|
2008-12-21 23:51:34 +00:00
|
|
|
if [ "$build_style" = "meta-template" ]; then
|
|
|
|
# If it's a metapkg, do nothing.
|
|
|
|
:
|
|
|
|
elif [ ! -f flist ]; then
|
2008-12-13 04:23:16 +00:00
|
|
|
msg_error "$pkg is incomplete, missing flist."
|
2008-12-18 07:17:46 +00:00
|
|
|
elif [ ! -w flist ]; then
|
2008-12-13 04:23:16 +00:00
|
|
|
msg_error "$pkg cannot be removed (permission denied)."
|
2008-12-18 08:50:19 +00:00
|
|
|
elif [ -s flist ]; then
|
|
|
|
# Remove installed files.
|
|
|
|
for f in $(cat flist); do
|
|
|
|
if [ -f $XBPS_MASTERDIR/$f -o -h $XBPS_MASTERDIR/$f ]; then
|
|
|
|
rm $XBPS_MASTERDIR/$f >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removing file: $f"
|
|
|
|
fi
|
2008-12-13 04:23:16 +00:00
|
|
|
fi
|
2008-12-18 08:50:19 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for f in $(cat flist); do
|
|
|
|
if [ -d $XBPS_MASTERDIR/$f ]; then
|
|
|
|
rmdir $XBPS_MASTERDIR/$f >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removing directory: $f"
|
|
|
|
fi
|
2008-12-13 04:23:16 +00:00
|
|
|
fi
|
2008-12-18 08:50:19 +00:00
|
|
|
done
|
|
|
|
fi
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
# Remove metadata dir.
|
2009-02-20 05:25:35 +00:00
|
|
|
rm -rf $XBPS_PKGMETADIR/$pkg
|
2009-02-17 23:28:35 +00:00
|
|
|
|
|
|
|
# Unregister pkg from plist file.
|
2009-02-20 05:25:35 +00:00
|
|
|
$XBPS_REGPKGDB_CMD unregister $pkg $ver
|
2008-12-21 23:51:34 +00:00
|
|
|
|
2008-12-13 04:23:16 +00:00
|
|
|
return $?
|
|
|
|
}
|