2009-01-06 15:43:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
program=${0##*/}
|
|
|
|
|
|
|
|
aportsdir=${APORTSDIR:-$HOME/aports}
|
|
|
|
repodir=${REPODIR:-$HOME/packages}
|
|
|
|
|
2013-02-22 08:34:57 +00:00
|
|
|
if [ -f /etc/abuild.conf ]; then
|
|
|
|
. /etc/abuild.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$CARCH" ]; then
|
|
|
|
machine=$(uname -m)
|
|
|
|
case $machine in
|
|
|
|
i[3-9]86) CARCH=x86;;
|
|
|
|
*) CARCH=$machine;;
|
|
|
|
esac
|
|
|
|
fi
|
2009-01-06 15:43:53 +00:00
|
|
|
|
|
|
|
usage() {
|
2009-01-17 10:00:55 +00:00
|
|
|
echo "usage: $program [-a APORTSDIR] [-d REPODIR] [-hp] [-l LOGPREFIX ]"
|
|
|
|
echo " [-r DEPREPO] REPOSITORY..."
|
|
|
|
|
2009-01-06 15:43:53 +00:00
|
|
|
echo "options:"
|
|
|
|
echo " -a Set the aports base dir to APORTSDIR instead of $aportsdir"
|
|
|
|
echo " -d Set destination repository base dir to REPODIR instead of $repodir"
|
|
|
|
echo " -h Show this help and exit"
|
|
|
|
echo " -l Send build to logfile, prefixed by LOGPREFIX"
|
|
|
|
echo " -p Purge obsolete packages from REPODIR after build"
|
2009-01-17 10:00:55 +00:00
|
|
|
echo " -r Dependencies are found in DEPREPO"
|
2009-01-06 15:43:53 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
listpackages() {
|
2013-02-22 10:12:43 +00:00
|
|
|
local repo="$1" i= pkgname= pkgver= pkgrel= subpackage= arch= subpkg=
|
|
|
|
cd "$aportsdir/$repo"
|
2009-01-06 15:43:53 +00:00
|
|
|
for i in */APKBUILD; do
|
2013-02-22 10:12:43 +00:00
|
|
|
cd "$aportsdir/$repo"/${i%/*} || return 1
|
|
|
|
pkgname=
|
|
|
|
pkgver=
|
|
|
|
pkgrel=
|
|
|
|
subpackages=
|
|
|
|
arch=
|
|
|
|
. ./APKBUILD
|
|
|
|
if ! is_in all $arch && ! is_in "$CARCH" $arch; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
for subpkg in $pkgname $subpackages; do
|
|
|
|
echo ${subpkg%:*}-$pkgver-r$pkgrel.apk
|
|
|
|
done
|
2009-01-06 15:43:53 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-06-04 12:22:48 +00:00
|
|
|
all_exist() {
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
[ -e "$1" ] || return 1
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
2013-02-22 09:03:13 +00:00
|
|
|
|
2013-02-22 09:53:55 +00:00
|
|
|
is_in() {
|
|
|
|
local needle="$1"
|
|
|
|
shift
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
[ "$needle" = "$1" ] && return 0
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-02-22 09:03:13 +00:00
|
|
|
list_needbuild() {
|
|
|
|
local repo="$1" i=
|
2009-01-06 15:43:53 +00:00
|
|
|
|
2010-11-02 09:03:20 +00:00
|
|
|
cd "$aportsdir/$repo" || return 0
|
2009-01-06 15:43:53 +00:00
|
|
|
|
2009-02-11 14:08:50 +00:00
|
|
|
# first we try copy everything possible and find out which we need
|
|
|
|
# to rebuild. By doing this we might save us for rebuilding
|
|
|
|
# needed when running 'abuild -R'
|
2009-01-06 15:43:53 +00:00
|
|
|
for i in */APKBUILD; do
|
2010-11-02 09:39:34 +00:00
|
|
|
[ -f "$aportsdir/$repo/$i" ] || continue
|
2009-02-11 14:08:50 +00:00
|
|
|
export REPODEST="$repodir"
|
|
|
|
cd "$aportsdir/$repo"/${i%/*} || return 1
|
2013-02-15 13:05:39 +00:00
|
|
|
pkgname=
|
|
|
|
pkgver=
|
|
|
|
pkgrel=
|
|
|
|
subpackages=
|
2013-02-22 09:53:55 +00:00
|
|
|
arch=
|
2013-02-15 13:05:39 +00:00
|
|
|
. ./APKBUILD
|
|
|
|
|
2013-02-22 09:53:55 +00:00
|
|
|
if ! is_in all $arch && ! is_in $CARCH $arch; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2013-02-15 13:05:39 +00:00
|
|
|
pkgs=
|
|
|
|
for subpkg in $pkgname $subpackages; do
|
|
|
|
pkgfile=${subpkg%:*}-$pkgver-r$pkgrel.apk
|
|
|
|
if ! [ -f "$REPODEST/$repo/$CARCH/$pkgfile" ]; then
|
|
|
|
pkgs="$pkgs $pkgfile"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z "$pkgs" ]; then
|
2009-02-11 14:08:50 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# try link or copy the files if they are in the ports dir
|
2009-06-04 12:22:48 +00:00
|
|
|
if all_exist $pkgs; then
|
2013-02-22 09:03:13 +00:00
|
|
|
echo ">>> Copying " $pkgs >&2
|
2013-02-22 08:34:57 +00:00
|
|
|
cp -p -l $pkgs "$repodir/$repo/$CARCH"/ 2>/dev/null \
|
|
|
|
|| cp -p $pkgs "$repodir/$repo/$CARCH"/ \
|
2013-02-22 09:03:13 +00:00
|
|
|
|| echo "$i"
|
2009-02-11 14:08:50 +00:00
|
|
|
else
|
2013-02-22 09:03:13 +00:00
|
|
|
echo "$i"
|
2009-02-11 14:08:50 +00:00
|
|
|
fi
|
2009-01-06 15:43:53 +00:00
|
|
|
done
|
2013-02-22 09:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_build() {
|
|
|
|
local repo="$1" i=
|
|
|
|
cd "$aportsdir/$repo" || return 0
|
|
|
|
local needbuild="$(list_needbuild $repo)"
|
2009-02-11 14:08:50 +00:00
|
|
|
|
2013-02-22 09:35:19 +00:00
|
|
|
export REPODEST="$repodir"
|
2009-02-11 14:08:50 +00:00
|
|
|
# build the postponed packages if any
|
|
|
|
if [ -n "$needbuild" ]; then
|
|
|
|
for i in $needbuild; do
|
|
|
|
cd "$aportsdir/$repo"/${i%/*} || return 1
|
|
|
|
abuild -k -R || return 1
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2009-02-17 07:42:15 +00:00
|
|
|
# kill old packages in repo
|
2009-03-05 08:39:25 +00:00
|
|
|
if [ -n "$dopurge" ]; then
|
2013-02-07 16:06:38 +00:00
|
|
|
echo ">>> Removing old packages from $repo..."
|
2009-03-05 08:39:25 +00:00
|
|
|
local tmp=$(mktemp /tmp/$program-XXXXXX)
|
|
|
|
local purgefiles
|
2013-02-22 08:34:57 +00:00
|
|
|
cd "$repodir/$repo/$CARCH" || return 1
|
2009-03-05 08:39:25 +00:00
|
|
|
trap 'rm -f "$tmp"; exit 1' INT
|
|
|
|
( listpackages "$1") >$tmp
|
|
|
|
purge=$(ls *.apk 2>/dev/null | grep -v -w -f $tmp)
|
|
|
|
if [ -n "$purge" ]; then
|
|
|
|
rm -f $purge
|
|
|
|
fi
|
|
|
|
rm -f "$tmp"
|
|
|
|
fi
|
2009-02-17 07:42:15 +00:00
|
|
|
|
2009-07-24 17:11:56 +00:00
|
|
|
# generate the repository index
|
|
|
|
echo ">>> Generating Index for $repo..."
|
2013-02-22 08:34:57 +00:00
|
|
|
cd "$repodir/$repo/$CARCH"
|
2009-07-24 17:11:56 +00:00
|
|
|
local deps
|
|
|
|
for i in $deprepo; do
|
|
|
|
deps="--repo $repodir/$i"
|
|
|
|
done
|
|
|
|
oldindex=
|
|
|
|
if [ -f APKINDEX.tar.gz ]; then
|
|
|
|
oldindex="--index APKINDEX.tar.gz"
|
2009-01-06 15:43:53 +00:00
|
|
|
fi
|
2009-07-24 17:11:56 +00:00
|
|
|
tmpindex=$(mktemp).tar.gz
|
2013-02-22 08:34:57 +00:00
|
|
|
apk index --rewrite-arch $CARCH $oldindex -o $tmpindex \
|
2009-09-03 16:35:00 +00:00
|
|
|
--description "$repo $(cd $aportsdir && git describe)" \
|
2011-11-01 08:45:19 +00:00
|
|
|
-- *.apk
|
2009-07-24 17:11:56 +00:00
|
|
|
abuild-sign $tmpindex && mv $tmpindex APKINDEX.tar.gz
|
2009-07-28 08:44:32 +00:00
|
|
|
chmod 644 APKINDEX.tar.gz
|
|
|
|
rm -f tmp.*
|
2009-01-06 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 10:00:55 +00:00
|
|
|
while getopts "a:d:hl:pr:" opt; do
|
2009-01-06 15:43:53 +00:00
|
|
|
case "$opt" in
|
|
|
|
a) aportsdir=$OPTARG;;
|
|
|
|
d) repodir=$OPTARG;;
|
|
|
|
h) usage >&2;;
|
|
|
|
l) logprefix=$OPTARG;;
|
|
|
|
p) dopurge=1;;
|
2009-01-17 10:00:55 +00:00
|
|
|
r) deprepo="$deprepo $OPTARG";;
|
2009-01-06 15:43:53 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
[ $# -eq 0 ] && usage >&2
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
if [ -n "$logprefix" ]; then
|
2013-02-22 09:03:13 +00:00
|
|
|
do_build $1 >$logprefix.$1.log 2>&1 || exit 1
|
2009-01-06 15:43:53 +00:00
|
|
|
else
|
2013-02-22 09:03:13 +00:00
|
|
|
do_build $1 || exit 1
|
2009-01-06 15:43:53 +00:00
|
|
|
fi
|
2009-02-11 14:08:50 +00:00
|
|
|
deprepo="$deprepo $1"
|
2009-01-06 15:43:53 +00:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
|