2008-12-18 06:32:42 +00:00
|
|
|
#-
|
|
|
|
# Copyright (c) 2008 Juan Romero Pardines.
|
|
|
|
# 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.
|
|
|
|
#-
|
|
|
|
|
2008-12-19 05:22:03 +00:00
|
|
|
XBPS_PKGINDEX_VERSION="1.0" # Current version for pkgindex plist
|
|
|
|
|
2008-12-18 06:32:42 +00:00
|
|
|
#
|
|
|
|
# These functions write a package index for a repository, with details about
|
|
|
|
# all available binary packages.
|
|
|
|
#
|
|
|
|
write_repo_pkgindex()
|
|
|
|
{
|
2008-12-19 23:10:06 +00:00
|
|
|
local repodir="$1"
|
2008-12-18 06:32:42 +00:00
|
|
|
local propsf=
|
|
|
|
local pkgname=
|
2009-02-17 13:09:15 +00:00
|
|
|
local pkgnbase=
|
2008-12-18 06:32:42 +00:00
|
|
|
local pkgsum=
|
|
|
|
local pkgindexf=
|
|
|
|
local tmppkgdir=
|
|
|
|
local i=
|
2008-12-18 10:40:56 +00:00
|
|
|
local found=
|
2008-12-18 06:32:42 +00:00
|
|
|
|
2008-12-19 23:10:06 +00:00
|
|
|
[ -z "$repodir" ] && repodir=$XBPS_PACKAGESDIR
|
|
|
|
[ ! -d $repodir ] && exit 1
|
2008-12-18 06:32:42 +00:00
|
|
|
|
2009-02-15 23:39:41 +00:00
|
|
|
found="$(echo $repodir/$xbps_machine/*)"
|
2008-12-18 10:40:56 +00:00
|
|
|
if $(echo $found|grep -vq .xbps); then
|
2008-12-19 23:10:06 +00:00
|
|
|
msg_error "couldn't find binary packages on $repodir."
|
2008-12-18 10:40:56 +00:00
|
|
|
fi
|
|
|
|
|
2009-02-15 23:39:41 +00:00
|
|
|
pkgindexf=$(mktemp -t xbps-pkgidx.XXXXXXXXXX) || exit 1
|
|
|
|
tmppkgdir=$(mktemp -d -t xbps-pkgdir.XXXXXXXX) || exit 1
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
# Write the header.
|
2008-12-19 23:10:06 +00:00
|
|
|
msg_normal "Creating package index for $repodir..."
|
|
|
|
write_repo_pkgindex_header $pkgindexf $repodir
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
#
|
2009-02-15 23:39:41 +00:00
|
|
|
# Write pkg dictionaries for all packages currently available at
|
|
|
|
# XBPS_PACKAGESDIR, both for your cpu arch and non arch dependent.
|
2008-12-18 06:32:42 +00:00
|
|
|
#
|
2009-02-15 23:39:41 +00:00
|
|
|
for i in $(find $repodir/$xbps_machine -type f -name \*.xbps); do
|
2009-02-17 13:09:15 +00:00
|
|
|
pkgnbase="$(basename ${i})"
|
|
|
|
pkgname=$(xbps-pkgdb getpkgname ${pkgnbase})
|
2009-02-14 22:21:12 +00:00
|
|
|
propsf="./var/db/xbps/metadata/$pkgname/props.plist"
|
2008-12-18 06:32:42 +00:00
|
|
|
cd $tmppkgdir && tar xfjp $i $propsf
|
|
|
|
if [ $? -ne 0 ]; then
|
2008-12-22 02:37:21 +00:00
|
|
|
msg_warn "Couldn't extract $(basename $i) metadata!"
|
2008-12-18 06:32:42 +00:00
|
|
|
continue
|
|
|
|
fi
|
2009-02-15 23:39:41 +00:00
|
|
|
write_repo_pkgindex_dict $propsf $pkgindexf $(basename $i) \
|
|
|
|
$xbps_machine
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_warn "Couldn't write $i metadata to index file!"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "$(basename $i) added."
|
|
|
|
pkgsum=$(($pkgsum + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $(find $repodir/noarch -type f -name \*.xbps); do
|
2009-02-17 13:09:15 +00:00
|
|
|
pkgnbase="$(basename ${i})"
|
|
|
|
pkgname=$(xbps-pkgdb getpkgname ${pkgnbase})
|
2009-02-15 23:39:41 +00:00
|
|
|
propsf="./var/db/xbps/metadata/$pkgname/props.plist"
|
|
|
|
cd $tmppkgdir && tar xfjp $i $propsf
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_warn "Couldn't extract $(basename $i) metadata!"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
write_repo_pkgindex_dict $propsf $pkgindexf $(basename $i) \
|
|
|
|
noarch
|
2008-12-18 06:32:42 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_warn "Couldn't write $i metadata to index file!"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "$(basename $i) added."
|
|
|
|
pkgsum=$(($pkgsum + 1))
|
|
|
|
done
|
|
|
|
|
2008-12-19 05:22:03 +00:00
|
|
|
write_repo_pkgindex_footer $pkgindexf $pkgsum
|
2008-12-18 06:32:42 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2008-12-19 03:18:49 +00:00
|
|
|
$XBPS_REGPKGDB_CMD sanitize-plist $pkgindexf
|
2008-12-19 07:32:55 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
rm -f $pkgindexf
|
|
|
|
rm -rf $tmppkgdir
|
|
|
|
exit 1
|
|
|
|
fi
|
2008-12-18 06:32:42 +00:00
|
|
|
msg_normal "Package index created (total pkgs: $pkgsum)."
|
2009-02-15 23:39:41 +00:00
|
|
|
cp -f $pkgindexf $repodir/$xbps_machine/pkg-index.plist
|
2008-12-18 06:32:42 +00:00
|
|
|
fi
|
|
|
|
rm -f $pkgindexf
|
|
|
|
rm -rf $tmppkgdir
|
|
|
|
}
|
|
|
|
|
2008-12-19 04:10:30 +00:00
|
|
|
#
|
|
|
|
# No indentation is done here, because xbps-pkgdb does it for us.
|
|
|
|
#
|
2008-12-18 06:32:42 +00:00
|
|
|
write_repo_pkgindex_header()
|
|
|
|
{
|
|
|
|
local file="$1"
|
2008-12-19 23:10:06 +00:00
|
|
|
local repo="$2"
|
2008-12-18 06:32:42 +00:00
|
|
|
|
2008-12-19 23:10:06 +00:00
|
|
|
[ -z "$file" -o -z "$repo" ] && return 1
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
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>
|
2008-12-19 05:22:03 +00:00
|
|
|
<key>pkgindex-version</key>
|
|
|
|
<string>$XBPS_PKGINDEX_VERSION</string>
|
|
|
|
<key>location-local</key>
|
2008-12-19 23:10:06 +00:00
|
|
|
<string>$repodir</string>
|
2008-12-20 02:45:35 +00:00
|
|
|
<key>packages</key>
|
2008-12-19 03:18:49 +00:00
|
|
|
<array>
|
2008-12-18 06:32:42 +00:00
|
|
|
_EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
write_repo_pkgindex_footer()
|
|
|
|
{
|
|
|
|
local file="$1"
|
2008-12-19 05:22:03 +00:00
|
|
|
local totalpkgs="$2"
|
2008-12-18 06:32:42 +00:00
|
|
|
|
2008-12-19 05:22:03 +00:00
|
|
|
[ -z "$file" -o -z "$totalpkgs" ] && return 1
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
cat >> $file <<_EOF
|
2008-12-19 03:18:49 +00:00
|
|
|
</array>
|
2008-12-19 05:22:03 +00:00
|
|
|
<key>total-pkgs</key>
|
|
|
|
<integer>$totalpkgs</integer>
|
2008-12-18 06:32:42 +00:00
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
_EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Function that writes the package's metadata dictionary into the
|
2008-12-19 04:10:30 +00:00
|
|
|
# package index file for a repository.
|
2008-12-18 06:32:42 +00:00
|
|
|
#
|
|
|
|
write_repo_pkgindex_dict()
|
|
|
|
{
|
|
|
|
local pkgf="$1"
|
|
|
|
local indexf="$2"
|
|
|
|
local binpkgf="$3"
|
2009-02-15 23:39:41 +00:00
|
|
|
local arch="$4"
|
2008-12-18 06:32:42 +00:00
|
|
|
local first_dict=
|
|
|
|
local tmpdictf=
|
2009-02-15 23:39:41 +00:00
|
|
|
local binpkg="$XBPS_PACKAGESDIR/$arch/$binpkgf"
|
|
|
|
local getsize=$(du -b $binpkg|awk '{print $1}')
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
[ -z "$pkgf" -o -z "$indexf" -o -z "$binpkgf" ] && return 1
|
|
|
|
|
2009-02-15 23:39:41 +00:00
|
|
|
tmpdictf=$(mktemp -t xbps-pkgdict.XXXXXXXXXX) || exit 1
|
2008-12-18 06:32:42 +00:00
|
|
|
|
|
|
|
cat $pkgf | while read line; do
|
|
|
|
# Find the first dictionary.
|
|
|
|
if $(echo $line|grep -q "<dict>"); then
|
|
|
|
first_dict=yes
|
2008-12-19 03:18:49 +00:00
|
|
|
echo "$line" >> $tmpdictf
|
2008-12-19 20:44:00 +00:00
|
|
|
# Write binpkg props.
|
2008-12-19 03:18:49 +00:00
|
|
|
echo "<key>filename</key>" >> $tmpdictf
|
|
|
|
echo "<string>$binpkgf</string>" >> $tmpdictf
|
2008-12-19 20:44:00 +00:00
|
|
|
echo "<key>filename-sha256</key>" >> $tmpdictf
|
2008-12-22 02:37:21 +00:00
|
|
|
echo "<string>$(xbps-digest $binpkg)</string>" \
|
2008-12-19 20:44:00 +00:00
|
|
|
>> $tmpdictf
|
2009-02-14 04:34:24 +00:00
|
|
|
echo "<key>filename-size</key>" >> $tmpdictf
|
|
|
|
echo "<integer>$getsize</integer>" >> $tmpdictf
|
2008-12-18 06:32:42 +00:00
|
|
|
continue
|
|
|
|
# Continue until found.
|
|
|
|
elif [ -z "$first_dict" ]; then
|
|
|
|
continue
|
|
|
|
# Is this line the end of dictionary?
|
|
|
|
elif $(echo $line|grep -q "</dict>"); then
|
|
|
|
# It is.
|
2008-12-19 03:18:49 +00:00
|
|
|
echo "$line" >> $tmpdictf
|
2008-12-18 06:32:42 +00:00
|
|
|
break
|
|
|
|
else
|
2008-12-19 03:18:49 +00:00
|
|
|
echo "$line" >> $tmpdictf
|
2008-12-18 06:32:42 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
cat $tmpdictf >> $indexf
|
|
|
|
rm -f $tmpdictf
|
|
|
|
}
|