2008-12-13 05:23:16 +01:00
|
|
|
#-
|
2009-02-19 14:11:30 +01:00
|
|
|
# Copyright (c) 2008-2009 Juan Romero Pardines.
|
2008-12-13 05:23:16 +01: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-19 14:11:30 +01:00
|
|
|
write_metadata_flist_header()
|
|
|
|
{
|
|
|
|
local file="$1"
|
|
|
|
|
|
|
|
[ -z "$file" ] && return 1
|
|
|
|
|
|
|
|
cat > $file <<_EOF
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>filelist</key>
|
|
|
|
<array>
|
|
|
|
_EOF
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-02-20 04:10:55 +01:00
|
|
|
xbps_write_metadata_pkg()
|
|
|
|
{
|
2009-02-20 06:25:35 +01:00
|
|
|
local pkg="$1"
|
2009-02-20 04:10:55 +01:00
|
|
|
local subpkg=
|
|
|
|
|
|
|
|
for subpkg in ${subpackages}; do
|
2009-02-20 06:25:35 +01: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-24 07:13:11 +01:00
|
|
|
unset run_depends
|
2009-02-20 04:10:55 +01:00
|
|
|
. $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template
|
|
|
|
pkgname=${sourcepkg}-${subpkg}
|
|
|
|
xbps_write_metadata_pkg_real
|
|
|
|
run_template ${sourcepkg}
|
2009-02-20 06:25:35 +01:00
|
|
|
[ "${pkg}" = "${sourcepkg}-${subpkg}" ] && break
|
2009-02-20 04:10:55 +01:00
|
|
|
done
|
|
|
|
|
2009-02-20 06:25:35 +01:00
|
|
|
[ -n "${subpackages}" ] && [ "$pkg" != "${sourcepkg}" ] && return $?
|
|
|
|
|
2009-02-24 07:13:11 +01:00
|
|
|
if [ -z "${run_depends}" ]; then
|
|
|
|
for subpkg in ${subpackages}; do
|
|
|
|
run_depends="$run_depends ${sourcepkg}-${subpkg}-${version}"
|
|
|
|
done
|
2009-02-20 04:10:55 +01:00
|
|
|
fi
|
|
|
|
xbps_write_metadata_pkg_real
|
|
|
|
}
|
|
|
|
|
2008-12-11 03:22:54 +01:00
|
|
|
#
|
2008-12-13 03:01:24 +01:00
|
|
|
# This function writes the metadata files into package's destdir,
|
|
|
|
# these will be used for binary packages.
|
2008-12-11 03:22:54 +01:00
|
|
|
#
|
2009-02-20 04:10:55 +01:00
|
|
|
xbps_write_metadata_pkg_real()
|
2008-12-11 03:22:54 +01:00
|
|
|
{
|
|
|
|
local destdir=$XBPS_DESTDIR/$pkgname-$version
|
2009-02-14 23:21:12 +01:00
|
|
|
local metadir=$destdir/var/db/xbps/metadata/$pkgname
|
2009-02-19 14:11:30 +01:00
|
|
|
local f i j arch prioinst TMPFLIST TMPFPLIST
|
|
|
|
local fpattern="s|$destdir||g;s|^\./$||g;/^$/d"
|
2008-12-11 03:22:54 +01:00
|
|
|
|
|
|
|
if [ ! -d "$destdir" ]; then
|
|
|
|
echo "ERROR: $pkgname not installed into destdir."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2008-12-29 15:54:33 +01:00
|
|
|
if [ -n "$install_priority" ]; then
|
2008-12-27 16:20:54 +01:00
|
|
|
prioinst=$install_priority
|
|
|
|
else
|
|
|
|
prioinst=0
|
|
|
|
fi
|
|
|
|
|
2009-02-16 00:39:41 +01:00
|
|
|
if [ -n "$noarch" ]; then
|
|
|
|
arch=noarch
|
|
|
|
else
|
|
|
|
arch=$xbps_machine
|
|
|
|
fi
|
|
|
|
|
2009-02-19 14:11:30 +01:00
|
|
|
# Write the files.plist file.
|
|
|
|
TMPFLIST=$(mktemp -t flist.XXXXXXXXXX) || exit 1
|
|
|
|
TMPFPLIST=$(mktemp -t fplist.XXXXXXXXXX) || exit 1
|
|
|
|
|
|
|
|
msg_normal "Writing package metadata for $pkgname-$version..."
|
|
|
|
|
|
|
|
write_metadata_flist_header $TMPFPLIST
|
|
|
|
|
2009-02-02 20:40:06 +01:00
|
|
|
# First add the regular files.
|
2009-02-19 14:11:30 +01:00
|
|
|
for f in $(find -L $destdir -type f); do
|
|
|
|
j=$(echo $f|sed -e "$fpattern")
|
|
|
|
[ "$j" = "" ] && continue
|
|
|
|
printf "$j\n" >> $TMPFLIST
|
|
|
|
printf "<dict>\n" >> $TMPFPLIST
|
|
|
|
printf "<key>file</key>\n" >> $TMPFPLIST
|
|
|
|
printf "<string>$j</string>\n" >> $TMPFPLIST
|
|
|
|
printf "<key>sha256</key>\n" >> $TMPFPLIST
|
|
|
|
printf "<string>$(xbps-digest $f)</string>\n" >> $TMPFPLIST
|
|
|
|
for i in ${conf_files}; do
|
|
|
|
if [ "$j" = "$i" ]; then
|
|
|
|
printf "<key>conf_file</key>\n" >> $TMPFPLIST
|
|
|
|
printf "<true/>\n" >> $TMPFPLIST
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
printf "</dict>\n" >> $TMPFPLIST
|
|
|
|
done
|
|
|
|
|
|
|
|
# Add directories at the end.
|
|
|
|
for f in $(find -L $destdir -type d|sort -ur); do
|
|
|
|
j=$(echo $f|sed -e "$fpattern")
|
|
|
|
[ "$j" = "" ] && continue
|
|
|
|
printf "$j\n" >> $TMPFLIST
|
|
|
|
printf "<dict>\n" >> $TMPFPLIST
|
|
|
|
printf "<key>dir</key>\n" >> $TMPFPLIST
|
|
|
|
printf "<string>$j</string>\n" >> $TMPFPLIST
|
|
|
|
for i in ${keep_dirs}; do
|
|
|
|
if [ "$j" = "$i" ]; then
|
|
|
|
printf "<key>keep</key>\n" >> $TMPFPLIST
|
|
|
|
printf "<true/>\n" >> $TMPFPLIST
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
printf "</dict>\n" >> $TMPFPLIST
|
|
|
|
done
|
|
|
|
printf "</array>\n</dict>\n</plist>\n" >> $TMPFPLIST
|
|
|
|
sed -i -e /^$/d $TMPFLIST
|
2008-12-11 03:22:54 +01:00
|
|
|
|
2009-02-19 14:11:30 +01:00
|
|
|
# Write the props.plist file.
|
2008-12-11 03:22:54 +01:00
|
|
|
local TMPFPROPS=$(mktemp -t fprops.XXXXXXXXXX) || exit 1
|
|
|
|
|
|
|
|
cat > $TMPFPROPS <<_EOF
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
2009-02-19 14:11:30 +01:00
|
|
|
<key>pkgname</key>
|
|
|
|
<string>$pkgname</string>
|
|
|
|
<key>version</key>
|
|
|
|
<string>$version</string>
|
|
|
|
<key>architecture</key>
|
|
|
|
<string>$arch</string>
|
|
|
|
<key>priority</key>
|
|
|
|
<integer>$prioinst</integer>
|
|
|
|
<key>installed_size</key>
|
|
|
|
<integer>$(du -sb $destdir|awk '{print $1}')</integer>
|
|
|
|
<key>maintainer</key>
|
|
|
|
<string>$(echo $maintainer|sed -e 's|<|[|g;s|>|]|g')</string>
|
|
|
|
<key>short_desc</key>
|
|
|
|
<string>$short_desc</string>
|
|
|
|
<key>long_desc</key>
|
|
|
|
<string>$long_desc</string>
|
2008-12-11 03:22:54 +01:00
|
|
|
_EOF
|
|
|
|
# Dependencies
|
|
|
|
if [ -n "$run_depends" ]; then
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<key>run_depends</key>\n" >> $TMPFPROPS
|
|
|
|
printf "<array>\n" >> $TMPFPROPS
|
2008-12-11 03:22:54 +01:00
|
|
|
for f in ${run_depends}; do
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<string>$f</string>\n" >> $TMPFPROPS
|
2008-12-11 03:22:54 +01:00
|
|
|
done
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "</array>\n" >> $TMPFPROPS
|
2008-12-11 03:22:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Configuration files
|
2008-12-14 01:54:18 +01:00
|
|
|
if [ -n "$conf_files" ]; then
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<key>conf_files</key>\n" >> $TMPFPROPS
|
|
|
|
printf "<array>\n" >> $TMPFPROPS
|
2008-12-14 01:54:18 +01:00
|
|
|
for f in ${conf_files}; do
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<string>$f</string>\n" >> $TMPFPROPS
|
2008-12-11 03:22:54 +01:00
|
|
|
done
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "</array>\n" >> $TMPFPROPS
|
2008-12-11 03:22:54 +01:00
|
|
|
fi
|
2008-12-14 01:48:36 +01:00
|
|
|
# Keep directories while removing.
|
|
|
|
if [ -n "$keep_dirs" ]; then
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<key>keep_dirs</key>\n" >> $TMPFPROPS
|
|
|
|
printf "<array>\n" >> $TMPFPROPS
|
2008-12-14 01:48:36 +01:00
|
|
|
for f in ${keep_dirs}; do
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "<string>$f</string>\n" >> $TMPFPROPS
|
2008-12-14 01:48:36 +01:00
|
|
|
done
|
2009-02-19 14:11:30 +01:00
|
|
|
printf "</array>\n" >> $TMPFPROPS
|
2008-12-14 01:48:36 +01:00
|
|
|
fi
|
2008-12-11 03:22:54 +01:00
|
|
|
|
|
|
|
# Terminate the property list file.
|
|
|
|
printf "</dict>\n</plist>\n" >> $TMPFPROPS
|
|
|
|
|
2008-12-17 08:27:28 +01:00
|
|
|
if [ ! -d $metadir ]; then
|
|
|
|
mkdir -p $metadir >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: you don't have enough perms for this."
|
|
|
|
rm -f $TMPFLIST $TMPFPROPS
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Write metadata files and cleanup.
|
|
|
|
cp -f $TMPFLIST $metadir/flist
|
2009-02-19 14:11:30 +01:00
|
|
|
cp -f $TMPFPLIST $metadir/files.plist
|
2008-12-17 08:27:28 +01:00
|
|
|
cp -f $TMPFPROPS $metadir/props.plist
|
2009-02-19 14:11:30 +01:00
|
|
|
$XBPS_REGPKGDB_CMD sanitize-plist $metadir/files.plist
|
|
|
|
$XBPS_REGPKGDB_CMD sanitize-plist $metadir/props.plist
|
2008-12-17 08:27:28 +01:00
|
|
|
chmod 644 $metadir/*
|
2009-02-19 14:11:30 +01:00
|
|
|
rm -f $TMPFLIST $TMPFPLIST $TMPFPROPS
|
2008-12-29 09:26:49 +01:00
|
|
|
|
2009-02-03 21:35:57 +01:00
|
|
|
if [ -f "$XBPS_TEMPLATESDIR/$pkgname/prepost-inst" ]; then
|
|
|
|
cp -f $XBPS_TEMPLATESDIR/$pkgname/prepost-inst \
|
2009-02-03 17:32:51 +01:00
|
|
|
$destdir/XBPS_PREPOST_INSTALL
|
|
|
|
chmod +x $destdir/XBPS_PREPOST_INSTALL
|
|
|
|
fi
|
2009-02-03 21:35:57 +01:00
|
|
|
if [ -f "$XBPS_TEMPLATESDIR/$pkgname/prepost-rm" ]; then
|
|
|
|
cp -f $XBPS_TEMPLATESDIR/$pkgname/prepost-rm \
|
2009-02-03 17:32:51 +01:00
|
|
|
$metadir/prepost-rm
|
|
|
|
chmod +x $metadir/prepost-rm
|
2008-12-29 09:26:49 +01:00
|
|
|
fi
|
2008-12-11 03:22:54 +01:00
|
|
|
}
|
|
|
|
|
2009-02-20 04:10:55 +01:00
|
|
|
xbps_make_binpkg()
|
|
|
|
{
|
|
|
|
local pkg="$1"
|
|
|
|
local subpkg=
|
|
|
|
|
|
|
|
for subpkg in ${subpackages}; do
|
|
|
|
if [ "$pkg" = "$pkgname-$subpkg" ]; then
|
|
|
|
. $XBPS_TEMPLATESDIR/$pkgname/$subpkg.template
|
|
|
|
pkgname=${sourcepkg}-${subpkg}
|
|
|
|
xbps_make_binpkg_real
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
run_template ${sourcepkg}
|
|
|
|
done
|
|
|
|
|
|
|
|
xbps_make_binpkg_real
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2008-12-13 03:01:24 +01:00
|
|
|
#
|
2008-12-13 05:23:16 +01:00
|
|
|
# This function builds a binary package from an installed xbps
|
2008-12-13 03:01:24 +01:00
|
|
|
# package in destdir.
|
|
|
|
#
|
2009-02-20 04:10:55 +01:00
|
|
|
xbps_make_binpkg_real()
|
2008-12-11 03:22:54 +01:00
|
|
|
{
|
|
|
|
local destdir=$XBPS_DESTDIR/$pkgname-$version
|
2009-02-16 00:39:41 +01:00
|
|
|
local binpkg=
|
|
|
|
local pkgdir=
|
|
|
|
local arch=
|
2009-02-19 14:11:30 +01:00
|
|
|
local use_sudo=
|
|
|
|
|
2008-12-11 03:22:54 +01:00
|
|
|
cd $destdir || exit 1
|
|
|
|
|
2009-02-16 00:39:41 +01:00
|
|
|
if [ -n "$noarch" ]; then
|
|
|
|
arch=noarch
|
|
|
|
else
|
|
|
|
arch=$xbps_machine
|
|
|
|
fi
|
|
|
|
|
2009-02-19 14:11:30 +01:00
|
|
|
if [ -n "$base_chroot" ]; then
|
|
|
|
use_sudo=no
|
|
|
|
else
|
|
|
|
use_sudo=yes
|
|
|
|
fi
|
|
|
|
|
2009-02-16 00:39:41 +01:00
|
|
|
binpkg=$pkgname-$version.$arch.xbps
|
|
|
|
pkgdir=$XBPS_PACKAGESDIR/$arch
|
|
|
|
|
2009-02-19 14:11:30 +01:00
|
|
|
run_rootcmd $use_sudo tar cfjp $XBPS_DESTDIR/$binpkg .
|
|
|
|
# Disabled for now.
|
|
|
|
# --exclude "./var/db/xbps/metadata/*/flist" .
|
|
|
|
#
|
2008-12-22 06:43:41 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
2009-02-16 00:39:41 +01:00
|
|
|
[ ! -d $pkgdir ] && mkdir -p $pkgdir
|
|
|
|
mv -f $XBPS_DESTDIR/$binpkg $pkgdir
|
2008-12-22 06:43:41 +01:00
|
|
|
echo "=> Built package: $binpkg"
|
|
|
|
fi
|
2008-12-11 03:22:54 +01:00
|
|
|
|
2008-12-22 06:43:41 +01:00
|
|
|
return $?
|
2008-12-11 03:22:54 +01:00
|
|
|
}
|