diff options
author | Judd Vinet <judd@archlinux.org> | 2006-02-20 07:33:40 +0100 |
---|---|---|
committer | Judd Vinet <judd@archlinux.org> | 2006-02-20 07:33:40 +0100 |
commit | a49feb74bba7a0dfe7f5a546fc4a188ded208c61 (patch) | |
tree | d380b8f8aa3cc73c58709f18e028c776c2248b88 | |
parent | 7c99f3e12b92f5112f3f79bf55deebcab6c3fc11 (diff) | |
download | dbscripts-a49feb74bba7a0dfe7f5a546fc4a188ded208c61.tar.gz dbscripts-a49feb74bba7a0dfe7f5a546fc4a188ded208c61.tar.xz |
re-worked db-gen scripts -- new and improved
-rwxr-xr-x | db-arch | 4 | ||||
-rwxr-xr-x | db-extra | 4 | ||||
-rw-r--r-- | db-inc | 136 | ||||
-rwxr-xr-x | db-testing | 82 | ||||
-rwxr-xr-x | db-unstable | 4 | ||||
-rwxr-xr-x | pkgdb1 | 73 | ||||
-rwxr-xr-x | pkgdb2-add | bin | 0 -> 13039 bytes | |||
-rwxr-xr-x | pkgdb2-del | bin | 0 -> 8692 bytes | |||
-rwxr-xr-x | updatesync-many | 248 |
9 files changed, 448 insertions, 103 deletions
@@ -1,5 +1,5 @@ #!/bin/bash -# $Id: db-arch,v 1.22 2005/06/21 03:44:57 judd Exp $ +# $Id: db-arch,v 1.23 2006/02/20 06:33:40 judd Exp $ repoid=1 reponame="current" @@ -9,6 +9,8 @@ ftppath="/home/ftp/current/os/i686" cvspath="/home/cvs-arch" cvsmod="arch/build" +stagedir="$HOME/staging/arch" + # call the real script . `dirname $0`/db-inc @@ -1,5 +1,5 @@ #!/bin/bash -# $Id: db-extra,v 1.11 2005/06/21 03:44:57 judd Exp $ +# $Id: db-extra,v 1.12 2006/02/20 06:33:40 judd Exp $ repoid=2 reponame="extra" @@ -9,6 +9,8 @@ ftppath="/home/ftp/extra/os/i686" cvspath="/home/cvs-extra" cvsmod="extra" +stagedir="$HOME/staging/extra" + # call the real script . `dirname $0`/db-inc @@ -1,10 +1,18 @@ -# $Id: db-inc,v 1.3 2005/06/30 22:30:36 judd Exp $ +# $Id: db-inc,v 1.4 2006/02/20 06:33:40 judd Exp $ [ "$UID" = "" ] && UID=`uid` TMPDIR="/tmp/archpkg.$repoid.$UID" +# where are the arch scripts located? +ARCHDIR="/arch-new" + if [ ! `type -p fakeroot` ]; then - echo "error: fakeroot is missing" + echo "error: fakeroot is missing" >&2 + exit 1 +fi + +if [ ! -d $stagedir ]; then + echo "error: staging directory missing: $stagedir" >&2 exit 1 fi @@ -12,7 +20,17 @@ cleanup() { rm -rf $TMPDIR # unlock rm -f /tmp/.repolck.$repoid - exit 0 + [ "$1" ] && exit $1 +} + +ctrl_c() { + echo "Interrupted" >&2 + cleanup 0 +} + +die() { + echo "$*" >&2 + cleanup 1 } # check for locks @@ -23,7 +41,7 @@ if [ -f /tmp/.repolck.$repoid ]; then fi # catch ^C breaks -trap cleanup SIGINT +trap ctrl_c SIGINT # lock touch /tmp/.repolck.$repoid @@ -34,33 +52,103 @@ if [ -d $TMPDIR ]; then fi mkdir $TMPDIR; [ $? -gt 0 ] && exit 1 -echo "==> Generating Pacman Database for repository '$reponame'..." >&2 cd $TMPDIR -CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:$cvspath cvs -q export -r CURRENT $cvsmod -if [ $? -gt 0 ]; then - echo "==> CVS export failed!" - cleanup - exit 1 + +# Checkout the CVS module if we need to +updatelists= +if [ "`ls $stagedir/add`" -o "`ls $stagedir/del`" ]; then + # if $cvsdir is set, then use that instead of doing our own cvs checkout + if [ "$cvsdir" ]; then + mv $cvsdir $TMPDIR/$cvsmod + else + echo "==> Checking out module: $cvsmod" + CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:$cvspath cvs -q export -r CURRENT $cvsmod + if [ $? -gt 0 ]; then + die "==> CVS export failed!" + fi + fi + updatelists=1 +else + echo "No files to process" + cleanup 0 fi -echo "chown -R root.root $TMPDIR/$cvsmod;" \ - "/usr/bin/gensync $TMPDIR/$cvsmod $TMPDIR/$reponame.db.tar.gz $ftppath" \ - | fakeroot +# Right-O, now we look through the "add" and "del" subdirectories of +# $stagedir and process the packages there accordingly -- all packages +# in the "add" dir are added/updated, all packages in the "del" dir +# are removed. +# +# This means the sync db could actually be unpacked/repacked twice in +# one db-* invocation, but it's not a huge performance hit. -[ -f $TMPDIR/$reponame.db.tar.gz ] && mv -f $TMPDIR/$reponame.db.tar.gz $ftppath +if [ "`ls $stagedir/add`" ]; then + cd $TMPDIR + echo "==> Processing new/updated packages for repository '$reponame'..." >&2 -echo "==> Scanning for New/Updated/Deleted packages..." >&2 -cd $TMPDIR/$cvsmod -/arch/pkgdb1 $repoid | /arch/pkgdb2 $repoid $ftppath + # copy the db file into our working area + cp $ftppath/$reponame.db.tar.gz . -echo "==> Generating Text Package List..." >&2 -/arch/genpkglist $reponame + cd $stagedir/add + # run it thru fakeroot make sure everything is owned by root.root + echo "$ARCHDIR/updatesync-many add $TMPDIR/$reponame.db.tar.gz $TMPDIR/$cvsmod" \ + | fakeroot -# hack -- only Current's packages.txt goes in a "setup" subdir -if [ "$reponame" = "current" ]; then - mv packages.txt $ftppath/setup/packages.txt -else - mv packages.txt $ftppath/packages.txt + if [ $? -ne 0 ]; then + die "==> Error returned from updatesync-many" + fi + + cp $TMPDIR/$reponame.db.tar.gz $ftppath + + echo "==> Scanning for New/Updated packages..." >&2 + cd $stagedir/add + $ARCHDIR/pkgdb1 $TMPDIR/$cvsmod | $ARCHDIR/pkgdb2-add $repoid $stagedir/add + + # move the package files into the ftp directory + mv -f $stagedir/add/*.pkg.tar.gz $ftppath +fi + +if [ "`ls $stagedir/del`" ]; then + cd $TMPDIR + echo "==> Processing deleted packages for repository '$reponame'..." >&2 + + # copy the db file into our working area + cp $ftppath/$reponame.db.tar.gz . + + cd $stagedir/del + # run it thru fakeroot make sure everything is owned by root.root + echo "$ARCHDIR/updatesync-many del $TMPDIR/$reponame.db.tar.gz NOT-USED" \ + | fakeroot + + if [ $? -ne 0 ]; then + die "==> Error returned from updatesync-many" + fi + + cp $TMPDIR/$reponame.db.tar.gz $ftppath + + echo "==> Scanning for Deleted packages..." >&2 + cd $stagedir/del + ( + for i in *.pkg.tar.gz; do + pkgname=${i%-*-*} + echo $pkgname + done + ) | $ARCHDIR/pkgdb2-del $repoid $stagedir/del + + # remove the package files + rm -f $stagedir/del/*.pkg.tar.gz +fi + +if [ "$updatelists" ]; then + echo "==> Generating Text Package List..." >&2 + cd $TMPDIR/$cvsmod + $ARCHDIR/genpkglist $reponame + + # hack -- only Current's packages.txt goes in a "setup" subdir + if [ "$reponame" = "current" ]; then + mv packages.txt $ftppath/setup/packages.txt + else + mv packages.txt $ftppath/packages.txt + fi fi cleanup @@ -1,68 +1,54 @@ #!/bin/bash -# $Id: db-testing,v 1.10 2005/02/25 21:27:44 judd Exp $ +# $Id: db-testing,v 1.11 2006/02/20 06:33:40 judd Exp $ -uid=`id -u` repoid=4 +reponame="testing" + ftppath="/home/ftp/testing/os/i686" -TMPDIR="/tmp/archpkg.$repoid.$uid" +cvspath="/home/cvs-arch" +cvsmod="testing" + +stagedir="$HOME/staging/testing" -cleanup() { - rm -rf $TMPDIR - # unlock - rm -f /tmp/.repolck.$repoid - exit 0 +testing_cleanup() { + rm -rf $testingtmp } -# check for locks +# catch ^C +trap cleanup SIGINT + if [ -f /tmp/.repolck.$repoid ]; then owner=`/bin/ls -l /tmp/.repolck.$repoid | awk '{print $3}'` echo "error: db generation is already in progress (started by $owner)" exit 1 fi -if [ -d /tmp/.gensync ]; then - echo "error: someone else is currently running gensync!" - exit 1 -fi - -# catch ^C breaks -trap cleanup SIGINT # lock touch /tmp/.repolck.$repoid -# RedHat's mktemp is broken... -if [ -d $TMPDIR ]; then - echo "==> Removing old temp dir..." >&2 - rm -rf $TMPDIR || exit 1 -fi -mkdir $TMPDIR; [ $? -gt 0 ] && exit 1 - -echo "==> Generating Pacman Database for TESTING..." >&2 -cd $TMPDIR -echo "--- CURRENT ---" -CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-arch cvs -q export -r TESTING arch -mv arch/build/* . && rm -rf arch -echo "--- EXTRA ---" -CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-extra cvs -q export -r TESTING extra -cp -a extra/* . && rm -rf extra -echo "--- UNSTABLE ---" -CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-unstable cvs -q export -r TESTING unstable -cp -a unstable/* . && rm -rf unstable -# check again -if [ -d /tmp/.gensync ]; then - echo "error: someone else is currently running gensync!" - cleanup - exit 1 +# testing is special, so we have to do the CVS checkout stuff here +testingtmp=$(mktemp -d /tmp/testtmp-XXXXXX) || exit 1 +cvsdir=$testingtmp/testing +mkdir $cvsdir +cd $cvsdir + +if [ "`ls $stagedir/add`" -o "`ls $stagedir/del`" ]; then + echo "==> Checking out TESTING branches..." >&2 + echo "--- CURRENT ---" + CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-arch cvs -q export -r TESTING arch + mv arch/build/* . && rm -rf arch + echo "--- EXTRA ---" + CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-extra cvs -q export -r TESTING extra + cp -a extra/* . && rm -rf extra + echo "--- UNSTABLE ---" + CVS_RSH=ssh CVSROOT=:ext:cvs.archlinux.org:/home/cvs-unstable cvs -q export -r TESTING unstable + cp -a unstable/* . && rm -rf unstable fi -/usr/bin/gensync $TMPDIR $TMPDIR/testing.db.tar.gz $ftppath -[ -f $TMPDIR/testing.db.tar.gz ] && mv -f $TMPDIR/testing.db.tar.gz $ftppath -echo "==> Scanning for New/Updated/Deleted packages..." >&2 -cd $TMPDIR -/arch/pkgdb1 $repoid | /arch/pkgdb2 $repoid $ftppath +# unlock +rm -f /tmp/.repolck.$repoid -echo "==> Generating Text Package List..." >&2 -/arch/genpkglist testing -mv packages.txt $ftppath/packages.txt +# call the real script +. `dirname $0`/db-inc -cleanup +testing_cleanup diff --git a/db-unstable b/db-unstable index a22188b..194bee5 100755 --- a/db-unstable +++ b/db-unstable @@ -1,5 +1,5 @@ #!/bin/bash -# $Id: db-unstable,v 1.16 2005/06/21 03:44:57 judd Exp $ +# $Id: db-unstable,v 1.17 2006/02/20 06:33:40 judd Exp $ repoid=3 reponame="unstable" @@ -9,6 +9,8 @@ ftppath="/home/ftp/unstable/os/i686" cvspath="/home/cvs-unstable" cvsmod="unstable" +stagedir="$HOME/staging/unstable" + # call the real script . `dirname $0`/db-inc @@ -1,40 +1,57 @@ #!/bin/bash -# $Id: pkgdb1,v 1.3 2005/01/03 08:11:19 judd Exp $ +# $Id: pkgdb1,v 1.4 2006/02/20 06:33:40 judd Exp $ -tl=`pwd` +STAGEDIR=`pwd` -repoid=$1 -if [ "$repoid" = "" ]; then +ABSDIR=$1 +if [ "$ABSDIR" = "" ]; then me=`basename $0` - echo "usage: $me <repoid>" + echo "usage: $me <abs_dir>" >&2 exit 1 fi -cd $tl -for category in `find . -maxdepth 1 -type d | grep -v CVS | grep -v "^extra" | grep -v "^unstable"`; do - category=`echo $category | sed 's|./||'` - if [ "$category" = "." ]; then +if [ ! "`ls $STAGEDIR/*.pkg.tar.gz 2>/dev/null`" ]; then + exit +fi + +cd $STAGEDIR +for pkgfile in `ls $STAGEDIR/*.pkg.tar.gz`; do + tmp=${pkgfile##*/} + pkgname=${tmp%-*-*}; + fullname=${tmp%.pkg.tar.gz} + # find the matching PKGBUILD + tmpf=$(mktemp /tmp/pkgdb1.XXXXXXXXXX) || exit 1 + find $ABSDIR -type d -name "$pkgname" >$tmpf + if [ "`cat $tmpf | wc -l`" != "1" ]; then + echo "WARNING: could not find PKGBUILD for $pkgname, cannot update this entry" >&2 + rm $tmpf continue fi - for pkg in `ls $category | sort`; do - cd $tl/$category/$pkg - if [ -f PKGBUILD ]; then - unset depends source deplist sources - unset pkgname pkgver pkgrel pkgdesc url - . PKGBUILD - deplist=${depends[@]} - sources=${source[@]} - echo $pkgname - echo $pkgver - echo $pkgrel - echo $pkgdesc - echo $category - echo $url - echo $sources - echo $deplist - fi - cd $tl - done + pkgbuild="`cat $tmpf`/PKGBUILD" + rm $tmpf + if [ ! -f $pkgbuild ]; then + echo "WARNING: could not find PKGBUILD for $fullname, cannot update this entry" >&2 + continue + fi + # pick out the category from the pathname + catpath=$(cd `dirname $pkgbuild`/.. && pwd) + category=${catpath##*/} + # now read the PKGBUILD and output the data for pkgdb2 + unset pkgname pkgver pkgrel pkgdesc license groups provides md5sums force + unset replaces depends conflicts backup source install build makedepends + unset options + source $pkgbuild || continue + + deplist=${depends[@]} + sources=${source[@]} + echo $pkgname + echo $pkgver + echo $pkgrel + echo $pkgdesc + echo $category + echo $url + echo $sources + echo $deplist done exit 0 diff --git a/pkgdb2-add b/pkgdb2-add Binary files differnew file mode 100755 index 0000000..e6a87c0 --- /dev/null +++ b/pkgdb2-add diff --git a/pkgdb2-del b/pkgdb2-del Binary files differnew file mode 100755 index 0000000..af44fe1 --- /dev/null +++ b/pkgdb2-del diff --git a/updatesync-many b/updatesync-many new file mode 100755 index 0000000..150cd66 --- /dev/null +++ b/updatesync-many @@ -0,0 +1,248 @@ +#!/bin/bash +# +# updatesync-many +# +# Copyright (c) 2004 by Jason Chu <jason@archlinux.org> +# Derived from gensync (c) 2002-2006 Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +usage() { + echo "updatesync-many" + echo "usage: $0 <action> <dbfile> <abs_dir>" + echo + echo "This should probably only be run from the Arch db-generation scripts" + echo + echo "Caveats:" + echo " - Make sure you run it from the staging directory" + echo " - Use absolute pathnames for dbfile and abs_dir" + echo + exit 0 +} + +die() +{ + echo "updatesync-many: $*" >&2 + rm -rf $TMPDIR + exit 1 +} + +msg() +{ + echo "updatesync-many: $*" >&2 +} + +check_option() { + local i + for i in ${options[@]}; do + local uc=`echo $i | tr [:lower:] [:upper:]` + local lc=`echo $i | tr [:upper:] [:lower:]` + if [ "$uc" = "$1" -o "$lc" = "$1" ]; then + echo $1 + return + fi + done +} + +get_md5checksum() +{ + md5line=`md5sum $1` + [ ! -z "$md5line" ] && pkgmd5sum=${md5line% *} + echo $pkgmd5sum +} + +db_write_entry() +{ + unset pkgname pkgver pkgrel pkgdesc license groups provides md5sums force + unset replaces depends conflicts backup source install build makedepends + unset options + source $1 || return 1 + cd $TMPDIR + mkdir $pkgname-$pkgver-$pkgrel || return 1 + cd $pkgname-$pkgver-$pkgrel + # desc + : >desc + echo "%NAME%" >>desc + echo "$pkgname" >>desc + echo "" >>desc + echo "%VERSION%" >>desc + echo "$pkgver-$pkgrel" >>desc + echo "" >>desc + echo "%DESC%" >>desc + echo "$pkgdesc" >>desc + echo "" >>desc + echo "%CSIZE%" >>desc + echo "$csize" >>desc + echo "" >>desc + if [ ! -z $pkgmd5sum ]; then + echo "%MD5SUM%" >>desc + echo "$pkgmd5sum" >>desc + echo "" >>desc + fi + if [ ${#groups[*]} -gt 0 ]; then + echo "%GROUPS%" >>desc + for it in "${groups[@]}"; do + echo "$it" >>desc + done + echo "" >>desc + fi + if [ ${#replaces[*]} -gt 0 ]; then + echo "%REPLACES%" >>desc + for it in "${replaces[@]}"; do + echo "$it" >>desc + done + echo "" >>desc + fi + if [ "$force" = "y" -o "$force" = "Y" -o "`check_option FORCE`" ]; then + echo "%FORCE%" >>desc + echo "" >>desc + fi + # depends + : >depends + if [ ${#depends[*]} -gt 0 ]; then + echo "%DEPENDS%" >>depends + for it in "${depends[@]}"; do + echo "$it" >>depends + done + echo "" >>depends + fi + if [ ${#conflicts[*]} -gt 0 ]; then + echo "%CONFLICTS%" >>depends + for it in "${conflicts[@]}"; do + echo "$it" >>depends + done + echo "" >>depends + fi + if [ ${#provides[*]} -gt 0 ]; then + echo "%PROVIDES%" >>depends + for it in "${provides[@]}"; do + echo "$it" >>depends + done + echo "" >>depends + fi +} + +delete_entry() +{ + # strip to the basename + tmp=${1##*/} + # grab the pkgname + pkgname=${tmp%-*-*} + for i in *; do + if [ "${i%-*-*}" = "$pkgname" ]; then + rm -rf $i + fi + done +} + +update_entry() +{ + pkgfile=$1 + tmp=${pkgfile##*/} + pkgname=${tmp%-*-*}; + fullname=${tmp%.pkg.tar.gz} + + # find the matching PKGBUILD + tmpf=$(mktemp /tmp/updatesync-many.XXXXXXXXXX) || exit 1 + find $ABSDIR -type d -name "$pkgname" >$tmpf + if [ "`cat $tmpf | wc -l`" != "1" ]; then + msg "WARNING: could not find PKGBUILD for $pkgname, cannot update this entry" + rm $tmpf + return + fi + pkgbuild="`cat $tmpf`/PKGBUILD" + rm $tmpf + if [ ! -f $pkgbuild ]; then + msg "WARNING: could not find PKGBUILD for $fullname, cannot update this entry" + return + fi + + source $pkgbuild + if [ $? -ne 0 ]; then + msg "WARNING: PKGBUILD for $fullname has errors, cannot update this entry" + return + fi + + # all good so far - delete the old entry + cd $TMPDIR + delete_entry $pkgfile + + csize=`du -b $pkgfile | cut -f1` + pkgmd5sum=`get_md5checksum $pkgfile` + [ -z $pkgmd5sum ] && die "error generating checksum for $pkgfile" + + db_write_entry $pkgbuild || die "error writing entry for $pkgname" + cd - >/dev/null +} + + +if [ $# -lt 3 ]; then + usage + exit 1 +fi + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +ACTION=$1 +PKGDB=$2 +ABSDIR=$3 +STAGEDIR="`pwd`" +PKGDIR="`dirname $PKGDB`" +if [ "$PKGDIR" = "." ]; then + PKGDIR=$STAGEDIR +fi + +if [ "$ACTION" != "add" -a "$ACTION" != "del" ]; then + usage + exit 1 +fi + +# Prepare the sync db for modifications +TMPDIR=$(mktemp -d /tmp/updatesync-many.XXXXXXXXXX) || exit 1 +cd $TMPDIR +if [ ! -f $PKGDB ]; then + die "$PKGDB not found" +fi +msg "Unpacking db: $PKGDB" +tar zxf $PKGDB || die "error unpacking $PKGDB" + +# Process packages in the staging directory +for pkgfile in $STAGEDIR/*.pkg.tar.gz; do + tmp=${pkgfile##*/} + pkgname=${tmp%-*-*}; + fullname=${tmp%.pkg.tar.gz} + if [ "$ACTION" = "del" ]; then + msg "Deleting entry: $pkgname" + delete_entry $pkgfile + else + msg "Updating entry: $pkgname" + update_entry $pkgfile + fi +done + +# Repackage the DB +msg "Repacking db: $PKGDB" +cd $TMPDIR +tar c * | gzip -9 >$PKGDB || die "error writing to $PKGDB" + +cd / +rm -rf $TMPDIR + +exit 0 |