From c3c08ee41c01b0beb2f53d7e75cf089dfbae9f99 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Tue, 15 Apr 2008 13:19:30 -0400 Subject: Switch to proper script usage Switch to a callable script in place of an include file Signed-off-by: Aaron Griffin --- db-core | 6 +- db-core64 | 6 +- db-extra | 6 +- db-extra64 | 6 +- db-inc | 179 ------------------------------------------------------- db-testing | 6 +- db-testing64 | 6 +- db-unstable | 6 +- db-unstable64 | 6 +- db-update | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 195 insertions(+), 219 deletions(-) delete mode 100644 db-inc create mode 100644 db-update diff --git a/db-core b/db-core index ccbfb61..f14bfab 100755 --- a/db-core +++ b/db-core @@ -1,7 +1,3 @@ #!/bin/bash -repoid=5 -reponame="core" -arch="i686" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "i686" "core" diff --git a/db-core64 b/db-core64 index d15be60..f14bfab 100755 --- a/db-core64 +++ b/db-core64 @@ -1,7 +1,3 @@ #!/bin/bash -repoid=5 -reponame="core" -arch="x86_64" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "i686" "core" diff --git a/db-extra b/db-extra index 8d2c5b8..99c7b8f 100755 --- a/db-extra +++ b/db-extra @@ -1,7 +1,3 @@ #!/bin/bash -repoid=2 -reponame="extra" -arch="i686" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "i686" "extra" diff --git a/db-extra64 b/db-extra64 index 19eef9f..5c183e9 100755 --- a/db-extra64 +++ b/db-extra64 @@ -1,7 +1,3 @@ #!/bin/bash -repoid=2 -reponame="extra" -arch="x86_64" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "x86_64" "extra" diff --git a/db-inc b/db-inc deleted file mode 100644 index 3f0e286..0000000 --- a/db-inc +++ /dev/null @@ -1,179 +0,0 @@ -#!/bin/bash - -# where are the arch scripts located? -ARCHDIR="/arch" - -#All this fun stuff used to be in the db-(whatever) files -# Let's make it cleaner -export CARCH="$arch" -ftppath="/home/ftp/$reponame/os/$arch/" -svnpath="/home/svn-packages" -svnrepo="$reponame-$arch" - -#Hacky for now -if [ "$arch" = "x86_64" ]; then - stagedir="$HOME/staging/${reponame}64" -else - stagedir="$HOME/staging/$reponame" -fi - -WORKDIR="~/.dbscripts" -CHECKOUTDIR="$WORKDIR/checkout" -LOCKFILE="/tmp/.repolck.$arch.$repoid" -DBFILE="$WORKDIR/$reponame.db.tar.gz" - -if [ ! `type -p fakeroot` ]; then - echo "error: fakeroot is missing" >&2 - exit 1 -fi - -if [ ! -d $stagedir ]; then - echo "error: staging directory missing: $stagedir" >&2 - exit 1 -fi - -# Get the package name from the filename -# hackish, but should work for now -getpkgname() { - local tmp - - tmp=${1##*/} - tmp=${tmp%.pkg.tar.gz} - tmp=${tmp%-i686} - tmp=${tmp%-x86_64} - echo ${tmp%-*-*} -} - -cleanup() { - # unlock - rm -f "$LOCKFILE" - [ "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} - -die() { - echo "$*" >&2 - cleanup 1 -} - -# check for locks -if [ -f "$LOCKFILE" ]; then - owner=$(/bin/ls -l $LOCKFILE | /bin/awk '{print $3}') - echo "error: db generation is already in progress (started by $owner)" - exit 1 -fi - -# catch ^C breaks -trap ctrl_c SIGINT -# lock -touch "$LOCKFILE" - -if [ -d $CHECKOUTDIR ]; then - cd $CHECKOUTDIR - svn update - if [ $? -gt 0 ]; then - die "==> SVN update failed, aborting!" - fi -else - echo "==> Checking out repo: $svnrepo ($arch) - Please be patient" - svn checkout file://$svnpath $CHECKOUTDIR - if [ $? -gt 0 ]; then - die "==> SVN checkout failed, aborting!" - fi -fi - -cd $CHECKOUTDIR - -# Checkout the SVN module if we need to -updatelists= -if [ "`ls $stagedir/add 2>/dev/null`" -o "`ls $stagedir/del 2>/dev/null`" ]; then - updatelists=1 -else - echo "No files to process" - cleanup 0 -fi - -# 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. - -if [ -d $stagedir/add -a "`ls $stagedir/add`" ]; then - echo "==> Processing new/updated packages for repository '$reponame'..." >&2 - - # copy the db file into our working area - cp $ftppath/$reponame.db.tar.gz $DBFILE - - cd $stagedir/add - # run it thru fakeroot make sure everything is owned by root.root - echo "$ARCHDIR/updatesync-many add $DBFILE $CHECKOUTDIR $svnrepo" | fakeroot - - if [ $? -ne 0 ]; then - die "==> Error returned from updatesync-many" - fi - - cp $DBFILE $ftppath - - # only for i686 (for now) - if [ "$arch" = "i686" ]; then - echo "==> Scanning for New/Updated packages..." >&2 - cd $stagedir/add - $ARCHDIR/pkgdb1 $CHECKOUTDIR $svnrepo | $ARCHDIR/pkgdb2-add $repoid $stagedir/add - fi - - # move the package files into the ftp directory - mv -f $stagedir/add/*.pkg.tar.gz $ftppath -fi - -if [ -d $stagedir/del -a "`ls $stagedir/del`" ]; then - echo "==> Processing deleted packages for repository '$reponame'..." >&2 - - # copy the db file into our working area - cp $ftppath/$reponame.db.tar.gz $DBFILE - - cd $stagedir/del - # run it thru fakeroot make sure everything is owned by root.root - echo "$ARCHDIR/updatesync-many del $DBFILE NOT-USED ZOMGWOO" \ - | fakeroot - - if [ $? -ne 0 ]; then - die "==> Error returned from updatesync-many" - fi - - cp $DBFILE $ftppath - - # only for i686 (for now) - if [ "$arch" = "i686" ]; then - echo "==> Scanning for Deleted packages..." >&2 - cd $stagedir/del - ( - for i in *.pkg.tar.gz; do - pkgname=$(getpkgname $i) - echo $pkgname - done - ) | $ARCHDIR/pkgdb2-del $repoid $stagedir/del - fi - - # remove the package files - rm -f $stagedir/del/*.pkg.tar.gz -fi - -if [ "$updatelists" ]; then - echo "==> Generating Text Package List..." >&2 - cd $CHECKOUTDIR - $ARCHDIR/genpkglist $ftppath $svnrepo - if [ -f packages.txt ]; then - mv packages.txt $ftppath/packages.txt - fi -fi - -cleanup - -# vim: set ts=4 sw=4 noet ft=sh: diff --git a/db-testing b/db-testing index 15205a2..e2fe01d 100755 --- a/db-testing +++ b/db-testing @@ -1,7 +1,3 @@ #!/bin/bash -repoid=4 -reponame="testing" -arch="i686" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "i686" "testing" diff --git a/db-testing64 b/db-testing64 index c34355b..244372b 100755 --- a/db-testing64 +++ b/db-testing64 @@ -1,7 +1,3 @@ #!/bin/bash -repoid=4 -reponame="testing" -arch="x86_64" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "x86_64" "testing" diff --git a/db-unstable b/db-unstable index b0231b4..a9aa49c 100755 --- a/db-unstable +++ b/db-unstable @@ -1,8 +1,4 @@ #!/bin/bash -repoid=3 -reponame="unstable" -arch="i686" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "i686" "unstable" diff --git a/db-unstable64 b/db-unstable64 index 225cf97..d9448ab 100755 --- a/db-unstable64 +++ b/db-unstable64 @@ -1,8 +1,4 @@ #!/bin/bash -repoid=3 -reponame="unstable" -arch="x86_64" - -. $(dirname $0)/db-inc +$(dirname $0)/db-update "x86_64" "unstable" diff --git a/db-update b/db-update new file mode 100644 index 0000000..24ca489 --- /dev/null +++ b/db-update @@ -0,0 +1,187 @@ +#!/bin/bash + +# where are the arch scripts located? +ARCHDIR="/arch" + +if [ $# -ne 2 ]; then + echo "usage: $(basename $0) " + exit 1 +fi + +#All this fun stuff used to be in the db-(whatever) files +# Let's make it cleaner +arch="$1" +reponame="$2" + +export CARCH="$arch" +ftppath="/home/ftp/$reponame/os/$arch/" +svnpath="/home/svn-packages" +svnrepo="$reponame-$arch" + +#Hacky for now +if [ "$arch" = "x86_64" ]; then + stagedir="$HOME/staging/${reponame}64" +else + stagedir="$HOME/staging/$reponame" +fi + +WORKDIR="~/.dbscripts" +CHECKOUTDIR="$WORKDIR/checkout" +LOCKFILE="/tmp/.repolck.$arch.$repoid" +DBFILE="$WORKDIR/$reponame.db.tar.gz" + +if [ ! `type -p fakeroot` ]; then + echo "error: fakeroot is missing" >&2 + exit 1 +fi + +if [ ! -d $stagedir ]; then + echo "error: staging directory missing: $stagedir" >&2 + exit 1 +fi + +# Get the package name from the filename +# hackish, but should work for now +getpkgname() { + local tmp + + tmp=${1##*/} + tmp=${tmp%.pkg.tar.gz} + tmp=${tmp%-i686} + tmp=${tmp%-x86_64} + echo ${tmp%-*-*} +} + +cleanup() { + # unlock + rm -f "$LOCKFILE" + [ "$1" ] && exit $1 +} + +ctrl_c() { + echo "Interrupted" >&2 + cleanup 0 +} + +die() { + echo "$*" >&2 + cleanup 1 +} + +# check for locks +if [ -f "$LOCKFILE" ]; then + owner=$(/bin/ls -l $LOCKFILE | /bin/awk '{print $3}') + echo "error: db generation is already in progress (started by $owner)" + exit 1 +fi + +# catch ^C breaks +trap ctrl_c SIGINT +# lock +touch "$LOCKFILE" + +if [ -d $CHECKOUTDIR ]; then + cd $CHECKOUTDIR + svn update + if [ $? -gt 0 ]; then + die "==> SVN update failed, aborting!" + fi +else + echo "==> Checking out repo: $svnrepo ($arch) - Please be patient" + svn checkout file://$svnpath $CHECKOUTDIR + if [ $? -gt 0 ]; then + die "==> SVN checkout failed, aborting!" + fi +fi + +cd $CHECKOUTDIR + +# Checkout the SVN module if we need to +updatelists= +if [ "`ls $stagedir/add 2>/dev/null`" -o "`ls $stagedir/del 2>/dev/null`" ]; then + updatelists=1 +else + echo "No files to process" + cleanup 0 +fi + +# 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. + +if [ -d $stagedir/add -a "`ls $stagedir/add`" ]; then + echo "==> Processing new/updated packages for repository '$reponame'..." >&2 + + # copy the db file into our working area + cp $ftppath/$reponame.db.tar.gz $DBFILE + + cd $stagedir/add + # run it thru fakeroot make sure everything is owned by root.root + echo "$ARCHDIR/updatesync-many add $DBFILE $CHECKOUTDIR $svnrepo" | fakeroot + + if [ $? -ne 0 ]; then + die "==> Error returned from updatesync-many" + fi + + cp $DBFILE $ftppath + + # only for i686 (for now) + if [ "$arch" = "i686" ]; then + echo "==> Scanning for New/Updated packages..." >&2 + cd $stagedir/add + $ARCHDIR/pkgdb1 $CHECKOUTDIR $svnrepo | $ARCHDIR/pkgdb2-add $repoid $stagedir/add + fi + + # move the package files into the ftp directory + mv -f $stagedir/add/*.pkg.tar.gz $ftppath +fi + +if [ -d $stagedir/del -a "`ls $stagedir/del`" ]; then + echo "==> Processing deleted packages for repository '$reponame'..." >&2 + + # copy the db file into our working area + cp $ftppath/$reponame.db.tar.gz $DBFILE + + cd $stagedir/del + # run it thru fakeroot make sure everything is owned by root.root + echo "$ARCHDIR/updatesync-many del $DBFILE NOT-USED ZOMGWOO" \ + | fakeroot + + if [ $? -ne 0 ]; then + die "==> Error returned from updatesync-many" + fi + + cp $DBFILE $ftppath + + # only for i686 (for now) + if [ "$arch" = "i686" ]; then + echo "==> Scanning for Deleted packages..." >&2 + cd $stagedir/del + ( + for i in *.pkg.tar.gz; do + pkgname=$(getpkgname $i) + echo $pkgname + done + ) | $ARCHDIR/pkgdb2-del $repoid $stagedir/del + fi + + # remove the package files + rm -f $stagedir/del/*.pkg.tar.gz +fi + +if [ "$updatelists" ]; then + echo "==> Generating Text Package List..." >&2 + cd $CHECKOUTDIR + $ARCHDIR/genpkglist $ftppath $svnrepo + if [ -f packages.txt ]; then + mv packages.txt $ftppath/packages.txt + fi +fi + +cleanup + +# vim: set ts=4 sw=4 noet ft=sh: -- cgit v1.2.3-54-g00ecf