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.
|
|
|
|
#-
|
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
stow_pkg_handler()
|
2009-10-18 09:17:26 +00:00
|
|
|
{
|
2009-11-22 07:31:44 +00:00
|
|
|
local action="$1" subpkg spkgrev
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
for subpkg in ${subpackages}; do
|
|
|
|
if [ -n "$revision" ]; then
|
2009-11-22 07:31:44 +00:00
|
|
|
spkgrev="${subpkg}-${version}_${revision}"
|
2009-10-18 09:17:26 +00:00
|
|
|
else
|
2009-11-22 07:31:44 +00:00
|
|
|
spkgrev="${subpkg}-${version}"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
2009-11-22 07:31:44 +00:00
|
|
|
if [ "$action" = "stow" ]; then
|
|
|
|
check_installed_pkg ${spkgrev}
|
|
|
|
[ $? -eq 0 ] && continue
|
|
|
|
fi
|
|
|
|
if [ ! -f $XBPS_SRCPKGDIR/${sourcepkg}/${subpkg}.template ]; then
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_error "Cannot find $subpkg subpkg build template!\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
2010-04-23 13:25:03 +00:00
|
|
|
unset revision pre_install pre_remove post_install \
|
|
|
|
post_remove post_stow
|
2009-11-22 07:31:44 +00:00
|
|
|
. $XBPS_SRCPKGDIR/${sourcepkg}/${subpkg}.template
|
|
|
|
pkgname=${subpkg}
|
2009-10-18 09:17:26 +00:00
|
|
|
set_tmpl_common_vars
|
2009-11-22 07:31:44 +00:00
|
|
|
if [ "$action" = "stow" ]; then
|
|
|
|
stow_pkg_real || return $?
|
|
|
|
else
|
|
|
|
unstow_pkg_real || return $?
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
2009-11-23 05:30:04 +00:00
|
|
|
setup_tmpl ${sourcepkg}
|
2009-10-18 09:17:26 +00:00
|
|
|
done
|
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
if [ "$action" = "stow" ]; then
|
|
|
|
stow_pkg_real
|
|
|
|
else
|
|
|
|
unstow_pkg_real
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Stow a package, i.e copy files from destdir into masterdir
|
|
|
|
# and register pkg into the package database.
|
|
|
|
#
|
|
|
|
stow_pkg_real()
|
|
|
|
{
|
2010-04-23 13:25:03 +00:00
|
|
|
local i lfile lver regpkgdb_flags
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
[ -z "$pkgname" ] && return 2
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
if [ $(id -u) -ne 0 ] && [ ! -w $XBPS_MASTERDIR ]; then
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_error "cannot stow $pkgname! (permission denied)\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$build_style" = "meta-template" ]; then
|
|
|
|
[ ! -d ${DESTDIR} ] && mkdir -p ${DESTDIR}
|
|
|
|
fi
|
|
|
|
|
2009-11-23 05:30:04 +00:00
|
|
|
[ -n "$stow_flag" ] && setup_tmpl $pkgname
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2010-04-23 13:25:03 +00:00
|
|
|
cd ${DESTDIR} || return 1
|
|
|
|
|
2010-05-13 22:07:47 +00:00
|
|
|
if [ -n "$revision" ]; then
|
|
|
|
lver="${version}_${revision}"
|
|
|
|
else
|
|
|
|
lver="${version}"
|
|
|
|
fi
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_normal "'${pkgname}-$lver': stowning files into masterdir, please wait...\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
# Copy files into masterdir.
|
2010-04-23 13:25:03 +00:00
|
|
|
for i in $(find -print); do
|
|
|
|
lfile="$(echo $i|sed -e 's|^\./||')"
|
|
|
|
# Skip pkg metadata
|
|
|
|
if [ "$lfile" = "INSTALL" -o "$lfile" = "REMOVE" -o \
|
|
|
|
"$lfile" = "files.plist" -o "$lfile" = "props.plist" ]; then
|
2009-10-18 09:17:26 +00:00
|
|
|
continue
|
2010-04-23 13:25:03 +00:00
|
|
|
# Skip files that are already in masterdir.
|
|
|
|
elif [ -f "$XBPS_MASTERDIR/$lfile" ]; then
|
2010-05-13 22:07:47 +00:00
|
|
|
echo " Skipping $lfile file, already exists!"
|
2010-04-23 13:25:03 +00:00
|
|
|
continue
|
|
|
|
elif [ -h "$XBPS_MASTERDIR/$lfile" ]; then
|
2010-05-13 22:07:47 +00:00
|
|
|
echo " Skipping $lfile link, already exists!"
|
2010-04-23 13:25:03 +00:00
|
|
|
continue
|
|
|
|
elif [ -d "$XBPS_MASTERDIR/$lfile" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2010-05-13 13:28:17 +00:00
|
|
|
if [ -f "$i" -o -h "$i" ]; then
|
2010-04-23 13:25:03 +00:00
|
|
|
# Always copy the pkg metadata flist file.
|
|
|
|
if [ "$(basename $i)" = "flist" ]; then
|
|
|
|
cp -dp $i $XBPS_MASTERDIR/$lfile
|
|
|
|
continue
|
|
|
|
fi
|
2011-07-04 17:07:08 +00:00
|
|
|
if [ -n "$IN_CHROOT" -a -n "$stow_copy_files" ]; then
|
2010-04-23 13:25:03 +00:00
|
|
|
# Templates that set stow_copy_files require
|
|
|
|
# some files to be copied, rather than symlinked.
|
|
|
|
local found
|
|
|
|
for j in ${stow_copy_files}; do
|
|
|
|
if [ "/$lfile" = "${j}" ]; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$found" ]; then
|
|
|
|
cp -dp $i $XBPS_MASTERDIR/$lfile
|
|
|
|
unset found
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
2011-07-04 17:07:08 +00:00
|
|
|
if [ -n "$IN_CHROOT" -a -n "$stow_copy" -o -z "$IN_CHROOT" ]; then
|
2010-04-23 13:25:03 +00:00
|
|
|
# In the no-chroot case and templates that
|
|
|
|
# set $stow_copy, we can't stow with symlinks.
|
|
|
|
# Just copy them.
|
|
|
|
cp -dp $i $XBPS_MASTERDIR/$lfile
|
|
|
|
else
|
|
|
|
# Always use symlinks in the chroot with pkgs
|
|
|
|
# that don't have $stow_copy set, they can have
|
|
|
|
# full path.
|
|
|
|
ln -sf $DESTDIR/$lfile $XBPS_MASTERDIR/$lfile
|
|
|
|
fi
|
2010-05-13 13:28:17 +00:00
|
|
|
elif [ -d "$i" ]; then
|
|
|
|
mkdir -p $XBPS_MASTERDIR/$lfile
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
#
|
|
|
|
# Register pkg in plist file.
|
|
|
|
#
|
2010-04-23 13:25:03 +00:00
|
|
|
$XBPS_PKGDB_CMD register $pkgname $lver "$short_desc" || return $?
|
2010-12-18 21:38:21 +00:00
|
|
|
run_func post_stow
|
|
|
|
return 0
|
2009-10-18 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unstow a package, i.e remove its files from masterdir and
|
|
|
|
# unregister pkg from package database.
|
|
|
|
#
|
2009-11-22 07:31:44 +00:00
|
|
|
unstow_pkg_real()
|
2009-10-18 09:17:26 +00:00
|
|
|
{
|
2011-06-16 10:21:12 +00:00
|
|
|
local f ver
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
[ -z $pkgname ] && return 1
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
if [ $(id -u) -ne 0 ] && \
|
|
|
|
[ ! -w $XBPS_MASTERDIR ]; then
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_error "cannot unstow $pkgname! (permission denied)\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
|
2009-11-23 05:30:04 +00:00
|
|
|
setup_tmpl $pkgname
|
2011-07-06 09:27:57 +00:00
|
|
|
pkg="${pkgname}-${version}"
|
|
|
|
[ -n "$revision" ] && pkg="${pkg}_${revision}"
|
2009-10-18 09:17:26 +00:00
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
ver=$($XBPS_PKGDB_CMD version $pkgname)
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ -z "$ver" ]; then
|
2011-07-06 09:27:57 +00:00
|
|
|
msg_warn "'${pkg}' not installed in masterdir!\n"
|
2011-06-21 13:19:34 +00:00
|
|
|
return 0
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
cd $XBPS_PKGMETADIR/$pkgname || exit 1
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ "$build_style" = "meta-template" ]; then
|
|
|
|
# If it's a metapkg, do nothing.
|
|
|
|
:
|
2010-04-23 13:25:03 +00:00
|
|
|
elif [ ! -f ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
|
2011-07-06 09:27:57 +00:00
|
|
|
msg_warn "'${pkg}' wasn't installed from source!\n"
|
|
|
|
return 1
|
2010-04-23 13:25:03 +00:00
|
|
|
elif [ ! -w ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_error "$pkgname cannot be removed (permission denied).\n"
|
2010-04-23 13:25:03 +00:00
|
|
|
elif [ -s ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
|
2010-12-18 21:38:21 +00:00
|
|
|
run_func pre_remove
|
2009-10-18 09:17:26 +00:00
|
|
|
# Remove installed files.
|
2010-04-23 13:25:03 +00:00
|
|
|
for f in $(cat ${XBPS_PKGMETADIR}/${pkgname}/flist); do
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ -f $XBPS_MASTERDIR/$f -o -h $XBPS_MASTERDIR/$f ]; then
|
2010-04-22 07:02:49 +00:00
|
|
|
rm -f $XBPS_MASTERDIR/$f >/dev/null 2>&1
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removing file: $f"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2010-04-23 13:25:03 +00:00
|
|
|
for f in $(cat ${XBPS_PKGMETADIR}/${pkgname}/flist); do
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ -d $XBPS_MASTERDIR/$f ]; then
|
|
|
|
rmdir $XBPS_MASTERDIR/$f >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removing directory: $f"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2010-12-18 21:38:21 +00:00
|
|
|
run_func post_remove
|
2009-10-18 09:17:26 +00:00
|
|
|
# Remove metadata dir.
|
2011-07-01 15:48:29 +00:00
|
|
|
[ -d $XBPS_PKGMETADIR/$pkgname ] && rm -rf $XBPS_PKGMETADIR/$pkgname
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
# Unregister pkg from plist file.
|
2011-06-16 10:21:12 +00:00
|
|
|
$XBPS_PKGDB_CMD unregister $pkgname $ver
|
2009-10-18 09:17:26 +00:00
|
|
|
return $?
|
|
|
|
}
|