From 1d903977850d8e8a22f8246994e72b0ef101eb76 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 7 Aug 2010 20:05:09 +0200 Subject: add some common functions for our test suite --- test/lib/common.inc | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/lib/common.inc (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc new file mode 100644 index 0000000..5abe2ed --- /dev/null +++ b/test/lib/common.inc @@ -0,0 +1,113 @@ +pkgdir="$(dirname $0)/packages" + +oneTimeSetUp() { + local p + echo -n 'Building packages...' + for p in "${pkgdir}"/*; do + pushd $p >/dev/null + linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || exit 1 + linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || exit 1 + popd >/dev/null + done + echo 'done' + echo +} + +oneTimeTearDown() { + find "${pkgdir}" -name '*.pkg.tar.*' -delete +} + +setUp() { + local p + local pkg + + [ -f "${curdir}/../config.local" ] && exit 1 + TMP="$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX)" + #echo "Using ${TMP}" + + mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} + mkdir -p "${TMP}/ftp/"{{core,extra,community,testing,community-testing}/os,packages/{arch,community}}/{i686,any,x86_64} + mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing} + + echo -n 'Creating svn repository...' + svnadmin create "${TMP}/svn-packages-repo" + svnadmin create "${TMP}/svn-community-repo" + svn checkout -q "file://${TMP}/svn-packages-repo" "${TMP}/svn-packages-copy" + svn checkout -q "file://${TMP}/svn-community-repo" "${TMP}/svn-community-copy" + + for p in "${pkgdir}"/*; do + pkg=$(basename $p) + mkdir -p "${TMP}/svn-packages-copy/${pkg}"/{trunk,repos} + cp "${p}/PKGBUILD" "${TMP}/svn-packages-copy"/${pkg}/trunk/ + svn add -q "${TMP}/svn-packages-copy"/${pkg} + svn commit -q -m"initial commit of ${pkg}" "${TMP}/svn-packages-copy" + done + echo 'done' + + cat < "${curdir}/../config.local" + FTP_BASE="${TMP}/ftp" + SVNREPO="file://${TMP}/svn-packages-repo" + SVNREPOCOMMUNITY="file://${TMP}/svn-community-repo" + CLEANUP_DESTDIR="${TMP}/package-cleanup" + SOURCE_CLEANUP_DESTDIR="${TMP}/source-cleanup" + STAGING="${TMP}/staging" + TMPDIR="${TMP}/tmp" +eot + . "${curdir}/../config" +} + +tearDown() { + rm -rf "${TMP}" + rm -f "${curdir}/../config.local" + echo +} + +testPackages() { + local p + for p in "${pkgdir}"/*; do + pushd $p >/dev/null + namcap *.pkg.tar.* || fail 'namcap failed' + popd >/dev/null + done +} + +releasePackage() { + local repo=$1 + local pkgbase=$2 + local arch=$3 + + pushd "${TMP}/svn-packages-copy"/${pkgbase}/trunk/ >/dev/null + archrelease ${repo}-${arch} >/dev/null + popd >/dev/null + cp "${pkgdir}/${pkgbase}"/*.pkg.tar.* "${STAGING}"/${repo}/ +} + +checkAnyPackage() { + local repo=$1 + local pkg=$2 + local arch + + [ -f "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "packages/arch/any/${pkg} not found" + + for arch in any i686 x86_64; do + [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/any/${pkg}" + done + [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" + + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" +} + +checkPackage() { + local repo=$1 + local pkg=$2 + local arch=$3 + + [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "packages/arch/${arch}/${pkg} not found" + [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" + [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" + + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/${arch}/${pkg}" + + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" +} -- cgit v1.2.3-54-g00ecf From bccf84211be4abda3c96ded43f03b597081fecb1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 7 Aug 2010 21:21:08 +0200 Subject: add test for db-remove --- test/lib/common.inc | 13 +++------ test/runTest | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 10 deletions(-) (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index 5abe2ed..4052aa1 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,4 +1,4 @@ -pkgdir="$(dirname $0)/packages" +pkgdir="${curdir}/packages" oneTimeSetUp() { local p @@ -57,20 +57,13 @@ eot } tearDown() { + echo -n 'Cleaning up...' rm -rf "${TMP}" rm -f "${curdir}/../config.local" + echo 'done' echo } -testPackages() { - local p - for p in "${pkgdir}"/*; do - pushd $p >/dev/null - namcap *.pkg.tar.* || fail 'namcap failed' - popd >/dev/null - done -} - releasePackage() { local repo=$1 local pkgbase=$2 diff --git a/test/runTest b/test/runTest index 1d54ea4..258a181 100755 --- a/test/runTest +++ b/test/runTest @@ -3,6 +3,23 @@ curdir=$(readlink -e $(dirname $0)) . "${curdir}/lib/common.inc" +# +# self test +# + +testPackages() { + local p + for p in "${pkgdir}"/*; do + pushd $p >/dev/null + namcap *.pkg.tar.* || fail 'namcap failed' + popd >/dev/null + done +} + + +# +# db-update +# testAddSimplePackages() { local arches=('i686' 'x86_64') @@ -63,4 +80,65 @@ testAddSplitPackages() { } +# +# db-remove +# + +testRemovePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update extra + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + ../db-remove ${pkgbase} extra ${arch} + done + done + + for arch in ${arches[@]}; do + [ -z "$(bsdtar -tf "${FTP_BASE}/extra/os/${arch}/extra.db.tar.gz" -O)" ] || fail "extra/os/${arch}/${repo}.db.tar.gz should be empty" + done + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + svn up -q "${TMP}/svn-packages-copy/${pkgbase}" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/extra-${arch}" ] && fail "svn-packages-copy/${pkgbase}/repos/extra-${arch} should not exist" + done + done +} + +testRemoveAnyPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + + ../db-update extra + + for pkgbase in ${pkgs[@]}; do + ../db-remove ${pkgbase} extra any + done + + for arch in ${arches[@]}; do + [ -z "$(bsdtar -tf "${FTP_BASE}/extra/os/${arch}/extra.db.tar.gz" -O)" ] || fail "extra/os/${arch}/${repo}.db.tar.gz should be empty" + done + + for pkgbase in ${pkgs[@]}; do + svn up -q "${TMP}/svn-packages-copy/${pkgbase}" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/extra-any" ] && fail "svn-packages-copy/${pkgbase}/repos/extra-any should not exist" + done +} + + . "${curdir}/lib/shunit2" -- cgit v1.2.3-54-g00ecf From 76ef37d1b1e03b0c517f8513b943474ea379738e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 7 Aug 2010 23:48:03 +0200 Subject: Simplify tests and add tests for db-move --- test/lib/common.inc | 38 ++++++++++++++++++++--- test/runTest | 86 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 110 insertions(+), 14 deletions(-) (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index 4052aa1..3ba715e 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,12 +1,14 @@ -pkgdir="${curdir}/packages" +. "${curdir}/../db-functions" oneTimeSetUp() { local p + pkgdir="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" + cp -r ${curdir}/packages/* "${pkgdir}" echo -n 'Building packages...' for p in "${pkgdir}"/*; do pushd $p >/dev/null linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || exit 1 - linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || exit 1 + [ -f *-any.pkg.tar.* ] || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || exit 1 popd >/dev/null done echo 'done' @@ -22,7 +24,7 @@ setUp() { local pkg [ -f "${curdir}/../config.local" ] && exit 1 - TMP="$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX)" + TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #echo "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} @@ -82,7 +84,7 @@ checkAnyPackage() { [ -f "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "packages/arch/any/${pkg} not found" - for arch in any i686 x86_64; do + for arch in i686 x86_64; do [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/any/${pkg}" done @@ -103,4 +105,32 @@ checkPackage() { [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/${arch}/${pkg}" bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" + + local pkgbase=$(getpkgbase "${FTP_BASE}/packages/arch/${arch}/${pkg}") + svn up -q "${TMP}/svn-packages-copy/${pkgbase}" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" +} + +checkRemovedPackage() { + local repo=$1 + local pkgbase=$2 + local arch=$3 + + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}.db.tar.gz" + + svn up -q "${TMP}/svn-packages-copy/${pkgbase}" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] && fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} should not exist" } + +checkRemovedAnyPackage() { + local repo=$1 + local pkgbase=$2 + local arch + + for arch in i686 x86_64; do + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}.db.tar.gz" + done + + svn up -q "${TMP}/svn-packages-copy/${pkgbase}" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] && fail "svn-packages-copy/${pkgbase}/repos/${repo}-any should not exist" +} \ No newline at end of file diff --git a/test/runTest b/test/runTest index 258a181..c53b63c 100755 --- a/test/runTest +++ b/test/runTest @@ -103,20 +103,14 @@ testRemovePackages() { done done - for arch in ${arches[@]}; do - [ -z "$(bsdtar -tf "${FTP_BASE}/extra/os/${arch}/extra.db.tar.gz" -O)" ] || fail "extra/os/${arch}/${repo}.db.tar.gz should be empty" - done - for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do - svn up -q "${TMP}/svn-packages-copy/${pkgbase}" - [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/extra-${arch}" ] && fail "svn-packages-copy/${pkgbase}/repos/extra-${arch} should not exist" + checkRemovedPackage extra ${pkgbase} ${arch} done done } testRemoveAnyPackages() { - local arches=('i686' 'x86_64') local pkgs=('pkg-any-a' 'pkg-any-b') local pkgbase @@ -130,15 +124,87 @@ testRemoveAnyPackages() { ../db-remove ${pkgbase} extra any done + for pkgbase in ${pkgs[@]}; do + checkRemovedAnyPackage extra ${pkgbase} + done +} + + +# +# db-move +# + +testMoveSimplePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage testing ${pkgbase} ${arch} + done + done + + ../db-update testing + + for arch in ${arches[@]}; do + ../db-move-draft pkg-simple-a testing extra ${arch} + done + for arch in ${arches[@]}; do - [ -z "$(bsdtar -tf "${FTP_BASE}/extra/os/${arch}/extra.db.tar.gz" -O)" ] || fail "extra/os/${arch}/${repo}.db.tar.gz should be empty" + checkPackage extra pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} + checkRemovedPackage testing pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} + + checkPackage testing pkg-simple-b-1-1-${arch}.pkg.tar.xz ${arch} done +} + +testMoveAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase for pkgbase in ${pkgs[@]}; do - svn up -q "${TMP}/svn-packages-copy/${pkgbase}" - [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/extra-any" ] && fail "svn-packages-copy/${pkgbase}/repos/extra-any should not exist" + releasePackage testing ${pkgbase} any done + + ../db-update testing + ../db-move-draft pkg-any-a testing extra any + + checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz + checkRemovedAnyPackage testing pkg-any-a + checkAnyPackage testing pkg-any-b-1-1-any.pkg.tar.xz } +testMoveSplitPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage testing ${pkgbase} ${arch} + done + done + + ../db-update testing + + for arch in ${arches[@]}; do + ../db-move-draft pkg-split-a testing extra ${arch} + done + + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/pkg-split-a"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + done + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/pkg-split-b"/*-${arch}.pkg.tar.*; do + checkPackage testing $(basename ${pkg}) ${arch} + done + done + + checkRemovedAnyPackage testing pkg-split-a +} . "${curdir}/lib/shunit2" -- cgit v1.2.3-54-g00ecf From 23d4669b8e330d131b2f78cd5858b30a07478c8a Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Aug 2010 00:33:46 +0200 Subject: Use package pool instead of $repo/os/any dirs --- db-move | 17 ++++++++--------- db-update | 16 +++++----------- test/lib/common.inc | 2 ++ 3 files changed, 15 insertions(+), 20 deletions(-) (limited to 'test/lib/common.inc') diff --git a/db-move b/db-move index 407027a..8609459 100755 --- a/db-move +++ b/db-move @@ -74,16 +74,15 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then _pkgfiles='' for i in ${pkgname[@]}; do - _pkgpath=$(getpkgfile "$ftppath_from/${_arch}/"$i-$pkgver-$pkgrel-$_arch$PKGEXT) - _pkgfile=$(basename "${_pkgpath}") - - # copy package to pool if needed - # TODO: can be removed once every package has benn moved to the package pool - if [ ! -f $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/$_pkgfile ]; then - cp $_pkgpath $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/ - fi - for _tarch in ${_tarches[@]}; do + _pkgpath=$(getpkgfile "$ftppath_from/${_tarch}/"$i-$pkgver-$pkgrel-$_arch$PKGEXT) + _pkgfile=$(basename "${_pkgpath}") + + # copy package to pool if needed + # TODO: can be removed once every package has been moved to the package pool + if [ ! -f $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/$_pkgfile ]; then + cp $_pkgpath $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/ + fi ln -s "../../../$(get_pkgpool_for_host)/${_arch}/${_pkgfile}" $ftppath_to/${_tarch}/ done diff --git a/db-update b/db-update index f05246b..9e641d2 100755 --- a/db-update +++ b/db-update @@ -223,7 +223,7 @@ for current_arch in ${ARCHES[@]}; do # if non empty, move all build dirs if [ $(/bin/ls "$WORKDIR/build/" 2>/dev/null | wc -l) != 0 ]; then if [ $(getpkgfiles "$WORKDIR/build/"*-$current_arch$PKGEXT 2>/dev/null | wc -l) != 0 ]; then - echo "Copying new files to '$ftppath'" + echo "Copying new files to '$poolpath' and symlinking" for f in "$WORKDIR/build/"*-$current_arch$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null if ! /bin/cp "$f" "$poolpath/"; then @@ -236,20 +236,14 @@ for current_arch in ${ARCHES[@]}; do done fi if [ $(getpkgfiles "$WORKDIR/build/"*-any$PKGEXT 2>/dev/null | wc -l) != 0 ]; then - echo "Copying new files to '$ftppath_any' and symlinking" + echo "Copying new files to '$poolpath_any' and symlinking" for f in "$WORKDIR/build/"*-any$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null fname="$(basename $f)" - if [ ! -f "$poolrel_any/$fname" ]; then - if ! /bin/cp "$f" "$poolpath_any/"; then - die "error: failure while copying files to $poolpath_any" - fi - fi - if [ ! -f "$ftppath_any/$fname" ]; then - if ! ln -s "$poolrel_any/$fname" "$ftppath_any/$fname"; then - die "error: failure symlinking $fname to $ftppath_any" - fi + if ! /bin/cp "$f" "$poolpath_any/"; then + die "error: failure while copying files to $poolpath_any" fi + if ! ln -s "$poolrel_any/$fname" "$ftppath/$fname"; then die "error: failure symlinking $fname to $ftppath" fi diff --git a/test/lib/common.inc b/test/lib/common.inc index 3ba715e..4080c38 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -91,6 +91,8 @@ checkAnyPackage() { [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" + + [ -f "${FTP_BASE}/${repo}/os/any/${pkg}" ] && fail "${repo}/os/any/${pkg} should not exist" } checkPackage() { -- cgit v1.2.3-54-g00ecf From 1db7071b222207d2d924a03a48d0745387f11c7b Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Aug 2010 01:26:11 +0200 Subject: add test for ftpdir-cleanup --- test/lib/common.inc | 3 +- test/runTest | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index 4080c38..dd3022e 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -16,7 +16,7 @@ oneTimeSetUp() { } oneTimeTearDown() { - find "${pkgdir}" -name '*.pkg.tar.*' -delete + rm -rf "${pkgdir}" } setUp() { @@ -54,6 +54,7 @@ setUp() { SOURCE_CLEANUP_DESTDIR="${TMP}/source-cleanup" STAGING="${TMP}/staging" TMPDIR="${TMP}/tmp" + CLEANUP_DRYRUN=false eot . "${curdir}/../config" } diff --git a/test/runTest b/test/runTest index 6a4f3de..7136508 100755 --- a/test/runTest +++ b/test/runTest @@ -25,6 +25,7 @@ testAddSimplePackages() { local arches=('i686' 'x86_64') local pkgs=('pkg-simple-a' 'pkg-simple-b') local pkgbase + local arch for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -61,6 +62,7 @@ testAddSplitPackages() { local pkgs=('pkg-split-a' 'pkg-split-b') local pkg local pkgbase + local arch for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -88,6 +90,7 @@ testRemovePackages() { local arches=('i686' 'x86_64') local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') local pkgbase + local arch for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -138,6 +141,7 @@ testMoveSimplePackages() { local arches=('i686' 'x86_64') local pkgs=('pkg-simple-a' 'pkg-simple-b') local pkgbase + local arch for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -180,6 +184,7 @@ testMoveSplitPackages() { local pkgs=('pkg-split-a' 'pkg-split-b') local pkg local pkgbase + local arch for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -207,4 +212,96 @@ testMoveSplitPackages() { checkRemovedAnyPackage testing pkg-split-a } + +# +# ftpdir-cleanup +# + +testCleanupSimplePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update extra + + for arch in ${arches[@]}; do + ../db-remove pkg-simple-a extra ${arch} + done + + ../cron-jobs/ftpdir-cleanup + + for arch in ${arches[@]}; do + local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" + [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg1}" ] && fail "packages/arch/${arch}/${pkg1} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" + + local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz" + checkPackage extra ${pkg2} ${arch} + done +} + +testCleanupAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + local arch='any' + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + + ../db-update extra + ../db-remove pkg-any-a extra any + ../cron-jobs/ftpdir-cleanup + + local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' + [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg1}" ] && fail "packages/arch/${arch}/${pkg1} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" + + local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz" + checkAnyPackage extra ${pkg2} +} + +testCleanupSplitPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update extra + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + ../db-remove pkg-split-a extra ${arch} + done + done + + ../cron-jobs/ftpdir-cleanup + + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do + [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] && fail "packages/arch/${arch}/${pkg} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] && fail "${repo}/os/${arch}/${pkg} found" + done + + for pkg in "${pkgdir}/${pkgs[1]}"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + done +} + + . "${curdir}/lib/shunit2" -- cgit v1.2.3-54-g00ecf From c117d9048ae591401a79037222da7bf7bda85705 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Aug 2010 03:44:17 +0200 Subject: Reduce verbosity Only inform of errors and processes that might take longer. --- db-move | 15 ++++++++------- db-remove | 21 +++++++++------------ db-update | 23 +++++++---------------- test/lib/common.inc | 4 +--- test/runTest | 14 +++++++------- 5 files changed, 32 insertions(+), 45 deletions(-) (limited to 'test/lib/common.inc') diff --git a/db-move b/db-move index 8609459..7dff563 100755 --- a/db-move +++ b/db-move @@ -55,22 +55,21 @@ repo_lock $repofrom $_arch || exit 1 /bin/mkdir -p "$WORKDIR" cd "$WORKDIR" -/usr/bin/svn checkout -N $SVNREPO checkout +/usr/bin/svn checkout -q -N $SVNREPO checkout >/dev/null cd checkout /usr/bin/svn up -q $packagebase if [ -d "$packagebase/repos/$svnrepo_from" ]; then . "$packagebase/repos/$svnrepo_from/$BUILDSCRIPT" + echo -n "Moving $packagebase from $repofrom to $repoto..." if [ -d "$packagebase/repos/$svnrepo_to" ]; then - echo " Removing existing package from subversion" /usr/bin/svn rm --force -q "$packagebase/repos/$svnrepo_to" /usr/bin/svn commit -q -m "$(basename $0): $packagebase removed by $(id -un) for move to $repoto" fi - echo " Moving svn entries" - /usr/bin/svn mv -r HEAD "$packagebase/repos/$svnrepo_from" "$packagebase/repos/$svnrepo_to" - /usr/bin/svn commit -m "$(basename $0): moved $packagebase from [$repofrom] to [$repoto] ($_arch)" + /usr/bin/svn mv -q -r HEAD "$packagebase/repos/$svnrepo_from" "$packagebase/repos/$svnrepo_to" + /usr/bin/svn commit -q -m "$(basename $0): moved $packagebase from [$repofrom] to [$repoto] ($_arch)" _pkgfiles='' for i in ${pkgname[@]}; do @@ -90,9 +89,11 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then done for _tarch in ${_tarches[@]}; do - /usr/bin/repo-add -q "$ftppath_to/${_tarch}/$repoto$DBEXT" ${_pkgfiles} || die "Error in repo-add $_pkgfiles" - /usr/bin/repo-remove -q "$ftppath_from/${_tarch}/$repofrom$DBEXT" ${pkgname[@]} || die "Error in repo-remove ${pkgname[@]}" + /usr/bin/repo-add -q "$ftppath_to/${_tarch}/$repoto$DBEXT" ${_pkgfiles} >/dev/null || die "Error in repo-add $_pkgfiles" + /usr/bin/repo-remove -q "$ftppath_from/${_tarch}/$repofrom$DBEXT" ${pkgname[@]} >/dev/null || die "Error in repo-remove ${pkgname[@]}" done + + echo 'done' else die "Error: $packagebase is not in repo $repofrom" fi diff --git a/db-remove b/db-remove index 0b77fc1..357e6c4 100755 --- a/db-remove +++ b/db-remove @@ -42,26 +42,21 @@ trap cleanup 0 repo_lock $reponame $_arch || exit 1 +echo -n "Removing $packagebase from $reponame..." /bin/mkdir -p "$WORKDIR" - - -echo "==> Removing package '$packagebase' from '$reponame'..." >&2 - cd "$WORKDIR" -/usr/bin/svn checkout -N $SVNREPO checkout +/usr/bin/svn checkout -q -N $SVNREPO checkout >/dev/null cd checkout /usr/bin/svn up -q $packagebase if [ -d "$packagebase/repos/$svnrepo" ]; then - echo " Removing from subversion" . "$packagebase/repos/$svnrepo/$BUILDSCRIPT" /usr/bin/svn rm --force -q "$packagebase/repos/$svnrepo" /usr/bin/svn commit -q -m "$(basename $0): $packagebase removed by $(id -un)" else echo " Warning: $packagebase not found in $svnrepo" - echo " Removing split packages is not supported" - echo " You need to specify each sub package instead" - pkgname=$packagebase + echo " Removing split packages is not yet supported" + exit 1 fi cd "$WORKDIR" @@ -82,14 +77,16 @@ for architecture in $arches; do exit 0 fi - echo " Removing from $reponame DB file ($architecture)" cd build/ - /usr/bin/repo-remove -q "$reponame$DBEXT" ${pkgname[@]} + /usr/bin/repo-remove -q "$reponame$DBEXT" ${pkgname[@]} >/dev/null /bin/mv "$reponame$DBEXT" "$ftppath/$architecture" - echo "Package files will be cleaned up automatically" cd .. done + +echo 'done' + cleanup + # vim: set ts=4 sw=4 noet ft=sh: diff --git a/db-update b/db-update index 9e641d2..057de39 100755 --- a/db-update +++ b/db-update @@ -74,6 +74,8 @@ die() { trap ctrl_c 2 trap cleanup 0 +echo -n "Updating $reponame..." + # Remove any package from $stagedir that is already in the FTP repository for current_arch in ${ARCHES[@]} any; do ftppath="$FTP_BASE/$reponame/os/$current_arch" @@ -97,9 +99,8 @@ cd "$WORKDIR" if [ -n "$ANYPKGS" ]; then pkgtotal=$(echo "$ANYPKGS" | wc -w) - echo "==> Processing $pkgtotal new/updated arch-independent packages for '$reponame'..." >&2 - /usr/bin/svn checkout -N $SVNREPO checkout + /usr/bin/svn checkout -q -N $SVNREPO checkout >/dev/null cd checkout to_add_any="" for pkg in $ANYPKGS; do @@ -107,11 +108,9 @@ if [ -n "$ANYPKGS" ]; then _pkgname="$(getpkgname $pkg)" _pkgbase="$(getpkgbase $pkg)" svnrepo="$reponame-any" - echo " Validating package arch (any) $_pkgname" if ! check_pkg_arch "$pkg" "any"; then echo " ERROR: $_pkgfile is not architecture independent!" else - echo " Checking SVN for $_pkgbase" /usr/bin/svn up -q $_pkgbase if [ -d "$_pkgbase/repos/$svnrepo" ]; then . "$_pkgbase/repos/$svnrepo/$BUILDSCRIPT" @@ -156,8 +155,6 @@ for current_arch in ${ARCHES[@]}; do /bin/cp "$ftppath/$reponame$DBEXT" build/$reponame-$current_arch$DBEXT fi - echo "Updating DB for $svnrepo" - to_add="" if [ -d "$stagedir" ]; then ADDPKGS="$(getpkgfiles $stagedir/*-${current_arch}$PKGEXT 2>/dev/null)" @@ -165,17 +162,14 @@ for current_arch in ${ARCHES[@]}; do if [ -n "$ADDPKGS" -o -n "$ANYPKGS" ]; then - echo "==> Copying DB file from '$reponame'..." >&2 - if [ -f "$ftppath/$reponame$DBEXT" ]; then /bin/cp "$ftppath/$reponame$DBEXT" build/$reponame-$current_arch$DBEXT fi pkgtotal=$(echo "$ADDPKGS $ANYPKGS" | wc -w) - echo "==> Processing $pkgtotal new/updated packages for repository '$reponame'..." >&2 cd "$WORKDIR" - /usr/bin/svn checkout -N $SVNREPO checkout + /usr/bin/svn checkout -N $SVNREPO checkout >/dev/null cd checkout if [ -n "$ADDPKGS" ]; then @@ -184,11 +178,9 @@ for current_arch in ${ARCHES[@]}; do _pkgname="$(getpkgname $pkg)" _pkgbase="$(getpkgbase $pkg)" - echo " Validating package arch ($current_arch) $_pkgname" if ! check_pkg_arch "$pkg" "$current_arch"; then echo " ERROR: $_pkgfile was built for the wrong architecture" else - echo " Checking SVN for $_pkgbase" /usr/bin/svn up -q $_pkgbase if [ -d "$_pkgbase/repos/$svnrepo" ]; then . "$_pkgbase/repos/$svnrepo/$BUILDSCRIPT" @@ -211,7 +203,7 @@ for current_arch in ${ARCHES[@]}; do pkgs="" for pkg in $to_add $to_add_any; do pkgs="$pkgs $(basename $pkg)"; done - /usr/bin/repo-add -q "$reponame-$current_arch$DBEXT" $pkgs + /usr/bin/repo-add -q "$reponame-$current_arch$DBEXT" $pkgs >/dev/null else rm -f "build/$reponame-$current_arch$DBEXT" echo "Errors found when adding packages" @@ -223,7 +215,6 @@ for current_arch in ${ARCHES[@]}; do # if non empty, move all build dirs if [ $(/bin/ls "$WORKDIR/build/" 2>/dev/null | wc -l) != 0 ]; then if [ $(getpkgfiles "$WORKDIR/build/"*-$current_arch$PKGEXT 2>/dev/null | wc -l) != 0 ]; then - echo "Copying new files to '$poolpath' and symlinking" for f in "$WORKDIR/build/"*-$current_arch$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null if ! /bin/cp "$f" "$poolpath/"; then @@ -236,7 +227,6 @@ for current_arch in ${ARCHES[@]}; do done fi if [ $(getpkgfiles "$WORKDIR/build/"*-any$PKGEXT 2>/dev/null | wc -l) != 0 ]; then - echo "Copying new files to '$poolpath_any' and symlinking" for f in "$WORKDIR/build/"*-any$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null fname="$(basename $f)" @@ -257,7 +247,6 @@ for current_arch in ${ARCHES[@]}; do fi if [ -n "$to_add" ]; then - echo "Cleaning staging dir" /bin/rm $to_add fi @@ -268,6 +257,8 @@ if [ -n "$to_add_any" ]; then /bin/rm $to_add_any fi +echo 'done' + trap '' 0 2 rm -rf $WORKDIR # vim: set ts=4 sw=4 noet ft=sh: diff --git a/test/lib/common.inc b/test/lib/common.inc index dd3022e..2d2b612 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -60,10 +60,8 @@ eot } tearDown() { - echo -n 'Cleaning up...' rm -rf "${TMP}" rm -f "${curdir}/../config.local" - echo 'done' echo } @@ -73,7 +71,7 @@ releasePackage() { local arch=$3 pushd "${TMP}/svn-packages-copy"/${pkgbase}/trunk/ >/dev/null - archrelease ${repo}-${arch} >/dev/null + archrelease ${repo}-${arch} >/dev/null 2&>1 popd >/dev/null cp "${pkgdir}/${pkgbase}"/*.pkg.tar.* "${STAGING}"/${repo}/ } diff --git a/test/runTest b/test/runTest index d453493..b24b7ea 100755 --- a/test/runTest +++ b/test/runTest @@ -235,7 +235,7 @@ testCleanupSimplePackages() { ../db-remove pkg-simple-a extra ${arch} done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for arch in ${arches[@]}; do local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" @@ -258,7 +258,7 @@ testCleanupAnyPackages() { ../db-update extra ../db-remove pkg-any-a extra any - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg1}" ] && fail "packages/arch/${arch}/${pkg1} found" @@ -289,7 +289,7 @@ testCleanupSplitPackages() { done done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for arch in ${arches[@]}; do for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do @@ -333,7 +333,7 @@ testMovePackagesWithoutPool() { done done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -341,7 +341,7 @@ testMovePackagesWithoutPool() { done done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for pkgbase in ${pkgs[@]}; do for arch in ${arches[@]}; do @@ -374,13 +374,13 @@ testMoveAnyPackagesWithoutPool() { done done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for pkgbase in ${pkgs[@]}; do ../db-move ${pkgbase} testing extra any done - ../cron-jobs/ftpdir-cleanup + ../cron-jobs/ftpdir-cleanup >/dev/null for pkgbase in ${pkgs[@]}; do for pkg in "${pkgdir}/${pkgbase}"/*-any.pkg.tar.*; do -- cgit v1.2.3-54-g00ecf From ff0745c50507f0cea48dbf97b8f55734698e3c13 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Aug 2010 12:47:06 +0200 Subject: Prepare for variable db file compression --- db-update | 1 + test/lib/common.inc | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test/lib/common.inc') diff --git a/db-update b/db-update index a08bee2..d08c96d 100755 --- a/db-update +++ b/db-update @@ -222,6 +222,7 @@ for current_arch in ${ARCHES[@]}; do if ! /bin/cp "$WORKDIR/build/$reponame-$current_arch$DBEXT" "$ftppath/$reponame$DBEXT"; then die "failed to move repository $reponame-$current_arch". fi + ln -sf "$reponame$DBEXT" "$ftppath/$reponame${DBEXT%.tar.*}" else echo "Nothing to copy, no work done" fi diff --git a/test/lib/common.inc b/test/lib/common.inc index 2d2b612..d28017d 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -89,7 +89,7 @@ checkAnyPackage() { done [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" [ -f "${FTP_BASE}/${repo}/os/any/${pkg}" ] && fail "${repo}/os/any/${pkg} should not exist" } @@ -105,7 +105,7 @@ checkPackage() { [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/${arch}/${pkg}" - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}.db.tar.gz" + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" local pkgbase=$(getpkgbase "${FTP_BASE}/packages/arch/${arch}/${pkg}") svn up -q "${TMP}/svn-packages-copy/${pkgbase}" @@ -117,7 +117,7 @@ checkRemovedPackage() { local pkgbase=$2 local arch=$3 - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}.db.tar.gz" + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" svn up -q "${TMP}/svn-packages-copy/${pkgbase}" [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] && fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} should not exist" @@ -129,7 +129,7 @@ checkRemovedAnyPackage() { local arch for arch in i686 x86_64; do - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}.db.tar.gz" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}.db.tar.gz" + bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" done svn up -q "${TMP}/svn-packages-copy/${pkgbase}" -- cgit v1.2.3-54-g00ecf From 9eb1cd7b9403533c4b60ecfbbbf00a08c211059a Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Aug 2010 15:03:27 +0200 Subject: Move common function to db-functions db-functions now sets an individual $WORKDIR and implements trap functinos that remove locks on exit or error. There are new functions to lock and unlock the running script. misc-scripts/ftpdir-cleanup was renamed to ftpdir-cleanup-repo as the cron-job had the same name. Script names have to be unique when using db-functions. --- cron-jobs/ftpdir-cleanup | 26 +---- db-functions | 74 +++++++++++-- db-move | 25 +---- db-remove | 23 +---- db-update | 22 ---- misc-scripts/ftpdir-cleanup | 218 --------------------------------------- misc-scripts/ftpdir-cleanup-repo | 207 +++++++++++++++++++++++++++++++++++++ misc-scripts/make-sourceball | 21 +--- misc-scripts/sourceballs-cleanup | 27 +---- test/lib/common.inc | 6 +- testing2x | 16 --- 11 files changed, 291 insertions(+), 374 deletions(-) delete mode 100755 misc-scripts/ftpdir-cleanup create mode 100755 misc-scripts/ftpdir-cleanup-repo (limited to 'test/lib/common.inc') diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 546afd9..f5e401a 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -5,34 +5,14 @@ repos="$(get_repos_for_host)" -LOCKFILE="/tmp/.ftpdircleanup.lock" - -cleanup () { - rm -f "$LOCKFILE" - exit 0 -} - -ctrl_c() { - cleanup -} - -if [ -f "$LOCKFILE" ]; then - owner="$(/usr/bin/stat -c %U $LOCKFILE)" - echo "error: ftp cleanup is already in progress (started by $owner)" - exit 1 -fi - -trap cleanup 0 -trap ctrl_c 2 - -/bin/touch "$LOCKFILE" +script_lock #adjust the nice level to run at a lower priority /usr/bin/renice +10 -p $$ > /dev/null repopaths='' for repo in $repos; do - $(dirname $0)/../misc-scripts/ftpdir-cleanup $repo + $(dirname $0)/../misc-scripts/ftpdir-cleanup-repo $repo repopaths="${repopaths} ${FTP_BASE}/${repo}/os/" done @@ -60,4 +40,4 @@ if [ -n "$to_cleanup" ]; then mv $to_cleanup "$CLEANUP_DESTDIR" fi -cleanup +script_unlock diff --git a/db-functions b/db-functions index caaf9a0..36ffb07 100644 --- a/db-functions +++ b/db-functions @@ -1,10 +1,6 @@ #!/bin/bash -# set up general environment -WORKDIR=$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX) - # Useful functions - UMASK="" set_umask () { [ "$UMASK" == "" ] && UMASK="$(umask)" @@ -16,8 +12,73 @@ restore_umask () { umask $UMASK >/dev/null } +# set up general environment +WORKDIR=$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX) +LOCKS=() + +script_lock() { + local LOCKDIR="$TMPDIR/.scriptlock.$(basename $0)" + if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then + local _owner="$(/usr/bin/stat -c %U $LOCKDIR)" + echo "Error: Script $(basename $0) is already locked by $_owner." >&2 + exit 1 + else + set_umask + return 0 + fi +} + +script_unlock() { + local LOCKDIR="$TMPDIR/.scriptlock.$(basename $0)" + if [ ! -d "$LOCKDIR" ]; then + echo "Warning: Script $(basename $0) was not locked!" >&2 + restore_umask + return 1 + else + rmdir "$LOCKDIR" + restore_umask + return 0 + fi +} + +cleanup() { + local l + local repo + local arch + + trap - EXIT INT QUIT TERM + for l in ${LOCKS[@]}; do + repo=${l%.*} + arch=${l#*.} + if [ -d "$TMPDIR/.repolock.$repo.$arch" ]; then + echo "Removing left over lock from $repo/$arch" >&2 + repo_unlock $repo $_arch + fi + done + if [ -d "$TMPDIR/.scriptlock.$(basename $0)" ]; then + echo "Removing left over lock from $(basename $0)" >&2 + script_unlock + fi + rm -rf "$WORKDIR" + [ "$1" ] && exit $1 +} + +abort() { + echo 'Aborting...' >&2 + cleanup 0 +} + +die() { + echo "$*" >&2 + cleanup 1 +} + +trap abort INT QUIT TERM +trap cleanup EXIT + + repo_lock () { #repo_lock [timeout] - LOCKDIR="$TMPDIR/.repolock.$1.$2" + local LOCKDIR="$TMPDIR/.repolock.$1.$2" local _count local _trial local _timeout @@ -39,6 +100,7 @@ repo_lock () { #repo_lock [timeout] _owner="$(/usr/bin/stat -c %U $LOCKDIR)" echo "warning: Repo $1-$2 is already locked by $_owner. Retrying in $LOCK_DELAY seconds..." >&2 else + LOCKS[${#LOCKS[*]}]="$1.$2" set_umask return 0 fi @@ -51,7 +113,7 @@ repo_lock () { #repo_lock [timeout] } repo_unlock () { #repo_unlock - LOCKDIR="$TMPDIR/.repolock.$1.$2" + local LOCKDIR="$TMPDIR/.repolock.$1.$2" if [ ! -d "$LOCKDIR" ]; then echo "warning: Repo lock $1-$2 was not locked!" >&2 restore_umask diff --git a/db-move b/db-move index 8b15831..b846e79 100755 --- a/db-move +++ b/db-move @@ -23,28 +23,6 @@ ftppath_to="$FTP_BASE/$repoto/os/" svnrepo_from="$repofrom-$_arch" svnrepo_to="$repoto-$_arch" -cleanup() { - trap '' 0 2 - # unlock - repo_unlock $repoto $_arch - repo_unlock $repofrom $_arch - rm -rf "$WORKDIR" - [ "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} - -die() { - echo "$*" >&2 - cleanup 1 -} - -trap ctrl_c 2 -trap cleanup 0 - repo_lock $repoto $_arch || exit 1 repo_lock $repofrom $_arch || exit 1 @@ -91,3 +69,6 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then else die "Error: $packagebase is not in repo $repofrom" fi + +repo_unlock $repoto $_arch || exit 1 +repo_unlock $repofrom $_arch || exit 1 diff --git a/db-remove b/db-remove index 0da9e75..5d61c97 100755 --- a/db-remove +++ b/db-remove @@ -15,27 +15,6 @@ _arch="$3" ftppath="$FTP_BASE/$reponame/os" svnrepo="$reponame-$_arch" -cleanup() { - trap '' 0 2 - # unlock - repo_unlock $reponame $_arch - rm -rf "$WORKDIR" - [ "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} - -die() { - echo "$*" >&2 - cleanup 1 -} - -trap ctrl_c 2 -trap cleanup 0 - repo_lock $reponame $_arch || exit 1 echo -n "Removing $packagebase from $reponame..." @@ -71,4 +50,6 @@ done echo 'done' +repo_unlock $reponame $_arch || exit 1 + # vim: set ts=4 sw=4 noet ft=sh: diff --git a/db-update b/db-update index e53aee8..f971a6f 100755 --- a/db-update +++ b/db-update @@ -33,26 +33,6 @@ if [ ! -d $stagedir ]; then exit 1 fi -cleanup() { - trap '' 0 2 - repo_unlock $reponame $current_arch - rm -rf "$WORKDIR" - [ "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 1 -} - -die() { - echo "$*" >&2 - cleanup 1 -} - -trap ctrl_c 2 -trap cleanup 0 - echo -n "Updating $reponame..." # Remove any package from $stagedir that is already in the FTP repository @@ -238,6 +218,4 @@ fi echo 'done' -trap '' 0 2 -rm -rf $WORKDIR # vim: set ts=4 sw=4 noet ft=sh: diff --git a/misc-scripts/ftpdir-cleanup b/misc-scripts/ftpdir-cleanup deleted file mode 100755 index ac17a8d..0000000 --- a/misc-scripts/ftpdir-cleanup +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/bash - -if [ $# -ne 1 ]; then - echo "usage: $(basename $0) " - exit 1 -fi - -reponame=$1 - -############################################################ - -. "$(dirname $0)/../db-functions" -. "$(dirname $0)/../config" - -cleanup() { - trap '' 2 15 - for arch in ${ARCHES[@]}; do - repo_unlock $reponame $arch - done - exit 1 -} - -clean_pkgs () { - for pkg in "$@"; do - if [ -h "$pkg" ]; then - rm -f "$pkg" - else - mv "$pkg" "$CLEANUP_DESTDIR" - fi - done -} - -trap cleanup 2 -trap cleanup 15 - -${CLEANUP_DRYRUN} && echo 'dry run mode is active' - -ftppath_base="$FTP_BASE/$reponame/os" - -for arch in ${ARCHES[@]}; do - - repo_lock $reponame $arch $LOCK_TIMEOUT || continue - - CLEANUP_TMPDIR=$(mktemp -d ${TMPDIR}/cleanup-XXXXXX) || exit 1 - ftppath="$ftppath_base/$arch" - MISSINGFILES="" - DELETEFILES="" - DELETESYMLINKS="" - EXTRAFILES="" - - if [ ! -d "$ftppath" ]; then - echo "FTP path '$ftppath' does not exist" - exit 1 - fi - - if ! cd "${CLEANUP_TMPDIR}" ; then - echo "Failed to cd to ${CLEANUP_TMPDIR}" - exit 1 - fi - - if [ ! -f "$ftppath/$reponame$DBEXT" ]; then - echo "" - echo "WARNING: The file \"$ftppath/$reponame$DBEXT\" could not be found, skipping." - echo "" - repo_unlock $reponame $arch - continue - fi - - if ! bsdtar xf "$ftppath/$reponame$DBEXT"; then - echo "" - echo "ERROR: Command failed: bsdtar xf \"$ftppath/$reponame$DBEXT\"" - exit 1 - fi - - cd "$ftppath" - - for pkg in $CLEANUP_TMPDIR/*; do - [ -f "${pkg}" ] || continue - filename=$(grep -A1 '^%FILENAME%$' "${pkg}/desc" | tail -n1) - - if [ ! -e "${filename}" ]; then - MISSINGFILES="${MISSINGFILES} ${filename}" - else - pkgname="$(getpkgname ${filename})" - for otherfile in ${pkgname}-*; do - if [ "${otherfile}" != "${filename}" -a "${pkgname}" = "$(getpkgname ${otherfile})" ]; then - if [ -h "${otherfile}" ]; then - DELETESYMLINKS="${DELETESYMLINKS} ${otherfile}" - else - DELETEFILES="${DELETEFILES} ${otherfile}" - fi - fi - done - fi - done - - for pkg in *$PKGEXT; do - if [ ! -e "$pkg" ]; then - continue - fi - pkgname="$(getpkgname $pkg)" - for p in ${CLEANUP_TMPDIR}/${pkgname}-*; do - [ ! -d "${p}" ] || continue 2 - dbpkgname=$(grep -A1 '^%FILENAME%$' "${p}/desc" 2>/dev/null| tail -n1) - if [ "${dbpkgname}" = "${pkgname}" ]; then - continue 2 - fi - done - EXTRAFILES="$EXTRAFILES $pkg" - done - - rm -rf ${CLEANUP_TMPDIR} - - # Do a quick check to see if a missing ARCHINDEPFILE is in the any dir - # If it is, and the file is MISSING, restore it - missfiles="$MISSINGFILES" - MISSINGFILES="" - for mf in $missfiles; do - if [ -e "${ftppath_base}/any/${mf}" ]; then - echo "Restoring missing 'any' symlink: ${mf}" - ${CLEANUP_DRYRUN} || ln -s "../any/${mf}" "${ftppath}" - else - MISSINGFILES="${MISSINGFILES} ${mf}" - fi - done - - repo_unlock $reponame $arch - - #Make sure we've done *something* before outputting anything - if [ -z "$DELETEFILES$DELETESYMLINKS$MISSINGFILES$EXTRAFILES" ]; then - continue - fi - - echo "Scan complete for $reponame ($arch) at ${ftppath}" - - if [ -n "$DELETEFILES" ]; then - echo " The following files are out of date" - for f in $DELETEFILES; do - echo " $f" - done - echo "" - fi - - if [ -n "$DELETESYMLINKS" ]; then - echo " The following symlinks are out of date" - echo " They will be deleted" - for f in $DELETESYMLINKS; do - echo " $f" - done - echo "" - fi - - if [ -n "$MISSINGFILES" ]; then - echo " The following files are missing in the repo" - for f in $MISSINGFILES; do - echo " $f" - done - echo "" - fi - - if [ -n "$EXTRAFILES" ]; then - echo " The following files are in the repo but not the db" - for f in $EXTRAFILES; do - echo " $f" - done - fi - - if [ -n "${DELETEFILES}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${DELETEFILES} - echo "" - fi - - if [ -n "${DELETESYMLINKS}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${DELETESYMLINKS} - echo "" - fi - - if [ -n "${EXTRAFILES}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${EXTRAFILES} - echo "" - fi - -done - -ARCHINDEPFILES="" - -if [ -d "$ftppath_base/any" ]; then - cd "$ftppath_base/any" - for pkg in *$PKGEXT; do - [ -f "$pkg" ] || continue # in case we get a file named "*.pkg.tar.gz" - found=0 - #check for any existing symlinks - for arch in ${ARCHES[@]}; do - if [ -h "$ftppath_base/$arch/$pkg" ]; then - found=1 - break - fi - done - if [ $found -eq 0 ]; then - # We found no symlinks to this, delete it - ARCHINDEPFILES="$ARCHINDEPFILES $pkg" - fi - done -fi - -if [ -n "$ARCHINDEPFILES" ]; then - echo " The following architecture independent packages" - echo " are not symlinked in the architecture repositories." - for f in $ARCHINDEPFILES; do - echo " $f" - done -fi - -if [ -d "$ftppath_base/any" -a -n "${ARCHINDEPFILES}" ]; then - cd "$ftppath_base/any" - ${CLEANUP_DRYRUN} || clean_pkgs ${ARCHINDEPFILES} - echo "" -fi diff --git a/misc-scripts/ftpdir-cleanup-repo b/misc-scripts/ftpdir-cleanup-repo new file mode 100755 index 0000000..12f726c --- /dev/null +++ b/misc-scripts/ftpdir-cleanup-repo @@ -0,0 +1,207 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo "usage: $(basename $0) " + exit 1 +fi + +reponame=$1 + +############################################################ + +. "$(dirname $0)/../db-functions" +. "$(dirname $0)/../config" + +clean_pkgs () { + for pkg in "$@"; do + if [ -h "$pkg" ]; then + rm -f "$pkg" + else + mv "$pkg" "$CLEANUP_DESTDIR" + fi + done +} + +${CLEANUP_DRYRUN} && echo 'dry run mode is active' + +ftppath_base="$FTP_BASE/$reponame/os" + +for arch in ${ARCHES[@]}; do + + repo_lock $reponame $arch $LOCK_TIMEOUT || continue + + CLEANUP_TMPDIR=$(mktemp -d ${WORKDIR}/cleanup-XXXXXX) || exit 1 + ftppath="$ftppath_base/$arch" + MISSINGFILES="" + DELETEFILES="" + DELETESYMLINKS="" + EXTRAFILES="" + + if [ ! -d "$ftppath" ]; then + echo "FTP path '$ftppath' does not exist" + exit 1 + fi + + if ! cd "${CLEANUP_TMPDIR}" ; then + echo "Failed to cd to ${CLEANUP_TMPDIR}" + exit 1 + fi + + if [ ! -f "$ftppath/$reponame$DBEXT" ]; then + echo "" + echo "WARNING: The file \"$ftppath/$reponame$DBEXT\" could not be found, skipping." + echo "" + repo_unlock $reponame $arch + continue + fi + + if ! bsdtar xf "$ftppath/$reponame$DBEXT"; then + echo "" + echo "ERROR: Command failed: bsdtar xf \"$ftppath/$reponame$DBEXT\"" + exit 1 + fi + + cd "$ftppath" + + for pkg in $CLEANUP_TMPDIR/*; do + [ -f "${pkg}" ] || continue + filename=$(grep -A1 '^%FILENAME%$' "${pkg}/desc" | tail -n1) + + if [ ! -e "${filename}" ]; then + MISSINGFILES="${MISSINGFILES} ${filename}" + else + pkgname="$(getpkgname ${filename})" + for otherfile in ${pkgname}-*; do + if [ "${otherfile}" != "${filename}" -a "${pkgname}" = "$(getpkgname ${otherfile})" ]; then + if [ -h "${otherfile}" ]; then + DELETESYMLINKS="${DELETESYMLINKS} ${otherfile}" + else + DELETEFILES="${DELETEFILES} ${otherfile}" + fi + fi + done + fi + done + + for pkg in *$PKGEXT; do + if [ ! -e "$pkg" ]; then + continue + fi + pkgname="$(getpkgname $pkg)" + for p in ${CLEANUP_TMPDIR}/${pkgname}-*; do + [ ! -d "${p}" ] || continue 2 + dbpkgname=$(grep -A1 '^%FILENAME%$' "${p}/desc" 2>/dev/null| tail -n1) + if [ "${dbpkgname}" = "${pkgname}" ]; then + continue 2 + fi + done + EXTRAFILES="$EXTRAFILES $pkg" + done + + rm -rf ${CLEANUP_TMPDIR} + + # Do a quick check to see if a missing ARCHINDEPFILE is in the any dir + # If it is, and the file is MISSING, restore it + missfiles="$MISSINGFILES" + MISSINGFILES="" + for mf in $missfiles; do + if [ -e "${ftppath_base}/any/${mf}" ]; then + echo "Restoring missing 'any' symlink: ${mf}" + ${CLEANUP_DRYRUN} || ln -s "../any/${mf}" "${ftppath}" + else + MISSINGFILES="${MISSINGFILES} ${mf}" + fi + done + + repo_unlock $reponame $arch + + #Make sure we've done *something* before outputting anything + if [ -z "$DELETEFILES$DELETESYMLINKS$MISSINGFILES$EXTRAFILES" ]; then + continue + fi + + echo "Scan complete for $reponame ($arch) at ${ftppath}" + + if [ -n "$DELETEFILES" ]; then + echo " The following files are out of date" + for f in $DELETEFILES; do + echo " $f" + done + echo "" + fi + + if [ -n "$DELETESYMLINKS" ]; then + echo " The following symlinks are out of date" + echo " They will be deleted" + for f in $DELETESYMLINKS; do + echo " $f" + done + echo "" + fi + + if [ -n "$MISSINGFILES" ]; then + echo " The following files are missing in the repo" + for f in $MISSINGFILES; do + echo " $f" + done + echo "" + fi + + if [ -n "$EXTRAFILES" ]; then + echo " The following files are in the repo but not the db" + for f in $EXTRAFILES; do + echo " $f" + done + fi + + if [ -n "${DELETEFILES}" ]; then + ${CLEANUP_DRYRUN} || clean_pkgs ${DELETEFILES} + echo "" + fi + + if [ -n "${DELETESYMLINKS}" ]; then + ${CLEANUP_DRYRUN} || clean_pkgs ${DELETESYMLINKS} + echo "" + fi + + if [ -n "${EXTRAFILES}" ]; then + ${CLEANUP_DRYRUN} || clean_pkgs ${EXTRAFILES} + echo "" + fi + +done + +ARCHINDEPFILES="" + +if [ -d "$ftppath_base/any" ]; then + cd "$ftppath_base/any" + for pkg in *$PKGEXT; do + [ -f "$pkg" ] || continue # in case we get a file named "*.pkg.tar.gz" + found=0 + #check for any existing symlinks + for arch in ${ARCHES[@]}; do + if [ -h "$ftppath_base/$arch/$pkg" ]; then + found=1 + break + fi + done + if [ $found -eq 0 ]; then + # We found no symlinks to this, delete it + ARCHINDEPFILES="$ARCHINDEPFILES $pkg" + fi + done +fi + +if [ -n "$ARCHINDEPFILES" ]; then + echo " The following architecture independent packages" + echo " are not symlinked in the architecture repositories." + for f in $ARCHINDEPFILES; do + echo " $f" + done +fi + +if [ -d "$ftppath_base/any" -a -n "${ARCHINDEPFILES}" ]; then + cd "$ftppath_base/any" + ${CLEANUP_DRYRUN} || clean_pkgs ${ARCHINDEPFILES} + echo "" +fi diff --git a/misc-scripts/make-sourceball b/misc-scripts/make-sourceball index e216356..6e57385 100755 --- a/misc-scripts/make-sourceball +++ b/misc-scripts/make-sourceball @@ -22,21 +22,7 @@ _arch="$3" srcpath="$FTP_BASE/sources/" logpath="/var/log/sourceballs/" -cleanup() { - restore_umask - rm -rf "$WORKDIR" - [ "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} - -die() { - echo -e "$*" >&2 - cleanup 1 -} +script_lock create_srcpackage() { if [ -d "$1" ]; then @@ -71,9 +57,6 @@ create_srcpackage() { fi } -trap ctrl_c 2 -trap cleanup 0 1 - set_umask /bin/mkdir -p "$logpath" cd "$WORKDIR" @@ -91,3 +74,5 @@ else die "\tPackage '$packagename' does not exist in repo '$reponame-$_arch'" fi fi + +script_unlock diff --git a/misc-scripts/sourceballs-cleanup b/misc-scripts/sourceballs-cleanup index c87a888..e058c38 100755 --- a/misc-scripts/sourceballs-cleanup +++ b/misc-scripts/sourceballs-cleanup @@ -6,19 +6,7 @@ srcpath="$FTP_BASE/sources/" logfile="$srcpath/cleanup.txt" -LOCKFILE="/tmp/.sourceball-cleanup.lock" - -cleanup () { - restore_umask - rm -rf "$WORKDIR" - rm -f "$LOCKFILE" - exit 0 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} +script_lock remove_old() { if [ -d "$1" ]; then @@ -52,17 +40,6 @@ remove_old() { fi } -if [ -f "$LOCKFILE" ]; then - owner="$(/usr/bin/stat -c %U $LOCKFILE)" - echo "error: source tarball generation is already in progress (started by $owner)" - exit 1 -fi - -trap cleanup 0 -trap ctrl_c 2 - -/bin/touch "$LOCKFILE" - #adjust the nice level to run at a lower priority /usr/bin/renice +10 -p $$ > /dev/null @@ -91,4 +68,4 @@ for sourceball in "$srcpath"/*$SRCEXT; do fi done -cleanup 0 +script_unlock diff --git a/test/lib/common.inc b/test/lib/common.inc index d28017d..ba5be9f 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -7,8 +7,8 @@ oneTimeSetUp() { echo -n 'Building packages...' for p in "${pkgdir}"/*; do pushd $p >/dev/null - linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || exit 1 - [ -f *-any.pkg.tar.* ] || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || exit 1 + linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || die 'makepkg failed' + [ -f *-any.pkg.tar.* ] || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || die 'makepkg failed' popd >/dev/null done echo 'done' @@ -23,7 +23,7 @@ setUp() { local p local pkg - [ -f "${curdir}/../config.local" ] && exit 1 + [ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #echo "Using ${TMP}" diff --git a/testing2x b/testing2x index e9fbeaa..bf48be6 100755 --- a/testing2x +++ b/testing2x @@ -12,20 +12,6 @@ case "$0" in ;; esac -cleanup() { - trap '' 0 2 - rm -rf "${WORKDIR}" - [ -n "$1" ] && exit $1 -} - -ctrl_c() { - echo "Interrupted" >&2 - cleanup 0 -} - -trap ctrl_c 2 -trap cleanup 0 - cd "${WORKDIR}" /usr/bin/svn checkout -N $SVNREPO checkout cd checkout @@ -49,5 +35,3 @@ for pkg in $*; do echo "===> Warning: ${pkg} is not in testing-${_arch}" fi done - -cleanup -- cgit v1.2.3-54-g00ecf From af4f86808e8cd45cc171f55a1ec15bf30d858a0d Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Tue, 10 Aug 2010 21:40:24 +0200 Subject: Use more consitent naming for package pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are no longer architecture-specific subdirs and the structure was switch to this: ftp └── pool ├── community └── packages packages contains all packages from core, extra and testing; this naming is in sync with the svn repo naming: svn-packages and svn-community --- cron-jobs/adjust-permissions | 8 ++++---- cron-jobs/ftpdir-cleanup | 20 +++++++++----------- db-functions | 4 ++-- db-move | 8 ++++---- db-update | 12 +++++------- test/lib/common.inc | 13 +++++++------ test/runTest | 10 +++++----- 7 files changed, 36 insertions(+), 39 deletions(-) (limited to 'test/lib/common.inc') diff --git a/cron-jobs/adjust-permissions b/cron-jobs/adjust-permissions index c21af0c..c28ca7c 100755 --- a/cron-jobs/adjust-permissions +++ b/cron-jobs/adjust-permissions @@ -17,9 +17,9 @@ get_dir_owner() { echo "root:tusers" ;; community-testing) echo "root:tusers" ;; - packages/arch) + pool/packages) echo "ftp:ftp-extra" ;; - packages/community) + pool/community) echo "root:tusers" ;; esac } @@ -35,8 +35,8 @@ for d in $(get_repos_for_host); do done for p in $(get_pkgpool_for_host); do owner="$(get_dir_owner $p)" - /bin/chown -R $owner $p/{any,i686,x86_64} - /bin/chmod -R g+w $p/{any,i686,x86_64} + /bin/chown $owner $p + /bin/chmod g+w $p done /bin/chmod 555 $FTP_BASE popd >/dev/null diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index f5e401a..7668ab5 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -17,18 +17,16 @@ for repo in $repos; do done to_cleanup="" -for _arch in any ${ARCHES[@]}; do - poolpath="$FTP_BASE/$(get_pkgpool_for_host)/$_arch/" - pushd $poolpath >/dev/null - for pkg in *$PKGEXT; do - [ -f "$pkg" ] || continue # in case we get a file named "*.pkg.tar.gz" - LINKS="$(/usr/bin/find $repopaths -type l -name "$pkg" 2>/dev/null)" - if [ -z "$LINKS" ]; then - to_cleanup="$to_cleanup $poolpath/$pkg" - fi - done - popd >/dev/null +poolpath="$FTP_BASE/$(get_pkgpool_for_host)/" +pushd $poolpath >/dev/null +for pkg in *$PKGEXT; do +[ -f "$pkg" ] || continue # in case we get a file named "*.pkg.tar.gz" +LINKS="$(/usr/bin/find $repopaths -type l -name "$pkg" 2>/dev/null)" +if [ -z "$LINKS" ]; then + to_cleanup="$to_cleanup $poolpath/$pkg" +fi done +popd >/dev/null if [ -n "$to_cleanup" ]; then echo " The following packages are no longer in any repo" diff --git a/db-functions b/db-functions index 9abb694..c4fc8f3 100644 --- a/db-functions +++ b/db-functions @@ -228,9 +228,9 @@ get_repos_for_host() { get_pkgpool_for_host() { if [ "$(hostname)" = "sigurd" ]; then - echo "packages/community" + echo "pool/community" else - echo "packages/arch" + echo "pool/packages" fi } diff --git a/db-move b/db-move index bbe7ff7..d18a4fa 100755 --- a/db-move +++ b/db-move @@ -53,13 +53,13 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then # copy package to pool if needed # TODO: can be removed once every package has been moved to the package pool - if [ ! -f $FTP_BASE/$(get_pkgpool_for_host)/${arch}/$pkgfile ]; then - cp $pkgpath $FTP_BASE/$(get_pkgpool_for_host)/${arch}/ + if [ ! -f $FTP_BASE/$(get_pkgpool_for_host)/$pkgfile ]; then + cp $pkgpath $FTP_BASE/$(get_pkgpool_for_host) fi - ln -s "../../../$(get_pkgpool_for_host)/${arch}/${pkgfile}" $ftppath_to/${tarch}/ + ln -s "../../../$(get_pkgpool_for_host)/${pkgfile}" $ftppath_to/${tarch}/ done - pkgfiles="${pkgfiles} $FTP_BASE/$(get_pkgpool_for_host)/${arch}/${pkgfile}" + pkgfiles="${pkgfiles} $FTP_BASE/$(get_pkgpool_for_host)/${pkgfile}" done for tarch in ${tarches[@]}; do diff --git a/db-update b/db-update index 375ed02..46becac 100755 --- a/db-update +++ b/db-update @@ -89,11 +89,9 @@ for current_arch in ${ARCHES[@]}; do ftppath="$FTP_BASE/$reponame/os/$current_arch" ftppath_any="$FTP_BASE/$reponame/os/any" - poolpath="$FTP_BASE/$(get_pkgpool_for_host)/$current_arch" - poolpath_any="$FTP_BASE/$(get_pkgpool_for_host)/any" + poolpath="$FTP_BASE/$(get_pkgpool_for_host)" # The following is used to create relative symlinks - poolrel="../../../$(get_pkgpool_for_host)/$current_arch" - poolrel_any="../../../$(get_pkgpool_for_host)/any" + poolrel="../../../$(get_pkgpool_for_host)" if [ ! -d "$ftppath" ]; then echo "FTP path for this repo ($reponame) is missing" @@ -190,11 +188,11 @@ for current_arch in ${ARCHES[@]}; do for f in "$WORKDIR/build/"*-any$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null fname="$(basename $f)" - if ! /bin/cp "$f" "$poolpath_any/"; then - die "error: failure while copying files to $poolpath_any" + if ! /bin/cp "$f" "$poolpath/"; then + die "error: failure while copying files to $poolpath" fi - if ! ln -s "$poolrel_any/$fname" "$ftppath/$fname"; then + if ! ln -s "$poolrel/$fname" "$ftppath/$fname"; then die "error: failure symlinking $fname to $ftppath" fi done diff --git a/test/lib/common.inc b/test/lib/common.inc index ba5be9f..89155c7 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -28,7 +28,8 @@ setUp() { #echo "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} - mkdir -p "${TMP}/ftp/"{{core,extra,community,testing,community-testing}/os,packages/{arch,community}}/{i686,any,x86_64} + mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing}/os/{i686,any,x86_64} + mkdir -p "${TMP}/ftp/pool/"{packages,community} mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing} echo -n 'Creating svn repository...' @@ -81,11 +82,11 @@ checkAnyPackage() { local pkg=$2 local arch - [ -f "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "packages/arch/any/${pkg} not found" + [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" for arch in i686 x86_64; do [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/any/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/any/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" done [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" @@ -99,15 +100,15 @@ checkPackage() { local pkg=$2 local arch=$3 - [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "packages/arch/${arch}/${pkg} not found" + [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to packages/arch/${arch}/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" - local pkgbase=$(getpkgbase "${FTP_BASE}/packages/arch/${arch}/${pkg}") + local pkgbase=$(getpkgbase "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}") svn up -q "${TMP}/svn-packages-copy/${pkgbase}" [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" } diff --git a/test/runTest b/test/runTest index 5bbea05..75c7a05 100755 --- a/test/runTest +++ b/test/runTest @@ -240,7 +240,7 @@ testCleanupSimplePackages() { for arch in ${arches[@]}; do local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" checkRemovedPackage extra 'pkg-simple-a' ${arch} - [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg1}" ] && fail "packages/arch/${arch}/${pkg1} found" + [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" ] && fail "$(get_pkgpool_for_host)/${pkg1} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz" @@ -263,7 +263,7 @@ testCleanupAnyPackages() { local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' checkRemovedAnyPackage extra 'pkg-any-a' - [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg1}" ] && fail "packages/arch/${arch}/${pkg1} found" + [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" ] && fail "$(get_pkgpool_for_host)/${pkg1} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz" @@ -294,7 +294,7 @@ testCleanupSplitPackages() { for arch in ${arches[@]}; do for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do checkRemovedPackage extra ${pkgs[0]} ${arch} - [ -f "${FTP_BASE}/packages/arch/${arch}/${pkg}" ] && fail "packages/arch/${arch}/${pkg} found" + [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] && fail "$(get_pkgpool_for_host)/${pkg} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] && fail "${repo}/os/${arch}/${pkg} found" done @@ -329,7 +329,7 @@ testMovePackagesWithoutPool() { for old in 0 2; do for pkg in "${pkgdir}/${pkgs[${old}]}"/*-${arch}.pkg.tar.*; do pkg=$(basename $pkg) - mv -f "${FTP_BASE}/packages/arch/${arch}/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" + mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" done done done @@ -369,7 +369,7 @@ testMoveAnyPackagesWithoutPool() { # transform a package to old style layout for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do pkg=$(basename $pkg) - mv -f "${FTP_BASE}/packages/arch/any/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" + mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" for arch in i686 x86_64; do ln -sf "../any/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" done -- cgit v1.2.3-54-g00ecf From e2c005b490df6762e23da3223944151c17d1de80 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 13 Aug 2010 08:20:27 +0200 Subject: Check permission before any action Added a function to check if user has permission to alter the repos and db files. --- db-functions | 29 ++++++++++++++++++++++++++++- db-move | 5 +++++ db-remove | 5 +++++ db-update | 10 +--------- test/lib/common.inc | 49 +++++++++++++++++++++++++++++++++---------------- 5 files changed, 72 insertions(+), 26 deletions(-) (limited to 'test/lib/common.inc') diff --git a/db-functions b/db-functions index c4fc8f3..f22567b 100644 --- a/db-functions +++ b/db-functions @@ -73,7 +73,7 @@ die() { cleanup 1 } -trap abort INT QUIT TERM +trap abort INT QUIT TERM HUP trap cleanup EXIT @@ -274,3 +274,30 @@ pkgver_from_src() { tmp=${tmp%-any} echo $tmp | sed 's|.*-\(.*-.*\)$|\1|g' } + +check_repo_permission() { + local repo=$1 + + local repos="$(get_repos_for_host)" + local found=false + local r + for r in $repos; do + if [ "$r" = "$repo" ]; then + found=true + fi + done + [ $found ] || return 1 + + [ -w "$FTP_BASE/$(get_pkgpool_for_host)" ] || return 1 + + local arch + for arch in ${ARCHES} any; do + local w + local ws=("${FTP_BASE}/${repo}/os/${arch}/"{,${repo}${DBEXT}}) + for w in ws; do + [ -w ] || return 1 + done + done + + return 0 +} diff --git a/db-move b/db-move index d18a4fa..41b360d 100755 --- a/db-move +++ b/db-move @@ -23,6 +23,11 @@ ftppath_to="$FTP_BASE/$repoto/os/" svnrepo_from="$repofrom-$arch" svnrepo_to="$repoto-$arch" +if ! check_repo_permission $repoto || ! check_repo_permission $repofrom; then + echo "Error: You don't have permission to move packages from ${repofrom} to ${repoto}" + exit 1 +fi + repo_lock $repoto $arch || exit 1 repo_lock $repofrom $arch || exit 1 diff --git a/db-remove b/db-remove index 5a55849..1492d18 100755 --- a/db-remove +++ b/db-remove @@ -15,6 +15,11 @@ arch="$3" ftppath="$FTP_BASE/$reponame/os" svnrepo="$reponame-$arch" +if ! check_repo_permission $reponame; then + echo "Error: You don't have permission to remove packages from ${reponam}" + exit 1 +fi + repo_lock $reponame $arch || exit 1 echo -n "Removing $packagebase from $reponame..." diff --git a/db-update b/db-update index 46becac..c049714 100755 --- a/db-update +++ b/db-update @@ -11,15 +11,7 @@ fi reponame="$1" current_arch="" -# ensure we should be playing with this DB on this server -repos="$(get_repos_for_host)" -found=0 -for r in $repos; do - if [ "$r" = "$reponame" ]; then - found=1 - fi -done -if [ $found -ne 1 ]; then +if ! check_repo_permission "$reponame"; then echo "error: you shouldn't be updating $reponame on this server!" exit 1 fi diff --git a/test/lib/common.inc b/test/lib/common.inc index 89155c7..795d01a 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,3 +1,5 @@ +set -E + . "${curdir}/../db-functions" oneTimeSetUp() { @@ -8,7 +10,9 @@ oneTimeSetUp() { for p in "${pkgdir}"/*; do pushd $p >/dev/null linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || die 'makepkg failed' - [ -f *-any.pkg.tar.* ] || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 || die 'makepkg failed' + [ -f *-any.pkg.tar.* ] \ + || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 \ + || die 'makepkg failed' popd >/dev/null done echo 'done' @@ -23,7 +27,7 @@ setUp() { local p local pkg - [ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" + #[ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #echo "Using ${TMP}" @@ -82,17 +86,20 @@ checkAnyPackage() { local pkg=$2 local arch - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" + [ -r "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" for arch in i686 x86_64; do [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] \ + || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" done - [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" + [ -r "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" + ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg}) \ + || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" - [ -f "${FTP_BASE}/${repo}/os/any/${pkg}" ] && fail "${repo}/os/any/${pkg} should not exist" + [ -r "${FTP_BASE}/${repo}/os/any/${pkg}" ] && fail "${repo}/os/any/${pkg} should not exist" } checkPackage() { @@ -100,17 +107,21 @@ checkPackage() { local pkg=$2 local arch=$3 - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" + [ -r "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" - [ -f "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" + [ -r "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] \ + || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg} || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" + ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg}) \ + || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" local pkgbase=$(getpkgbase "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}") svn up -q "${TMP}/svn-packages-copy/${pkgbase}" - [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] \ + || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" } checkRemovedPackage() { @@ -118,10 +129,13 @@ checkRemovedPackage() { local pkgbase=$2 local arch=$3 - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" + ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase}) \ + && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" svn up -q "${TMP}/svn-packages-copy/${pkgbase}" - [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] && fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} should not exist" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] \ + && fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} should not exist" } checkRemovedAnyPackage() { @@ -130,9 +144,12 @@ checkRemovedAnyPackage() { local arch for arch in i686 x86_64; do - bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase} && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" + ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase}) \ + && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" done svn up -q "${TMP}/svn-packages-copy/${pkgbase}" - [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] && fail "svn-packages-copy/${pkgbase}/repos/${repo}-any should not exist" + [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] \ + && fail "svn-packages-copy/${pkgbase}/repos/${repo}-any should not exist" } \ No newline at end of file -- cgit v1.2.3-54-g00ecf From a422060414670bb49d2422a38467b73ae01e7ecb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 13 Aug 2010 09:47:31 +0200 Subject: Use common functions to print messages, warnings and errors These functions are copied from makepkg --- cron-jobs/create-filelists | 4 +-- cron-jobs/ftpdir-cleanup | 8 ++--- cron-jobs/sourceballs | 2 +- db-functions | 70 +++++++++++++++++++++++++++--------- db-move | 10 +++--- db-remove | 10 +++--- db-update | 48 ++++++++++++------------- misc-scripts/ftpdir-cleanup-repo | 78 +++++++++++++++------------------------- misc-scripts/make-sourceball | 14 ++++---- test/lib/common.inc | 10 +++--- testing2x | 6 ++-- 11 files changed, 134 insertions(+), 126 deletions(-) (limited to 'test/lib/common.inc') diff --git a/cron-jobs/create-filelists b/cron-jobs/create-filelists index 8c354fc..9249408 100755 --- a/cron-jobs/create-filelists +++ b/cron-jobs/create-filelists @@ -23,7 +23,7 @@ case "${DBEXT}" in *.gz) TAR_OPT="z" ;; *.bz2) TAR_OPT="j" ;; *.xz) TAR_OPT="J" ;; - *) echo "Unknown compression type for DBEXT=${DBEXT}" && exit 1 ;; + *) die "Unknown compression type for DBEXT=${DBEXT}" ;; esac FILESEXT="${DBEXT//db/files}" @@ -42,7 +42,7 @@ for repo in ${repos[@]}; do mkdir -p "${DBDIR}/${repodir}" bsdtar -xf "${targetdir}/${repodir}/${REPO_DB_FILE}" -C "${DBDIR}/${repodir}" else - echo "Fail! Does the repo $repo with arch $arch even exist?" + error "Fail! Does the repo $repo with arch $arch even exist?" continue fi diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 7668ab5..3456e9c 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -29,13 +29,11 @@ done popd >/dev/null if [ -n "$to_cleanup" ]; then - echo " The following packages are no longer in any repo" - echo " They will be moved to $CLEANUP_DESTDIR" + msg "The following packages are no longer in any repo" for f in $to_cleanup; do - echo " $(basename "$f")" + msg2 "$(basename "$f")" done - echo "" - mv $to_cleanup "$CLEANUP_DESTDIR" + ${CLEANUP_DRYRUN} || mv $to_cleanup "$CLEANUP_DESTDIR" fi script_unlock diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 78c3959..b82e375 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -22,7 +22,7 @@ for repo in ${repos[@]}; do for arch in ${ARCHES[@]} any; do ftppath="$ftpbase/$repo/os/$arch" if [ ! -d "$ftppath" ]; then - echo "FTP path does not exist: $ftppath" >2 + error "FTP path does not exist: $ftppath" continue fi cd $ftppath diff --git a/db-functions b/db-functions index f22567b..0c96913 100644 --- a/db-functions +++ b/db-functions @@ -16,11 +16,48 @@ restore_umask () { WORKDIR=$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX) LOCKS=() +# check if messages are to be printed using color +unset ALL_OFF BOLD BLUE GREEN RED YELLOW +if [[ -t 2 ]]; then + ALL_OFF="$(tput sgr0)" + BOLD="$(tput bold)" + BLUE="${BOLD}$(tput setaf 4)" + GREEN="${BOLD}$(tput setaf 2)" + RED="${BOLD}$(tput setaf 1)" + YELLOW="${BOLD}$(tput setaf 3)" +fi +readonly ALL_OFF BOLD BLUE GREEN RED YELLOW + +plain() { + local mesg=$1; shift + printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" +} + +msg() { + local mesg=$1; shift + printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" +} + +msg2() { + local mesg=$1; shift + printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" +} + +warning() { + local mesg=$1; shift + printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +error() { + local mesg=$1; shift + printf "${RED}==> ERROR${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + script_lock() { local LOCKDIR="$TMPDIR/.scriptlock.$(basename $0)" if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then local _owner="$(/usr/bin/stat -c %U $LOCKDIR)" - echo "Error: Script $(basename $0) is already locked by $_owner." >&2 + error "Script $(basename $0) is already locked by $_owner." exit 1 else set_umask @@ -31,7 +68,7 @@ script_lock() { script_unlock() { local LOCKDIR="$TMPDIR/.scriptlock.$(basename $0)" if [ ! -d "$LOCKDIR" ]; then - echo "Warning: Script $(basename $0) was not locked!" >&2 + warning "Script $(basename $0) was not locked!" restore_umask return 1 else @@ -51,12 +88,12 @@ cleanup() { repo=${l%.*} arch=${l#*.} if [ -d "$TMPDIR/.repolock.$repo.$arch" ]; then - echo "Removing left over lock from $repo/$arch" >&2 + msg "Removing left over lock from $repo/$arch" repo_unlock $repo $arch fi done if [ -d "$TMPDIR/.scriptlock.$(basename $0)" ]; then - echo "Removing left over lock from $(basename $0)" >&2 + msg "Removing left over lock from $(basename $0)" script_unlock fi rm -rf "$WORKDIR" @@ -64,12 +101,12 @@ cleanup() { } abort() { - echo 'Aborting...' >&2 + msg 'Aborting...' cleanup 0 } die() { - echo "$*" >&2 + error "$*" cleanup 1 } @@ -99,7 +136,8 @@ repo_lock () { while [ $_count -le $_trial ] || $_lockblock ; do if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then _owner="$(/usr/bin/stat -c %U $LOCKDIR)" - echo "Warning: Repo $1-$2 is already locked by $_owner. Retrying in $LOCK_DELAY seconds..." >&2 + warning "Repo $1-$2 is already locked by $_owner. " \ + "Retrying in $LOCK_DELAY seconds..." else LOCKS[${#LOCKS[*]}]="$1.$2" set_umask @@ -109,14 +147,14 @@ repo_lock () { let _count=$_count+1 done - echo "Error: Repo $1-$2 is already locked by $_owner. Giving up!" >&2 + error "Repo $1-$2 is already locked by $_owner. Giving up!" return 1 } repo_unlock () { #repo_unlock local LOCKDIR="$TMPDIR/.repolock.$1.$2" if [ ! -d "$LOCKDIR" ]; then - echo "Warning: Repo lock $1-$2 was not locked!" >&2 + warning "Repo lock $1-$2 was not locked!" restore_umask return 1 else @@ -153,7 +191,7 @@ getpkgname() { _name="$(_grep_pkginfo "$1" "^pkgname")" if [ -z "$_name" ]; then - echo "Error: Package '$1' has no pkgname in the PKGINFO. Fail!" >&2 + error "Package '$1' has no pkgname in the PKGINFO. Fail!" exit 1 fi @@ -166,7 +204,7 @@ getpkgver() { _ver="$(_grep_pkginfo "$1" "^pkgver")" if [ -z "$_ver" ]; then - echo "Error: Package '$1' has no pkgver in the PKGINFO. Fail!" >&2 + error "Package '$1' has no pkgver in the PKGINFO. Fail!" exit 1 fi @@ -175,10 +213,10 @@ getpkgver() { getpkgfile() { if [[ ${#} -ne 1 ]]; then - echo 'Error: No canonical package found!' >&2 + error 'No canonical package found!' exit 1 elif [ ! -f "${1}" ]; then - echo "Error: Package ${1} not found!" >&2 + error "Package ${1} not found!" exit 1 fi @@ -188,13 +226,13 @@ getpkgfile() { getpkgfiles() { local f if [ ! -z "$(echo ${@%\.*} | sed "s/ /\n/g" | sort | uniq -D)" ]; then - echo 'Error: Duplicate packages found!'>&2 + error 'Duplicate packages found!' exit 1 fi for f in ${@}; do if [ ! -f "${f}" ]; then - echo "Error: Package ${f} not found!" >&2 + error "Package ${f} not found!" exit 1 fi done @@ -208,7 +246,7 @@ check_pkg_arch () { _arch="$(_grep_pkginfo "$1" "^arch")" if [ -z "$_arch" ]; then - echo "Error: Package '$1' has no arch in the PKGINFO. Fail!" >&2 + error "Package '$1' has no arch in the PKGINFO. Fail!" return 1 fi if [ "$_arch" = "$2" ]; then diff --git a/db-move b/db-move index 41b360d..207baec 100755 --- a/db-move +++ b/db-move @@ -1,7 +1,7 @@ #!/bin/bash if [ $# -ne 4 ]; then - echo "usage: $(basename $0) " + msg "usage: $(basename $0) " exit 1 fi @@ -24,7 +24,7 @@ svnrepo_from="$repofrom-$arch" svnrepo_to="$repoto-$arch" if ! check_repo_permission $repoto || ! check_repo_permission $repofrom; then - echo "Error: You don't have permission to move packages from ${repofrom} to ${repoto}" + error "You don't have permission to move packages from ${repofrom} to ${repoto}" exit 1 fi @@ -41,7 +41,7 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then pkgver=$(. "$packagebase/repos/$svnrepo_from/PKGBUILD"; echo ${pkgver}) pkgrel=$(. "$packagebase/repos/$svnrepo_from/PKGBUILD"; echo ${pkgrel}) - echo -n "Moving $packagebase from $repofrom to $repoto..." + msg "Moving $packagebase from $repofrom to $repoto..." if [ -d "$packagebase/repos/$svnrepo_to" ]; then /usr/bin/svn rm --force -q "$packagebase/repos/$svnrepo_to" /usr/bin/svn commit -q -m "$(basename $0): $packagebase removed by $(id -un) for move to $repoto" @@ -71,10 +71,8 @@ if [ -d "$packagebase/repos/$svnrepo_from" ]; then /usr/bin/repo-add -q "$ftppath_to/${tarch}/$repoto$DBEXT" ${pkgfiles} >/dev/null || die "Error in repo-add $pkgfiles" /usr/bin/repo-remove -q "$ftppath_from/${tarch}/$repofrom$DBEXT" ${pkgname[@]} >/dev/null || die "Error in repo-remove ${pkgname[@]}" done - - echo 'done' else - die "Error: $packagebase is not in repo $repofrom" + die "$packagebase is not in repo $repofrom" fi repo_unlock $repoto $arch || exit 1 diff --git a/db-remove b/db-remove index 1492d18..2f05c16 100755 --- a/db-remove +++ b/db-remove @@ -1,7 +1,7 @@ #!/bin/bash if [ $# -ne 3 ]; then - echo "usage: $(basename $0) " + msg "usage: $(basename $0) " exit 1 fi @@ -16,13 +16,13 @@ ftppath="$FTP_BASE/$reponame/os" svnrepo="$reponame-$arch" if ! check_repo_permission $reponame; then - echo "Error: You don't have permission to remove packages from ${reponam}" + error "You don't have permission to remove packages from ${reponam}" exit 1 fi repo_lock $reponame $arch || exit 1 -echo -n "Removing $packagebase from $reponame..." +msg "Removing $packagebase from $reponame..." cd "$WORKDIR" /usr/bin/svn checkout -q -N $SVNREPO checkout >/dev/null cd checkout @@ -33,7 +33,7 @@ if [ -d "$packagebase/repos/$svnrepo" ]; then /usr/bin/svn rm --force -q "$packagebase/repos/$svnrepo" /usr/bin/svn commit -q -m "$(basename $0): $packagebase removed by $(id -un)" else - die "Error: $packagebase not found in $svnrepo" + die "$packagebase not found in $svnrepo" fi cd "$WORKDIR" @@ -53,8 +53,6 @@ for tarch in $arches; do /usr/bin/repo-remove -q "$ftppath/$tarch/$reponame$DBEXT" ${pkgname[@]} >/dev/null done -echo 'done' - repo_unlock $reponame $arch || exit 1 # vim: set ts=4 sw=4 noet ft=sh: diff --git a/db-update b/db-update index c049714..b56a70f 100755 --- a/db-update +++ b/db-update @@ -1,7 +1,7 @@ #!/bin/bash if [ $# -ne 1 ]; then - echo "usage: $(basename $0) " + msg "usage: $(basename $0) " exit 1 fi @@ -12,7 +12,7 @@ reponame="$1" current_arch="" if ! check_repo_permission "$reponame"; then - echo "error: you shouldn't be updating $reponame on this server!" + error "you shouldn't be updating $reponame on this server!" exit 1 fi @@ -21,11 +21,11 @@ ANYPKGS="" stagedir="$STAGING/$reponame" if [ ! -d $stagedir ]; then - echo "error: staging directory missing: $stagedir" >&2 + error "staging directory missing: $stagedir" exit 1 fi -echo -n "Updating $reponame..." +msg "Updating $reponame..." # Remove any package from $stagedir that is already in the FTP repository for current_arch in ${ARCHES[@]} any; do @@ -33,8 +33,8 @@ for current_arch in ${ARCHES[@]} any; do for f in $stagedir/*-$current_arch$PKGEXT; do bf=$(basename $f) if [[ -f $ftppath/$bf ]]; then - echo " WARNING: Package file $bf already exists in FTP repo" - echo " Removing from $stagedir" + warning " Package file $bf already exists in FTP repo" \ + " Removing from $stagedir" /bin/rm $f fi done @@ -59,7 +59,7 @@ if [ -n "$ANYPKGS" ]; then pkgbase="$(getpkgbase $pkg)" svnrepo="$reponame-any" if ! check_pkg_arch "$pkg" "any"; then - echo " ERROR: $pkgfile is not architecture independent!" + error "$pkgfile is not architecture independent!" else /usr/bin/svn up -q $pkgbase if [ -d "$pkgbase/repos/$svnrepo" ]; then @@ -68,10 +68,10 @@ if [ -n "$ANYPKGS" ]; then if echo "$pkgfile" | grep -q "$pkgname-$pkgver-$pkgrel-any"; then to_add_any="$to_add_any $pkg" else - echo " WARNING: $pkgfile does not match PKGBUILD in $svnrepo" + warning "$pkgfile does not match PKGBUILD in $svnrepo" fi else - echo " WARNING: Package $pkgbase not found in $svnrepo" + warning "Package $pkgbase not found in $svnrepo" fi fi done @@ -86,9 +86,9 @@ for current_arch in ${ARCHES[@]}; do poolrel="../../../$(get_pkgpool_for_host)" if [ ! -d "$ftppath" ]; then - echo "FTP path for this repo ($reponame) is missing" - echo " -> $ftppath" - echo "Please contact a system administrator" + error "FTP path for this repo ($reponame) is missing" \ + " -> $ftppath" \ + "Please contact a system administrator" exit 1 fi @@ -120,7 +120,7 @@ for current_arch in ${ARCHES[@]}; do cd "$WORKDIR" /usr/bin/svn checkout -N $SVNREPO checkout >/dev/null cd checkout - + if [ -n "$ADDPKGS" ]; then for pkg in $ADDPKGS; do pkgfile=$(basename $pkg) @@ -128,7 +128,7 @@ for current_arch in ${ARCHES[@]}; do pkgbase="$(getpkgbase $pkg)" if ! check_pkg_arch "$pkg" "$current_arch"; then - echo " ERROR: $pkgfile was built for the wrong architecture" + error "$pkgfile was built for the wrong architecture" else /usr/bin/svn up -q $pkgbase if [ -d "$pkgbase/repos/$svnrepo" ]; then @@ -137,10 +137,10 @@ for current_arch in ${ARCHES[@]}; do if echo "$pkgfile" | grep -q "$pkgname-$pkgver-$pkgrel-$current_arch"; then to_add="$to_add $pkg" else - echo " WARNING: $pkgfile does not match PKGBUILD in $svnrepo" + warning "$pkgfile does not match PKGBUILD in $svnrepo" fi else - echo " WARNING: Package $pkgbase not found in $svnrepo" + warning "Package $pkgbase not found in $svnrepo" fi fi done @@ -156,10 +156,10 @@ for current_arch in ${ARCHES[@]}; do /usr/bin/repo-add -q "$reponame-$current_arch$DBEXT" $pkgs >/dev/null else rm -f "build/$reponame-$current_arch$DBEXT" - echo "Errors found when adding packages" + error "Errors found when adding packages" fi else - echo "No packages to add" + warning "No packages to add" fi # if non empty, move all build dirs @@ -168,11 +168,11 @@ for current_arch in ${ARCHES[@]}; do for f in "$WORKDIR/build/"*-$current_arch$PKGEXT; do /bin/chmod 664 "$f" &>/dev/null if ! /bin/cp "$f" "$poolpath/"; then - die "error: failure while copying files to $poolpath" + die "failure while copying files to $poolpath" fi fname="$(basename $f)" if ! ln -s "$poolrel/$fname" "$ftppath/$fname"; then - die "error: failure symlinking $fname to $ftppath" + die "failure symlinking $fname to $ftppath" fi done fi @@ -181,11 +181,11 @@ for current_arch in ${ARCHES[@]}; do /bin/chmod 664 "$f" &>/dev/null fname="$(basename $f)" if ! /bin/cp "$f" "$poolpath/"; then - die "error: failure while copying files to $poolpath" + die "failure while copying files to $poolpath" fi if ! ln -s "$poolrel/$fname" "$ftppath/$fname"; then - die "error: failure symlinking $fname to $ftppath" + die "failure symlinking $fname to $ftppath" fi done fi @@ -194,7 +194,7 @@ for current_arch in ${ARCHES[@]}; do fi ln -sf "$reponame$DBEXT" "$ftppath/$reponame${DBEXT%.tar.*}" else - echo "Nothing to copy, no work done" + warning "Nothing to copy, no work done" fi if [ -n "$to_add" ]; then @@ -208,6 +208,4 @@ if [ -n "$to_add_any" ]; then /bin/rm $to_add_any fi -echo 'done' - # vim: set ts=4 sw=4 noet ft=sh: diff --git a/misc-scripts/ftpdir-cleanup-repo b/misc-scripts/ftpdir-cleanup-repo index 12f726c..20f297b 100755 --- a/misc-scripts/ftpdir-cleanup-repo +++ b/misc-scripts/ftpdir-cleanup-repo @@ -1,7 +1,7 @@ #!/bin/bash if [ $# -ne 1 ]; then - echo "usage: $(basename $0) " + msg "usage: $(basename $0) " exit 1 fi @@ -13,6 +13,7 @@ reponame=$1 . "$(dirname $0)/../config" clean_pkgs () { + if ! ${CLEANUP_DRYRUN}; then for pkg in "$@"; do if [ -h "$pkg" ]; then rm -f "$pkg" @@ -20,9 +21,10 @@ clean_pkgs () { mv "$pkg" "$CLEANUP_DESTDIR" fi done + fi } -${CLEANUP_DRYRUN} && echo 'dry run mode is active' +${CLEANUP_DRYRUN} && warning 'dry run mode is active' ftppath_base="$FTP_BASE/$reponame/os" @@ -38,26 +40,23 @@ for arch in ${ARCHES[@]}; do EXTRAFILES="" if [ ! -d "$ftppath" ]; then - echo "FTP path '$ftppath' does not exist" + error "FTP path '$ftppath' does not exist" exit 1 fi if ! cd "${CLEANUP_TMPDIR}" ; then - echo "Failed to cd to ${CLEANUP_TMPDIR}" + error "Failed to cd to ${CLEANUP_TMPDIR}" exit 1 fi if [ ! -f "$ftppath/$reponame$DBEXT" ]; then - echo "" - echo "WARNING: The file \"$ftppath/$reponame$DBEXT\" could not be found, skipping." - echo "" + msg "The file \"$ftppath/$reponame$DBEXT\" could not be found, skipping." repo_unlock $reponame $arch continue fi if ! bsdtar xf "$ftppath/$reponame$DBEXT"; then - echo "" - echo "ERROR: Command failed: bsdtar xf \"$ftppath/$reponame$DBEXT\"" + error "Command failed: bsdtar xf \"$ftppath/$reponame$DBEXT\"" exit 1 fi @@ -106,7 +105,7 @@ for arch in ${ARCHES[@]}; do MISSINGFILES="" for mf in $missfiles; do if [ -e "${ftppath_base}/any/${mf}" ]; then - echo "Restoring missing 'any' symlink: ${mf}" + msg "Restoring missing 'any' symlink: ${mf}" ${CLEANUP_DRYRUN} || ln -s "../any/${mf}" "${ftppath}" else MISSINGFILES="${MISSINGFILES} ${mf}" @@ -120,53 +119,36 @@ for arch in ${ARCHES[@]}; do continue fi - echo "Scan complete for $reponame ($arch) at ${ftppath}" - - if [ -n "$DELETEFILES" ]; then - echo " The following files are out of date" - for f in $DELETEFILES; do - echo " $f" - done - echo "" - fi - - if [ -n "$DELETESYMLINKS" ]; then - echo " The following symlinks are out of date" - echo " They will be deleted" - for f in $DELETESYMLINKS; do - echo " $f" - done - echo "" - fi + msg "Scan complete for $reponame ($arch) at ${ftppath}" if [ -n "$MISSINGFILES" ]; then - echo " The following files are missing in the repo" for f in $MISSINGFILES; do - echo " $f" - done - echo "" - fi - - if [ -n "$EXTRAFILES" ]; then - echo " The following files are in the repo but not the db" - for f in $EXTRAFILES; do - echo " $f" + error "$f is missing" done fi if [ -n "${DELETEFILES}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${DELETEFILES} - echo "" + msg "The following files are out of date" + for f in $DELETEFILES; do + msg2 "$f" + done + clean_pkgs ${DELETEFILES} fi if [ -n "${DELETESYMLINKS}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${DELETESYMLINKS} - echo "" + msg "The following symlinks are out of date" + for f in $DELETESYMLINKS; do + msg2 "$f" + done + clean_pkgs ${DELETESYMLINKS} fi if [ -n "${EXTRAFILES}" ]; then - ${CLEANUP_DRYRUN} || clean_pkgs ${EXTRAFILES} - echo "" + msg "The following files are in the repo but not the db" + for f in $EXTRAFILES; do + msg2 "$f" + done + clean_pkgs ${EXTRAFILES} fi done @@ -193,15 +175,13 @@ if [ -d "$ftppath_base/any" ]; then fi if [ -n "$ARCHINDEPFILES" ]; then - echo " The following architecture independent packages" - echo " are not symlinked in the architecture repositories." + msg "The following architecture independent packages are not symlinked in the architecture repositories." for f in $ARCHINDEPFILES; do - echo " $f" + msg2 "$f" done fi if [ -d "$ftppath_base/any" -a -n "${ARCHINDEPFILES}" ]; then cd "$ftppath_base/any" - ${CLEANUP_DRYRUN} || clean_pkgs ${ARCHINDEPFILES} - echo "" + clean_pkgs ${ARCHINDEPFILES} fi diff --git a/misc-scripts/make-sourceball b/misc-scripts/make-sourceball index 8e26eec..5bd155f 100755 --- a/misc-scripts/make-sourceball +++ b/misc-scripts/make-sourceball @@ -1,8 +1,8 @@ #!/bin/bash if [ $# -ne 3 -a $# -ne 4 ]; then - echo "usage: $(basename $0) [-f] " - echo " -f Force building. Skip license checks" + msg "usage: $(basename $0) [-f] " + msg " -f Force building. Skip license checks" exit 1 fi @@ -31,17 +31,17 @@ create_srcpackage() { pkgrel=$(. PKGBUILD; echo ${pkgrel}) if ! [ $FORCE == 1 ] && ! chk_license ${license[@]} ; then #Removed so as not to clutter failed.txt - #echo -e "\t$packagename license (${license[@]}) does not require source tarballs" >&2 + #warning "$packagename license (${license[@]}) does not require source tarballs" cleanup 0 else - echo "Creating source tarball for $packagename-$pkgver-$pkgrel" + msg "Creating source tarball for $packagename-$pkgver-$pkgrel" fi local logfile="$logpath/$packagename" if ! /usr/bin/makepkg --allsource --ignorearch >"$logfile" 2>&1; then popd >/dev/null /bin/gzip -f -9 "$logfile" - die "\tFailed to download source for $packagename-$pkgver-$pkgrel ($reponame-$arch)" + die "Failed to download source for $packagename-$pkgver-$pkgrel ($reponame-$arch)" fi /bin/rm -f "$logfile"{,.gz} @@ -66,13 +66,13 @@ if [[ "$reponame" = "community" || "$reponame" = "community-testing" ]]; then if /usr/bin/svn export -q "$SVNREPOCOMMUNITY/$packagename" $packagename; then create_srcpackage "$packagename/repos/$reponame-$arch" else - die "\tPackage '$packagename' does not exist in repo '$reponame-$arch'" + die "Package '$packagename' does not exist in repo '$reponame-$arch'" fi else if /usr/bin/svn export -q "$SVNREPO/$packagename" $packagename; then create_srcpackage "$packagename/repos/$reponame-$arch" else - die "\tPackage '$packagename' does not exist in repo '$reponame-$arch'" + die "Package '$packagename' does not exist in repo '$reponame-$arch'" fi fi diff --git a/test/lib/common.inc b/test/lib/common.inc index 795d01a..5c76eb5 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -6,7 +6,7 @@ oneTimeSetUp() { local p pkgdir="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" cp -r ${curdir}/packages/* "${pkgdir}" - echo -n 'Building packages...' + msg 'Building packages...' for p in "${pkgdir}"/*; do pushd $p >/dev/null linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || die 'makepkg failed' @@ -15,7 +15,6 @@ oneTimeSetUp() { || die 'makepkg failed' popd >/dev/null done - echo 'done' echo } @@ -29,14 +28,14 @@ setUp() { #[ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" - #echo "Using ${TMP}" + #msg "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing}/os/{i686,any,x86_64} mkdir -p "${TMP}/ftp/pool/"{packages,community} mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing} - echo -n 'Creating svn repository...' + msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" svnadmin create "${TMP}/svn-community-repo" svn checkout -q "file://${TMP}/svn-packages-repo" "${TMP}/svn-packages-copy" @@ -49,7 +48,6 @@ setUp() { svn add -q "${TMP}/svn-packages-copy"/${pkg} svn commit -q -m"initial commit of ${pkg}" "${TMP}/svn-packages-copy" done - echo 'done' cat < "${curdir}/../config.local" FTP_BASE="${TMP}/ftp" @@ -152,4 +150,4 @@ checkRemovedAnyPackage() { svn up -q "${TMP}/svn-packages-copy/${pkgbase}" [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] \ && fail "svn-packages-copy/${pkgbase}/repos/${repo}-any should not exist" -} \ No newline at end of file +} diff --git a/testing2x b/testing2x index bf48be6..3626432 100755 --- a/testing2x +++ b/testing2x @@ -22,16 +22,16 @@ for pkg in $*; do if [ -f "${pkg}/repos/testing-${_arch}/PKGBUILD" ]; then for repo in core extra; do if [ -f "${pkg}/repos/${repo}-${_arch}/PKGBUILD" ]; then - echo "===> Moving package '${pkg}': testing-${_arch} -> ${repo}-${_arch}" + msg "Moving package '${pkg}': testing-${_arch} -> ${repo}-${_arch}" $(dirname $0)/db-move "${pkg}" "testing" "${repo}" "${_arch}" moved=1 break fi done if [ ${moved} -eq 0 ]; then - echo "===> Warning: ${pkg} is only in testing-${_arch}, cannot determine where to move it" + warning "${pkg} is only in testing-${_arch}, cannot determine where to move it" fi else - echo "===> Warning: ${pkg} is not in testing-${_arch}" + warning "${pkg} is not in testing-${_arch}" fi done -- cgit v1.2.3-54-g00ecf From ce604bc3a2569198fa749acca190fef036e059a1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 15 Aug 2010 19:17:05 +0200 Subject: add test to check updating a package --- test/lib/common.inc | 3 ++- test/runTest | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index 5c76eb5..e55ce38 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -75,8 +75,9 @@ releasePackage() { pushd "${TMP}/svn-packages-copy"/${pkgbase}/trunk/ >/dev/null archrelease ${repo}-${arch} >/dev/null 2&>1 + pkgver=$(. PKGBUILD; echo "${pkgver}-${pkgrel}") popd >/dev/null - cp "${pkgdir}/${pkgbase}"/*.pkg.tar.* "${STAGING}"/${repo}/ + cp "${pkgdir}/${pkgbase}"/*-${pkgver}-${arch}.pkg.tar.* "${STAGING}"/${repo}/ } checkAnyPackage() { diff --git a/test/runTest b/test/runTest index 03f94c2..a16165d 100755 --- a/test/runTest +++ b/test/runTest @@ -81,6 +81,24 @@ testAddSplitPackages() { done } +testUpdateAnyPackage() { + releasePackage extra pkg-any-a any + ../db-update + + pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null + sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD + svn commit -q -m"update pkg to pkgrel=2" >/dev/null + makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 + mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" + popd >/dev/null + + releasePackage extra pkg-any-a any + ../db-update + + checkAnyPackage extra pkg-any-a-1-2-any.pkg.tar.xz any + + rm "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" +} # # db-remove -- cgit v1.2.3-54-g00ecf From 4daeb0a71e65618c56d672118675c9efd57c5979 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Tue, 17 Aug 2010 08:00:21 +0200 Subject: Add [staging] repository --- cron-jobs/adjust-permissions | 2 ++ cron-jobs/create-filelists | 2 +- cron-jobs/sourceballs | 2 +- db-functions | 2 +- test/lib/common.inc | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/lib/common.inc') diff --git a/cron-jobs/adjust-permissions b/cron-jobs/adjust-permissions index c28ca7c..6acfcf2 100755 --- a/cron-jobs/adjust-permissions +++ b/cron-jobs/adjust-permissions @@ -13,6 +13,8 @@ get_dir_owner() { echo "ftp:ftp-extra" ;; testing) echo "ftp:ftp-extra" ;; + staging) + echo "ftp:ftp-extra" ;; community) echo "root:tusers" ;; community-testing) diff --git a/cron-jobs/create-filelists b/cron-jobs/create-filelists index 9249408..fd07617 100755 --- a/cron-jobs/create-filelists +++ b/cron-jobs/create-filelists @@ -5,7 +5,7 @@ reposdir=${FTP_BASE} targetdir=${FTP_BASE} -repos=(core extra testing community community-testing) +repos=(core extra testing community community-testing staging) script_lock diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index b82e375..a6f7a19 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -5,7 +5,7 @@ ftpbase="${FTP_BASE}" srcbase="${FTP_BASE}/sources" -repos=(core extra testing community community-testing) +repos=(core extra testing community community-testing staging) script_lock diff --git a/db-functions b/db-functions index 015f254..a04dbf5 100644 --- a/db-functions +++ b/db-functions @@ -315,7 +315,7 @@ get_repos_for_host() { if [ "$(hostname)" = "sigurd" ]; then echo "community community-testing" else - echo "core extra testing" + echo "core extra testing staging" fi } diff --git a/test/lib/common.inc b/test/lib/common.inc index e55ce38..a79558c 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -31,9 +31,9 @@ setUp() { #msg "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} - mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing}/os/{i686,any,x86_64} + mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing,staging}/os/{i686,any,x86_64} mkdir -p "${TMP}/ftp/pool/"{packages,community} - mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing} + mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing,staging} msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" -- cgit v1.2.3-54-g00ecf From 9e8897aeadb2aa51b70c5fc0ed1ae281b015d146 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Aug 2010 22:01:09 +0200 Subject: add makepkg.conf for [multilib] --- cron-jobs/adjust-permissions | 2 ++ cron-jobs/create-filelists | 2 +- cron-jobs/sourceballs | 2 +- db-functions | 2 +- test/lib/common.inc | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/lib/common.inc') diff --git a/cron-jobs/adjust-permissions b/cron-jobs/adjust-permissions index 6acfcf2..2cc8b40 100755 --- a/cron-jobs/adjust-permissions +++ b/cron-jobs/adjust-permissions @@ -19,6 +19,8 @@ get_dir_owner() { echo "root:tusers" ;; community-testing) echo "root:tusers" ;; + multilib) + echo "root:tusers" ;; pool/packages) echo "ftp:ftp-extra" ;; pool/community) diff --git a/cron-jobs/create-filelists b/cron-jobs/create-filelists index fd07617..e280f84 100755 --- a/cron-jobs/create-filelists +++ b/cron-jobs/create-filelists @@ -5,7 +5,7 @@ reposdir=${FTP_BASE} targetdir=${FTP_BASE} -repos=(core extra testing community community-testing staging) +repos=(core extra testing community community-testing staging multilib) script_lock diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index a6f7a19..a482eb7 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -5,7 +5,7 @@ ftpbase="${FTP_BASE}" srcbase="${FTP_BASE}/sources" -repos=(core extra testing community community-testing staging) +repos=(core extra testing community community-testing staging multilib) script_lock diff --git a/db-functions b/db-functions index 292e3ff..9f87298 100644 --- a/db-functions +++ b/db-functions @@ -314,7 +314,7 @@ check_pkgsvn() { get_repos_for_host() { if [ "$(hostname)" = "sigurd" ]; then - echo "community community-testing" + echo "community community-testing multilib" else echo "core extra testing staging" fi diff --git a/test/lib/common.inc b/test/lib/common.inc index a79558c..9017aa5 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -31,9 +31,9 @@ setUp() { #msg "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} - mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing,staging}/os/{i686,any,x86_64} + mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing,staging,multilib}/os/{i686,any,x86_64} mkdir -p "${TMP}/ftp/pool/"{packages,community} - mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing,staging} + mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing,staging,multilib} msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" -- cgit v1.2.3-54-g00ecf From 328b1ce478e25902aba5d8f19024dadeaaf3f678 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 1 Sep 2010 19:34:47 +0200 Subject: Simplify repo configuration * Repositories can now be defined in the config file for each host * added community-staging, gnome-unstable and kde-unstable * Exception is the adjust-permission cron-job; but we might want to use acls in future anyway Signed-off-by: Pierre Schmitz --- config | 8 ++++++++ cron-jobs/adjust-permissions | 6 ++++++ cron-jobs/create-filelists | 3 +-- cron-jobs/integrity-check | 2 +- cron-jobs/sourceballs | 3 +-- db-functions | 12 ++++++------ test/lib/common.inc | 16 +++++++++++++--- 7 files changed, 36 insertions(+), 14 deletions(-) (limited to 'test/lib/common.inc') diff --git a/config b/config index f6600a6..f0d6cfc 100644 --- a/config +++ b/config @@ -4,6 +4,14 @@ FTP_BASE="/srv/ftp" SVNREPO="file:///srv/svn-packages" SVNREPOCOMMUNITY="file:///srv/svn-community" +declare -A PKGREPO +PKGREPO['default']='core extra testing staging kde-unstable gnome-unstable' +PKGREPO['sigurd']='community community-testing community-staging multilib' + +declare -A PKGPOOL +PKGPOOL['default']='pool/packages' +PKGPOOL['sigurd']='pool/community' + CLEANUP_DESTDIR="/srv/package-cleanup" CLEANUP_DRYRUN=false SOURCE_CLEANUP_DESTDIR="/srv/source-cleanup" diff --git a/cron-jobs/adjust-permissions b/cron-jobs/adjust-permissions index a68584c..e0b6e4e 100755 --- a/cron-jobs/adjust-permissions +++ b/cron-jobs/adjust-permissions @@ -15,10 +15,16 @@ get_dir_owner() { echo "ftp:ftp-extra" ;; staging) echo "ftp:ftp-extra" ;; + kde-unstable) + echo "ftp:ftp-extra" ;; + gnome-unstable) + echo "ftp:ftp-extra" ;; community) echo "root:tusers" ;; community-testing) echo "root:tusers" ;; + community-staging) + echo "root:tusers" ;; multilib) echo "root:multilib" ;; pool/packages) diff --git a/cron-jobs/create-filelists b/cron-jobs/create-filelists index e280f84..a37080f 100755 --- a/cron-jobs/create-filelists +++ b/cron-jobs/create-filelists @@ -5,7 +5,6 @@ reposdir=${FTP_BASE} targetdir=${FTP_BASE} -repos=(core extra testing community community-testing staging multilib) script_lock @@ -28,7 +27,7 @@ esac FILESEXT="${DBEXT//db/files}" -for repo in ${repos[@]}; do +for repo in ${PKGREPO[@]}; do REPO_DB_FILE="${repo}$DBEXT" FILES_DB_FILE="${repo}$FILESEXT" for arch in ${ARCHES[@]}; do diff --git a/cron-jobs/integrity-check b/cron-jobs/integrity-check index 0b2b9c7..c120cfd 100755 --- a/cron-jobs/integrity-check +++ b/cron-jobs/integrity-check @@ -7,7 +7,7 @@ if [ $# -ne 2 ]; then exit 1 fi -for arch in i686 x86_64; do +for arch in ${ARCHES[@]}; do $basedir/check_archlinux/check_packages.py \ --repos="$1" \ --abs-tree="/srv/abs/rsync/$arch,/srv/abs/rsync/any" --arch="$arch" |\ diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index a482eb7..0cf062f 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -5,7 +5,6 @@ ftpbase="${FTP_BASE}" srcbase="${FTP_BASE}/sources" -repos=(core extra testing community community-testing staging multilib) script_lock @@ -18,7 +17,7 @@ FAILED_PKGS="" [ -e "$srcbase/errors.txt" ] && /bin/mv "$srcbase/errors.txt" "$srcbase/errors.txt.old" echo "Errors occured during run:" > "$srcbase/errors.txt" -for repo in ${repos[@]}; do +for repo in ${PKGREPO[@]}; do for arch in ${ARCHES[@]} any; do ftppath="$ftpbase/$repo/os/$arch" if [ ! -d "$ftppath" ]; then diff --git a/db-functions b/db-functions index 9f87298..28928da 100644 --- a/db-functions +++ b/db-functions @@ -313,18 +313,18 @@ check_pkgsvn() { } get_repos_for_host() { - if [ "$(hostname)" = "sigurd" ]; then - echo "community community-testing multilib" + if [ -n "${PKGREPO[$(hostname -s)]}" ]; then + echo "${PKGREPO[$(hostname -s)]}" else - echo "core extra testing staging" + echo "${PKGREPO['default']}" fi } get_pkgpool_for_host() { - if [ "$(hostname)" = "sigurd" ]; then - echo "pool/community" + if [ -n "${PKGPOOL[$(hostname -s)]}" ]; then + echo "${PKGPOOL[$(hostname -s)]}" else - echo "pool/packages" + echo "${PKGPOOL['default']}" fi } diff --git a/test/lib/common.inc b/test/lib/common.inc index 9017aa5..71dfd3d 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,5 +1,6 @@ set -E +. "${curdir}/../config" . "${curdir}/../db-functions" oneTimeSetUp() { @@ -25,15 +26,24 @@ oneTimeTearDown() { setUp() { local p local pkg + local r + local a #[ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #msg "Using ${TMP}" mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} - mkdir -p "${TMP}/ftp/"{core,extra,community,testing,community-testing,staging,multilib}/os/{i686,any,x86_64} - mkdir -p "${TMP}/ftp/pool/"{packages,community} - mkdir -p "${TMP}/staging/"{core,extra,community,testing,community-testing,staging,multilib} + + for r in ${PKGREPO[@]}; do + mkdir -p "${TMP}/staging/${r}" + for a in ${ARCHES[@]} any; do + mkdir -p "${TMP}/ftp/${r}/os/${a}" + done + done + for p in ${PKGPOOL[@]}; do + mkdir -p "${TMP}/ftp/${p}" + done msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" -- cgit v1.2.3-54-g00ecf From f121126f8166fb6dc261ea82f2890ba6693d047e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 11 Sep 2010 22:52:23 +0200 Subject: Use local config instead of guessing by hostname Using the hostname to decide which repos to use is not releiable and hard to test. Instead use config.local to configure these. config files for sigurd and gerolde were added which can be copied or symlinked to config.local on the specific host. --- config | 10 ++-------- config.local.gerolde | 2 ++ config.local.sigurd | 2 ++ cron-jobs/ftpdir-cleanup | 14 ++++++-------- db-functions | 29 ++++++++--------------------- db-move | 8 ++++---- db-update | 4 ++-- test/lib/common.inc | 26 ++++++++++++++------------ test/runTest | 16 ++++++++-------- 9 files changed, 48 insertions(+), 63 deletions(-) create mode 100644 config.local.gerolde create mode 100644 config.local.sigurd (limited to 'test/lib/common.inc') diff --git a/config b/config index a595331..89e89fd 100644 --- a/config +++ b/config @@ -1,16 +1,10 @@ - FTP_BASE="/srv/ftp" SVNREPO="file:///srv/svn-packages" SVNREPOCOMMUNITY="file:///srv/svn-community" -declare -A PKGREPO -PKGREPO['default']='core extra testing staging kde-unstable gnome-unstable' -PKGREPO['sigurd']='community community-testing community-staging multilib multilib-testing' - -declare -A PKGPOOL -PKGPOOL['default']='pool/packages' -PKGPOOL['sigurd']='pool/community' +PKGREPOS=() +PKGPOOL='' CLEANUP_DESTDIR="/srv/package-cleanup" CLEANUP_DRYRUN=false diff --git a/config.local.gerolde b/config.local.gerolde new file mode 100644 index 0000000..dd8ba86 --- /dev/null +++ b/config.local.gerolde @@ -0,0 +1,2 @@ +PKGREPOS=('core' 'extra' 'testing' 'staging' 'kde-unstable' 'gnome-unstable') +PKGPOOL='pool/packages' diff --git a/config.local.sigurd b/config.local.sigurd new file mode 100644 index 0000000..c8c3c9f --- /dev/null +++ b/config.local.sigurd @@ -0,0 +1,2 @@ +PKGREPOS=('community' 'community-testing' 'community-staging' 'multilib' 'multilib-testing') +PKGPOOL='pool/community' diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 5c8776e..914ef8c 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -18,11 +18,9 @@ clean_pkg() { fi } -repos=($(get_repos_for_host)) - script_lock -for repo in ${repos[@]}; do +for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do repo_lock ${repo} ${arch} || exit 1 done @@ -30,7 +28,7 @@ done ${CLEANUP_DRYRUN} && warning 'dry run mode is active' -for repo in ${repos[@]}; do +for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do if [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" ]; then warning "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT} not found, skipping" @@ -61,7 +59,7 @@ for repo in ${repos[@]}; do done # get a list of all available packages in the pacakge pool -find "$FTP_BASE/$(get_pkgpool_for_host)" -name "*${PKGEXT}" -printf '%f\n' | sort > "${WORKDIR}/pool" +find "$FTP_BASE/${PKGPOOL}" -name "*${PKGEXT}" -printf '%f\n' | sort > "${WORKDIR}/pool" # create a list of packages in our db cat "${WORKDIR}/db-"* | sort -u > "${WORKDIR}/db" @@ -70,12 +68,12 @@ if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old packages from package pool..." for old_pkg in ${old_pkgs[@]}; do msg2 "${old_pkg}" - clean_pkg "$FTP_BASE/$(get_pkgpool_for_host)/${old_pkg}" + clean_pkg "$FTP_BASE/${PKGPOOL}/${old_pkg}" done fi # cleanup of legacy $repo/os/any directories -for repo in ${repos[@]}; do +for repo in ${PKGREPOS[@]}; do if [ ! -d "${FTP_BASE}/${repo}/os/any" ]; then continue fi @@ -98,7 +96,7 @@ for repo in ${repos[@]}; do done -for repo in ${repos[@]}; do +for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do repo_unlock ${repo} ${arch} done diff --git a/db-functions b/db-functions index 18029ee..939f2d5 100644 --- a/db-functions +++ b/db-functions @@ -294,7 +294,7 @@ check_pkgsvn() { [ $? -ge 1 ] && return 1 local repo="${2}" - in_array "${repo}" $(get_repos_for_host) || return 1 + in_array "${repo}" ${PKGREPOS[@]} || return 1 if [ ! -f "${WORKDIR}/pkgbuilds/${repo}/${pkgbase}" ]; then mkdir -p "${WORKDIR}/pkgbuilds/${repo}" @@ -320,13 +320,13 @@ check_pkgrepos() { local pkgver="$(getpkgver ${pkgfile})" [ $? -ge 1 ] && return 1 - if [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkgname}-${pkgver}-"*${PKGEXT} ]; then + if [ -f "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-"*${PKGEXT} ]; then return 1 fi local repo local arch - for repo in $(get_repos_for_host); do + for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do if [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkgname}-${pkgver}"*${PKGEXT} ]; then return 1 @@ -337,22 +337,6 @@ check_pkgrepos() { return 0 } -get_repos_for_host() { - if [ -n "${PKGREPO[$(hostname -s)]}" ]; then - echo "${PKGREPO[$(hostname -s)]}" - else - echo "${PKGREPO['default']}" - fi -} - -get_pkgpool_for_host() { - if [ -n "${PKGPOOL[$(hostname -s)]}" ]; then - echo "${PKGPOOL[$(hostname -s)]}" - else - echo "${PKGPOOL['default']}" - fi -} - #usage: chk_license ${license[@]}" chk_license() { local l @@ -397,9 +381,12 @@ pkgver_from_src() { check_repo_permission() { local repo=$1 - in_array "${repo}" $(get_repos_for_host) || return 1 + [ ${#PKGREPOS[@]} -eq 0 ] && return 1 + [ -z "${PKGPOOL}" ] && return 1 + + in_array "${repo}" ${PKGREPOS[@]} || return 1 - [ -w "$FTP_BASE/$(get_pkgpool_for_host)" ] || return 1 + [ -w "$FTP_BASE/${PKGPOOL}" ] || return 1 local arch for arch in ${ARCHES}; do diff --git a/db-move b/db-move index fe9d2c9..cdc261c 100755 --- a/db-move +++ b/db-move @@ -92,11 +92,11 @@ for pkgbase in ${args[@]:2}; do # copy package to pool if needed # TODO: can be removed once every package has been moved to the package pool - if [ ! -f ${FTP_BASE}/$(get_pkgpool_for_host)/${pkgfile} ]; then - cp ${pkgpath} ${FTP_BASE}/$(get_pkgpool_for_host) + if [ ! -f ${FTP_BASE}/${PKGPOOL}/${pkgfile} ]; then + cp ${pkgpath} ${FTP_BASE}/${PKGPOOL} fi - ln -s "../../../$(get_pkgpool_for_host)/${pkgfile}" ${ftppath_to}/${tarch}/ - add_pkgs[${tarch}]+="${FTP_BASE}/$(get_pkgpool_for_host)/${pkgfile} " + ln -s "../../../${PKGPOOL}/${pkgfile}" ${ftppath_to}/${tarch}/ + add_pkgs[${tarch}]+="${FTP_BASE}/${PKGPOOL}/${pkgfile} " remove_pkgs[${tarch}]+="${pkgname} " done done diff --git a/db-update b/db-update index 70f0525..49ecbde 100755 --- a/db-update +++ b/db-update @@ -58,9 +58,9 @@ for repo in ${repos[@]}; do msg2 "${pkgfile} (${pkgarch})" # any packages might have been moved by the previous run if [ -f "${pkg}" ]; then - mv "${pkg}" "$FTP_BASE/$(get_pkgpool_for_host)" + mv "${pkg}" "$FTP_BASE/${PKGPOOL}" fi - ln -s "../../../$(get_pkgpool_for_host)/${pkgfile}" "$FTP_BASE/$repo/os/${pkgarch}" + ln -s "../../../${PKGPOOL}/${pkgfile}" "$FTP_BASE/$repo/os/${pkgarch}" add_pkgs[${#add_pkgs[*]}]=${pkgfile} done if [ ${#add_pkgs[@]} -ge 1 ]; then diff --git a/test/lib/common.inc b/test/lib/common.inc index 71dfd3d..a0d864a 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -29,13 +29,15 @@ setUp() { local r local a - #[ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" + [ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #msg "Using ${TMP}" - mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-{packages,community}-{copy,repo}} + PKGREPOS=('core' 'extra' 'testing') + PKGPOOL='pool/packages' + mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-packages-{copy,repo}} - for r in ${PKGREPO[@]}; do + for r in ${PKGREPOS[@]}; do mkdir -p "${TMP}/staging/${r}" for a in ${ARCHES[@]} any; do mkdir -p "${TMP}/ftp/${r}/os/${a}" @@ -47,9 +49,7 @@ setUp() { msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" - svnadmin create "${TMP}/svn-community-repo" svn checkout -q "file://${TMP}/svn-packages-repo" "${TMP}/svn-packages-copy" - svn checkout -q "file://${TMP}/svn-community-repo" "${TMP}/svn-community-copy" for p in "${pkgdir}"/*; do pkg=$(basename $p) @@ -63,6 +63,8 @@ setUp() { FTP_BASE="${TMP}/ftp" SVNREPO="file://${TMP}/svn-packages-repo" SVNREPOCOMMUNITY="file://${TMP}/svn-community-repo" + PKGREPOS=(${PKGREPOS[@]}) + PKGPOOL="${PKGPOOL}" CLEANUP_DESTDIR="${TMP}/package-cleanup" SOURCE_CLEANUP_DESTDIR="${TMP}/source-cleanup" STAGING="${TMP}/staging" @@ -95,12 +97,12 @@ checkAnyPackage() { local pkg=$2 local arch - [ -r "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" + [ -r "${FTP_BASE}/${PKGPOOL}/${pkg}" ] || fail "${PKGPOOL}/${pkg} not found" for arch in i686 x86_64; do [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] \ - || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/${PKGPOOL}/${pkg}" ] \ + || fail "${repo}/os/${arch}/${pkg} does not link to ${PKGPOOL}/${pkg}" done [ -r "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" @@ -116,18 +118,18 @@ checkPackage() { local pkg=$2 local arch=$3 - [ -r "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] || fail "$(get_pkgpool_for_host)/${pkg} not found" + [ -r "${FTP_BASE}/${PKGPOOL}/${pkg}" ] || fail "${PKGPOOL}/${pkg} not found" [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" [ -r "${STAGING}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging dir" - [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] \ - || fail "${repo}/os/${arch}/${pkg} does not link to $(get_pkgpool_for_host)/${pkg}" + [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == "${FTP_BASE}/${PKGPOOL}/${pkg}" ] \ + || fail "${repo}/os/${arch}/${pkg} does not link to ${PKGPOOL}/${pkg}" ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkg}) \ || fail "${pkg} not in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" - local pkgbase=$(getpkgbase "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}") + local pkgbase=$(getpkgbase "${FTP_BASE}/${PKGPOOL}/${pkg}") svn up -q "${TMP}/svn-packages-copy/${pkgbase}" [ -d "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] \ || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" diff --git a/test/runTest b/test/runTest index b07b099..4681944 100755 --- a/test/runTest +++ b/test/runTest @@ -321,7 +321,7 @@ testCleanupSimplePackages() { for arch in ${arches[@]}; do local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" checkRemovedPackage extra 'pkg-simple-a' ${arch} - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" ] && fail "$(get_pkgpool_for_host)/${pkg1} found" + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz" @@ -344,7 +344,7 @@ testCleanupAnyPackages() { local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' checkRemovedAnyPackage extra 'pkg-any-a' - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" ] && fail "$(get_pkgpool_for_host)/${pkg1} found" + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz" @@ -375,7 +375,7 @@ testCleanupSplitPackages() { for arch in ${arches[@]}; do for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do checkRemovedPackage extra ${pkgs[0]} ${arch} - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" ] && fail "$(get_pkgpool_for_host)/${pkg} found" + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg}" ] && fail "${PKGPOOL}/${pkg} found" [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] && fail "${repo}/os/${arch}/${pkg} found" done @@ -410,7 +410,7 @@ testMovePackagesWithoutPool() { for old in 0 2; do for pkg in "${pkgdir}/${pkgs[${old}]}"/*-${arch}.pkg.tar.*; do pkg=$(basename $pkg) - mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" done done done @@ -441,7 +441,7 @@ testUpdateAnyPackageWithoutPool() { releasePackage extra pkg-any-a any ../db-update # transform two packages to old style layout - mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" "${FTP_BASE}/extra/os/any" + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" "${FTP_BASE}/extra/os/any" for arch in i686 x86_64; do ln -sf "../any/${pkg1}" "${FTP_BASE}/extra/os/${arch}" done @@ -461,7 +461,7 @@ testUpdateAnyPackageWithoutPool() { checkAnyPackage extra "${pkg2}" - [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg1}" ] && fail "$(get_pkgpool_for_host)/${pkg1} found" + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" for arch in any i686 x86_64; do [ -f "${FTP_BASE}/extra/os/${arch}/${pkg1}" ] && fail "extra/os/${arch}/${pkg1} found" done @@ -482,7 +482,7 @@ testMoveAnyPackagesWithoutPool() { # transform a package to old style layout for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do pkg=$(basename $pkg) - mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" for arch in i686 x86_64; do ln -sf "../any/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" done @@ -519,7 +519,7 @@ testUpdateSameAnyPackageToDifferentRepositoriesWithoutPool() { # transform a package to old style layout for pkg in "${pkgdir}/pkg-any-a"/*-any.pkg.tar.*; do pkg=$(basename $pkg) - mv -f "${FTP_BASE}/$(get_pkgpool_for_host)/${pkg}" "${FTP_BASE}/extra/os/any/${pkg}" + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/extra/os/any/${pkg}" for arch in i686 x86_64; do ln -sf "../any/${pkg}" "${FTP_BASE}/extra/os/${arch}/${pkg}" done -- cgit v1.2.3-54-g00ecf From cb2dcc6ee207e9c5ba4b875d70e387e6347591ed Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 20 Nov 2010 16:11:59 +0100 Subject: Fix sourceballs cron job * add unit test for sourceballs and cleanup * introduce SRCPOOL and LOGDIR variables in config --- config | 2 ++ config.local.gerolde | 1 + config.local.sigurd | 1 + cron-jobs/sourceballs | 21 ++++++-------- misc-scripts/make-sourceball | 13 +++------ misc-scripts/sourceballs-cleanup | 9 +++--- test/lib/common.inc | 7 +++-- test/runTest | 59 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 29 deletions(-) (limited to 'test/lib/common.inc') diff --git a/config b/config index 89e89fd..efc4381 100644 --- a/config +++ b/config @@ -5,6 +5,7 @@ SVNREPOCOMMUNITY="file:///srv/svn-community" PKGREPOS=() PKGPOOL='' +SRCPOOL='' CLEANUP_DESTDIR="/srv/package-cleanup" CLEANUP_DRYRUN=false @@ -15,6 +16,7 @@ LOCK_TIMEOUT=300 STAGING="$HOME/staging" TMPDIR="/srv/tmp" +LOGDIR="/var/log/dbscripts" ARCHES=(i686 x86_64) DBEXT=".db.tar.gz" PKGEXT=".pkg.tar.*" diff --git a/config.local.gerolde b/config.local.gerolde index dd8ba86..03e8a70 100644 --- a/config.local.gerolde +++ b/config.local.gerolde @@ -1,2 +1,3 @@ PKGREPOS=('core' 'extra' 'testing' 'staging' 'kde-unstable' 'gnome-unstable') PKGPOOL='pool/packages' +SRCPOOL='sources/packages' diff --git a/config.local.sigurd b/config.local.sigurd index c8c3c9f..ddb5ba4 100644 --- a/config.local.sigurd +++ b/config.local.sigurd @@ -1,2 +1,3 @@ PKGREPOS=('community' 'community-testing' 'community-staging' 'multilib' 'multilib-testing') PKGPOOL='pool/community' +SRCPOOL='sources/community' diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 0b01321..4fc194f 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -3,9 +3,6 @@ . "$(dirname $0)/../db-functions" . "$(dirname $0)/../config" -ftpbase="${FTP_BASE}" -srcbase="${FTP_BASE}/sources" - script_lock set_umask @@ -14,12 +11,12 @@ dirname="$(/bin/readlink -f $(/usr/bin/dirname $0))" FAILED_PKGS="" -[ -e "$srcbase/errors.txt" ] && /bin/mv "$srcbase/errors.txt" "$srcbase/errors.txt.old" -echo "Errors occured during run:" > "$srcbase/errors.txt" +[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" +[ -e "${LOGDIR}/sourceballs/errors.txt" ] && /bin/mv "${LOGDIR}/sourceballs/errors.txt" "${LOGDIR}/sourceballs/errors.txt.old" for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]} any; do - ftppath="$ftpbase/$repo/os/$arch" + for arch in ${ARCHES[@]}; do + ftppath="${FTP_BASE}/$repo/os/$arch" if [ ! -d "$ftppath" ]; then error "FTP path does not exist: $ftppath" continue @@ -28,7 +25,6 @@ for repo in ${PKGREPOS[@]}; do for pkg in *$PKGEXT; do [ -f "$pkg" ] || continue pkgbase=$(getpkgbase $pkg) - srcpath="$srcbase/" srcpkg="${pkg//$PKGEXT/$SRCEXT}" srcpkg="${srcpkg//-$arch/}" srcpkgname="${srcpkg%-*-*$SRCEXT}" @@ -51,9 +47,9 @@ for repo in ${PKGREPOS[@]}; do force="-f" fi - if [ ! \( -f "$srcpath$srcpkg" -o -f "$srcpath$srcpkgbase" \) ]; then + if [ ! \( -f "${FTP_BASE}/${SRCPOOL}/$srcpkg" -o -f "${FTP_BASE}/${SRCPOOL}/$srcpkgbase" \) ]; then if ! $dirname/../misc-scripts/make-sourceball $force \ - $pkgbase $repo $arch 2>>"$srcbase/errors.txt"; then + $pkgbase $repo $arch 2>>"${LOGDIR}/sourceballs/errors.txt"; then FAILED_PKGS="$FAILED_PKGS $pkgbase" fi fi @@ -62,9 +58,8 @@ for repo in ${PKGREPOS[@]}; do done if [ -n "$FAILED_PKGS" ]; then - [ -e "$srcbase/failed.txt" ] && /bin/mv "$srcbase/failed.txt" "$srcbase/failed.txt.old" - echo "The following package bases failed:" > "$srcbase/failed.txt" - echo -e $FAILED_PKGS | sed "s| |\n|g" | sort -u >> "$srcbase/failed.txt" + [ -e "${LOGDIR}/sourceballs/failed.txt" ] && /bin/mv "${LOGDIR}/sourceballs/failed.txt" "${LOGDIR}/sourceballs/failed.txt.old" + echo -e $FAILED_PKGS | sed "s| |\n|g" | sort -u >> "${LOGDIR}/sourceballs/failed.txt" fi $dirname/../misc-scripts/sourceballs-cleanup diff --git a/misc-scripts/make-sourceball b/misc-scripts/make-sourceball index 5bd155f..221d0ce 100755 --- a/misc-scripts/make-sourceball +++ b/misc-scripts/make-sourceball @@ -19,9 +19,6 @@ packagename="$1" reponame="$2" arch="$3" -srcpath="$FTP_BASE/sources/" -logpath="/var/log/sourceballs/" - script_lock create_srcpackage() { @@ -29,6 +26,7 @@ create_srcpackage() { pushd "$1" >/dev/null pkgver=$(. PKGBUILD; echo ${pkgver}) pkgrel=$(. PKGBUILD; echo ${pkgrel}) + license=($(. PKGBUILD; echo ${license[@]})) if ! [ $FORCE == 1 ] && ! chk_license ${license[@]} ; then #Removed so as not to clutter failed.txt #warning "$packagename license (${license[@]}) does not require source tarballs" @@ -37,7 +35,7 @@ create_srcpackage() { msg "Creating source tarball for $packagename-$pkgver-$pkgrel" fi - local logfile="$logpath/$packagename" + local logfile="${LOGDIR}/sourceballs/$packagename" if ! /usr/bin/makepkg --allsource --ignorearch >"$logfile" 2>&1; then popd >/dev/null /bin/gzip -f -9 "$logfile" @@ -47,10 +45,7 @@ create_srcpackage() { local pkg_file="${packagename}-${pkgver}-${pkgrel}${SRCEXT}" - if [ ! -d "$srcpath" ]; then - mkdir -p "$srcpath" - fi - cp "$pkg_file" "$srcpath" + cp "$pkg_file" "${FTP_BASE}/${SRCPOOL}" popd >/dev/null @@ -59,7 +54,7 @@ create_srcpackage() { } set_umask -/bin/mkdir -p "$logpath" +[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" cd "$WORKDIR" if [[ "$reponame" = "community" || "$reponame" = "community-testing" ]]; then diff --git a/misc-scripts/sourceballs-cleanup b/misc-scripts/sourceballs-cleanup index e407989..788cc98 100755 --- a/misc-scripts/sourceballs-cleanup +++ b/misc-scripts/sourceballs-cleanup @@ -3,8 +3,8 @@ . "$(dirname $0)/../db-functions" . "$(dirname $0)/../config" -srcpath="$FTP_BASE/sources/" -logfile="$srcpath/cleanup.txt" +[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" +logfile="${LOGDIR}/sourceballs/cleanup.txt" script_lock @@ -20,7 +20,7 @@ remove_old() { cd .. done - for srcpkg in "$srcpath/$packagename-"*; do + for srcpkg in "${FTP_BASE}/${SRCPOOL}/$packagename-"*; do [ -f "$srcpkg" ] || continue if [ "$(pkgname_from_src $srcpkg)" == "$packagename" ]; then skip=0 @@ -47,10 +47,11 @@ remove_old() { set_umask cd "$WORKDIR" + [ -e "$logfile" ] && /bin/mv "$logfile" "$logfile.old" echo "Orphaned sourceballs:" > "$logfile" -for sourceball in "$srcpath"/*$SRCEXT; do +for sourceball in "${FTP_BASE}/${SRCPOOL}"/*$SRCEXT; do packagename=$(basename $sourceball) packagename=${packagename%-*-*$SRCEXT} diff --git a/test/lib/common.inc b/test/lib/common.inc index a0d864a..14dc000 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -43,9 +43,9 @@ setUp() { mkdir -p "${TMP}/ftp/${r}/os/${a}" done done - for p in ${PKGPOOL[@]}; do - mkdir -p "${TMP}/ftp/${p}" - done + mkdir -p "${TMP}/ftp/${PKGPOOL}" + mkdir -p "${TMP}/ftp/${SRCPOOL}" + mkdir -p "${TMP}/log" msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" @@ -69,6 +69,7 @@ setUp() { SOURCE_CLEANUP_DESTDIR="${TMP}/source-cleanup" STAGING="${TMP}/staging" TMPDIR="${TMP}/tmp" + LOGDIR="${TMP}/log" CLEANUP_DRYRUN=false eot . "${curdir}/../config" diff --git a/test/runTest b/test/runTest index 4681944..d3e2eff 100755 --- a/test/runTest +++ b/test/runTest @@ -535,5 +535,64 @@ testUpdateSameAnyPackageToDifferentRepositoriesWithoutPool() { done } +# +#sourceballs tests +# + +testSourceballs() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + ../db-update + + ../cron-jobs/sourceballs + + for log in errors failed; do + if [ -s "${LOGDIR}/sourceballs/${log}.txt" ]; then + fail "${LOGDIR}/sourceballs/${log}.txt includes the following errors:" + cat "${LOGDIR}/sourceballs/${log}.txt" + fi + done + for pkgbase in ${pkgs[@]}; do + [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" + done +} + +testSourceballsCleanup() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + ../db-update + ../cron-jobs/sourceballs + + for arch in ${arches[@]}; do + ../db-remove pkg-simple-a extra ${arch} + done + ../cron-jobs/ftpdir-cleanup >/dev/null + + ../cron-jobs/sourceballs + for log in errors failed; do + if [ -s "${LOGDIR}/sourceballs/${log}.txt" ]; then + fail "${LOGDIR}/sourceballs/${log}.txt includes the following errors:" + cat "${LOGDIR}/sourceballs/${log}.txt" + fi + done + [ -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-a-*${SRCEXT} ] && fail "source package was not removed!" + [ ! -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-b-*${SRCEXT} ] && fail "source package not found!" +} . "${curdir}/lib/shunit2" -- cgit v1.2.3-54-g00ecf From a7591f4be3f9e741f5d1e5aeadd3ab20b497a252 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 20 Nov 2010 20:38:38 +0100 Subject: Simplify sourceballs creation * Read package lists directly from DB file * Make SVNREPO configurable --- config | 5 +---- config.local.gerolde | 1 + config.local.sigurd | 1 + cron-jobs/sourceballs | 46 ++++++++++++++++---------------------------- misc-scripts/make-sourceball | 34 ++++++++++++-------------------- test/lib/common.inc | 1 - 6 files changed, 32 insertions(+), 56 deletions(-) (limited to 'test/lib/common.inc') diff --git a/config b/config index efc4381..e149b18 100644 --- a/config +++ b/config @@ -1,8 +1,5 @@ FTP_BASE="/srv/ftp" - -SVNREPO="file:///srv/svn-packages" -SVNREPOCOMMUNITY="file:///srv/svn-community" - +SVNREPO='' PKGREPOS=() PKGPOOL='' SRCPOOL='' diff --git a/config.local.gerolde b/config.local.gerolde index 03e8a70..4501a93 100644 --- a/config.local.gerolde +++ b/config.local.gerolde @@ -1,3 +1,4 @@ PKGREPOS=('core' 'extra' 'testing' 'staging' 'kde-unstable' 'gnome-unstable') PKGPOOL='pool/packages' SRCPOOL='sources/packages' +SVNREPO='file:///srv/svn-packages' diff --git a/config.local.sigurd b/config.local.sigurd index ddb5ba4..f62372c 100644 --- a/config.local.sigurd +++ b/config.local.sigurd @@ -1,3 +1,4 @@ PKGREPOS=('community' 'community-testing' 'community-staging' 'multilib' 'multilib-testing') PKGPOOL='pool/community' SRCPOOL='sources/community' +SVNREPO='file:///srv/svn-community' diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 4fc194f..1add36e 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -9,59 +9,47 @@ set_umask dirname="$(/bin/readlink -f $(/usr/bin/dirname $0))" -FAILED_PKGS="" - [ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" [ -e "${LOGDIR}/sourceballs/errors.txt" ] && /bin/mv "${LOGDIR}/sourceballs/errors.txt" "${LOGDIR}/sourceballs/errors.txt.old" +[ -e "${LOGDIR}/sourceballs/failed.txt" ] && /bin/mv "${LOGDIR}/sourceballs/failed.txt" "${LOGDIR}/sourceballs/failed.txt.old" for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do ftppath="${FTP_BASE}/$repo/os/$arch" - if [ ! -d "$ftppath" ]; then - error "FTP path does not exist: $ftppath" + dbfile="${ftppath}/${repo}${DBEXT}" + if [ ! -r "${dbfile}" ]; then + warning "DB file does not exist: ${dbfile}" continue fi - cd $ftppath - for pkg in *$PKGEXT; do - [ -f "$pkg" ] || continue - pkgbase=$(getpkgbase $pkg) - srcpkg="${pkg//$PKGEXT/$SRCEXT}" - srcpkg="${srcpkg//-$arch/}" - srcpkgname="${srcpkg%-*-*$SRCEXT}" - srcpkgbase="${srcpkg/$srcpkgname/$pkgbase}" - - #Don't do anything for package in this 'blacklist' - if grep "^$pkgbase\$" "$dirname/sourceballs.skip" >/dev/null 2>&1; then - continue - fi - - #This pkgbase has already failed. No sense in trying it again this run - if echo $FAILED_PKGS | grep "\<$pkgbase\>" >&/dev/null; then + for pkg in $(bsdtar -xOf "${dbfile}" \ + | awk '/^%NAME%/{getline b};/^%BASE%/{getline b};/^%VERSION%/{getline v};/^%ARCH%/{printf "%s/%s\n", b, v}' \ + | sort -u); do + pkgbase=${pkg%/*} + pkgver=${pkg#*/} + srcpkg="${pkgbase}-${pkgver}${SRCEXT}" + + # Don't do anything for package in this 'blacklist' + if grep -q "^${pkgbase}\$" "$dirname/sourceballs.skip"; then continue fi - #Use this file to 'whitelist' or force building some sourceballs, + # Use this file to 'whitelist' or force building some sourceballs, # skipping the license check force="" - if grep "^$pkgbase\$" "$dirname/sourceballs.force" >/dev/null 2>&1; then + if grep -q "^$pkgbase\$" "$dirname/sourceballs.force"; then force="-f" fi - if [ ! \( -f "${FTP_BASE}/${SRCPOOL}/$srcpkg" -o -f "${FTP_BASE}/${SRCPOOL}/$srcpkgbase" \) ]; then + if [ ! -f "${FTP_BASE}/${SRCPOOL}/$srcpkg" ]; then if ! $dirname/../misc-scripts/make-sourceball $force \ $pkgbase $repo $arch 2>>"${LOGDIR}/sourceballs/errors.txt"; then - FAILED_PKGS="$FAILED_PKGS $pkgbase" + echo "$pkgbase" >> "${LOGDIR}/sourceballs/failed.txt" fi fi done done done -if [ -n "$FAILED_PKGS" ]; then - [ -e "${LOGDIR}/sourceballs/failed.txt" ] && /bin/mv "${LOGDIR}/sourceballs/failed.txt" "${LOGDIR}/sourceballs/failed.txt.old" - echo -e $FAILED_PKGS | sed "s| |\n|g" | sort -u >> "${LOGDIR}/sourceballs/failed.txt" -fi - $dirname/../misc-scripts/sourceballs-cleanup script_unlock diff --git a/misc-scripts/make-sourceball b/misc-scripts/make-sourceball index 221d0ce..661f481 100755 --- a/misc-scripts/make-sourceball +++ b/misc-scripts/make-sourceball @@ -24,28 +24,26 @@ script_lock create_srcpackage() { if [ -d "$1" ]; then pushd "$1" >/dev/null - pkgver=$(. PKGBUILD; echo ${pkgver}) - pkgrel=$(. PKGBUILD; echo ${pkgrel}) - license=($(. PKGBUILD; echo ${license[@]})) - if ! [ $FORCE == 1 ] && ! chk_license ${license[@]} ; then - #Removed so as not to clutter failed.txt + pkgver=$(. PKGBUILD; echo ${pkgver}) + pkgrel=$(. PKGBUILD; echo ${pkgrel}) + license=($(. PKGBUILD; echo ${license[@]})) + if ! [ $FORCE == 1 ] && ! chk_license ${license[@]} ; then + # Removed so as not to clutter failed.txt #warning "$packagename license (${license[@]}) does not require source tarballs" cleanup 0 else msg "Creating source tarball for $packagename-$pkgver-$pkgrel" fi - local logfile="${LOGDIR}/sourceballs/$packagename" - if ! /usr/bin/makepkg --allsource --ignorearch >"$logfile" 2>&1; then - popd >/dev/null - /bin/gzip -f -9 "$logfile" + local logfile="${LOGDIR}/sourceballs/$packagename.gz" + if ! /usr/bin/makepkg --allsource --ignorearch 2>&1 | gzip >"$logfile"; then die "Failed to download source for $packagename-$pkgver-$pkgrel ($reponame-$arch)" fi - /bin/rm -f "$logfile"{,.gz} + /bin/rm -f "$logfile" local pkg_file="${packagename}-${pkgver}-${pkgrel}${SRCEXT}" - cp "$pkg_file" "${FTP_BASE}/${SRCPOOL}" + mv "$pkg_file" "${FTP_BASE}/${SRCPOOL}" popd >/dev/null @@ -57,18 +55,10 @@ set_umask [ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" cd "$WORKDIR" -if [[ "$reponame" = "community" || "$reponame" = "community-testing" ]]; then - if /usr/bin/svn export -q "$SVNREPOCOMMUNITY/$packagename" $packagename; then - create_srcpackage "$packagename/repos/$reponame-$arch" - else - die "Package '$packagename' does not exist in repo '$reponame-$arch'" - fi +if /usr/bin/svn export -q "$SVNREPO/$packagename" $packagename; then + create_srcpackage "$packagename/repos/$reponame-$arch" else - if /usr/bin/svn export -q "$SVNREPO/$packagename" $packagename; then - create_srcpackage "$packagename/repos/$reponame-$arch" - else - die "Package '$packagename' does not exist in repo '$reponame-$arch'" - fi + die "Package '$packagename' does not exist in repo '$reponame-$arch'" fi script_unlock diff --git a/test/lib/common.inc b/test/lib/common.inc index 14dc000..e47ae2d 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -62,7 +62,6 @@ setUp() { cat < "${curdir}/../config.local" FTP_BASE="${TMP}/ftp" SVNREPO="file://${TMP}/svn-packages-repo" - SVNREPOCOMMUNITY="file://${TMP}/svn-community-repo" PKGREPOS=(${PKGREPOS[@]}) PKGPOOL="${PKGPOOL}" CLEANUP_DESTDIR="${TMP}/package-cleanup" -- cgit v1.2.3-54-g00ecf From 30a128a864bdbfc294b6ba6a49c9264570bb3c58 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 21 Nov 2010 13:23:09 +0100 Subject: sourceballs: Don't write any log This is consistent with the other dbscripts. The output will be send to the mailinglist. --- config | 1 - cron-jobs/sourceballs | 11 +++-------- misc-scripts/make-sourceball | 15 +++++++-------- misc-scripts/sourceballs-cleanup | 17 +++++------------ test/lib/common.inc | 2 -- test/runTest | 13 ------------- 6 files changed, 15 insertions(+), 44 deletions(-) (limited to 'test/lib/common.inc') diff --git a/config b/config index 4b89f2d..01956ba 100644 --- a/config +++ b/config @@ -13,7 +13,6 @@ LOCK_TIMEOUT=300 STAGING="$HOME/staging" TMPDIR="/srv/tmp" -LOGDIR="/var/log/dbscripts" ARCHES=(i686 x86_64) DBEXT=".db.tar.gz" PKGEXT=".pkg.tar.*" diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 351b06d..23e8421 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -9,16 +9,12 @@ set_umask dirname="$(/bin/readlink -f $(/usr/bin/dirname $0))" -[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" -[ -e "${LOGDIR}/sourceballs/errors.txt" ] && /bin/mv "${LOGDIR}/sourceballs/errors.txt" "${LOGDIR}/sourceballs/errors.txt.old" -[ -e "${LOGDIR}/sourceballs/failed.txt" ] && /bin/mv "${LOGDIR}/sourceballs/failed.txt" "${LOGDIR}/sourceballs/failed.txt.old" - for repo in ${PKGREPOS[@]}; do for arch in ${ARCHES[@]}; do ftppath="${FTP_BASE}/$repo/os/$arch" dbfile="${ftppath}/${repo}${DBEXT}" if [ ! -r "${dbfile}" ]; then - warning "DB file does not exist: ${dbfile}" + warning "${dbfile} not found, skipping" continue fi @@ -48,9 +44,8 @@ for repo in ${PKGREPOS[@]}; do fi if [ ! -f "${FTP_BASE}/${SRCPOOL}/$srcpkg" ]; then - if ! $dirname/../misc-scripts/make-sourceball $force \ - $pkgbase $repo $arch 2>>"${LOGDIR}/sourceballs/errors.txt"; then - echo "$pkgbase" >> "${LOGDIR}/sourceballs/failed.txt" + if ! $dirname/../misc-scripts/make-sourceball $force $pkgbase $repo $arch; then + error "Failed to download sources for $pkgbase" fi fi done diff --git a/misc-scripts/make-sourceball b/misc-scripts/make-sourceball index 66d3dad..fccc4b5 100755 --- a/misc-scripts/make-sourceball +++ b/misc-scripts/make-sourceball @@ -47,17 +47,17 @@ create_srcpackage() { msg "Creating source tarball for $packagename-$pkgver-$pkgrel" fi - local logfile="${LOGDIR}/sourceballs/$packagename" - if ! /usr/bin/makepkg --allsource --ignorearch >"$logfile" 2>&1; then + /usr/bin/makepkg --allsource --ignorearch > "$WORKDIR/makepkg.log" 2>&1 + if [ $? -ne 0 ]; then error "Failed to download source for $packagename-$pkgver-$pkgrel ($reponame-$arch)" - popd >/dev/null + local line + while read line; do + msg2 "${line}" + done < "$WORKDIR/makepkg.log" return 1 fi - /bin/rm -f "$logfile" - - local pkg_file="${packagename}-${pkgver}-${pkgrel}${SRCEXT}" - mv "$pkg_file" "${FTP_BASE}/${SRCPOOL}" + mv "${packagename}-${pkgver}-${pkgrel}${SRCEXT}" "${FTP_BASE}/${SRCPOOL}" popd >/dev/null @@ -68,7 +68,6 @@ create_srcpackage() { } set_umask -[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" cd "$WORKDIR" failed=0 diff --git a/misc-scripts/sourceballs-cleanup b/misc-scripts/sourceballs-cleanup index 450d137..fdb1355 100755 --- a/misc-scripts/sourceballs-cleanup +++ b/misc-scripts/sourceballs-cleanup @@ -3,9 +3,6 @@ . "$(dirname $0)/../db-functions" . "$(dirname $0)/../config" -[ ! -d "${LOGDIR}/sourceballs" ] && mkdir -p "${LOGDIR}/sourceballs" -logfile="${LOGDIR}/sourceballs/cleanup.txt" - script_lock ${CLEANUP_DRYRUN} && warning 'dry run mode is active' @@ -53,10 +50,6 @@ remove_old() { set_umask cd "$WORKDIR" - -[ -e "$logfile" ] && /bin/mv "$logfile" "$logfile.old" -echo "Orphaned sourceballs:" > "$logfile" - for sourceball in "${FTP_BASE}/${SRCPOOL}"/*$SRCEXT; do [ -f "$sourceball" ] || continue packagename=$(basename $sourceball) @@ -64,16 +57,16 @@ for sourceball in "${FTP_BASE}/${SRCPOOL}"/*$SRCEXT; do if ! /usr/bin/svn export -q --force "$SVNREPO/$packagename" "$packagename" >/dev/null 2>&1; then if [ $? -ne 1 ]; then - echo "$packagename : svn died during export. Skipping sourceball." >> "$logfile" + error "$packagename : svn died during export. Skipping sourceball." else - echo "$packagename : no longer in svn. Removing sourceball." >> "$logfile" + msg "$packagename : no longer in svn. Removing sourceball." ${CLEANUP_DRYRUN} || mv $sourceball $SOURCE_CLEANUP_DESTDIR fi elif [ -z "$(ls -A "$packagename/repos")" ]; then - echo "$packagename : no longer in repos but trunk is still in svn. Removing sourceball." >> "$logfile" + warning "$packagename : no longer in repos but trunk is still in svn. Removing sourceball." ${CLEANUP_DRYRUN} || mv $sourceball $SOURCE_CLEANUP_DESTDIR - elif ! source "$packagename/trunk/PKGBUILD" && chk_license ${license[@]}; then - echo "$packagename : source hosting no longer required by license. Removing sourceball." >> "$logfile" + elif ! chk_license $(. "$packagename/trunk/PKGBUILD"; echo ${license[@]}); then + msg "$packagename : source hosting no longer required by license. Removing sourceball." ${CLEANUP_DRYRUN} || mv $sourceball $SOURCE_CLEANUP_DESTDIR else remove_old "$packagename/repos/" diff --git a/test/lib/common.inc b/test/lib/common.inc index e47ae2d..6619c0a 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -45,7 +45,6 @@ setUp() { done mkdir -p "${TMP}/ftp/${PKGPOOL}" mkdir -p "${TMP}/ftp/${SRCPOOL}" - mkdir -p "${TMP}/log" msg 'Creating svn repository...' svnadmin create "${TMP}/svn-packages-repo" @@ -68,7 +67,6 @@ setUp() { SOURCE_CLEANUP_DESTDIR="${TMP}/source-cleanup" STAGING="${TMP}/staging" TMPDIR="${TMP}/tmp" - LOGDIR="${TMP}/log" CLEANUP_DRYRUN=false eot . "${curdir}/../config" diff --git a/test/runTest b/test/runTest index d3e2eff..6c60ddc 100755 --- a/test/runTest +++ b/test/runTest @@ -553,13 +553,6 @@ testSourceballs() { ../db-update ../cron-jobs/sourceballs - - for log in errors failed; do - if [ -s "${LOGDIR}/sourceballs/${log}.txt" ]; then - fail "${LOGDIR}/sourceballs/${log}.txt includes the following errors:" - cat "${LOGDIR}/sourceballs/${log}.txt" - fi - done for pkgbase in ${pkgs[@]}; do [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" done @@ -585,12 +578,6 @@ testSourceballsCleanup() { ../cron-jobs/ftpdir-cleanup >/dev/null ../cron-jobs/sourceballs - for log in errors failed; do - if [ -s "${LOGDIR}/sourceballs/${log}.txt" ]; then - fail "${LOGDIR}/sourceballs/${log}.txt includes the following errors:" - cat "${LOGDIR}/sourceballs/${log}.txt" - fi - done [ -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-a-*${SRCEXT} ] && fail "source package was not removed!" [ ! -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-b-*${SRCEXT} ] && fail "source package not found!" } -- cgit v1.2.3-54-g00ecf From cadd215e9d726030bd7b86396eda47c2c69c1bbb Mon Sep 17 00:00:00 2001 From: Eric Bélanger Date: Wed, 24 Nov 2010 15:13:13 -0500 Subject: Added seperate dryrun options for the packages and sources cleanup scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric Bélanger Signed-off-by: Pierre Schmitz --- config | 1 + cron-jobs/sourceballs | 4 ++-- test/lib/common.inc | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test/lib/common.inc') diff --git a/config b/config index 01956ba..69f40c7 100644 --- a/config +++ b/config @@ -7,6 +7,7 @@ SRCPOOL='' CLEANUP_DESTDIR="/srv/package-cleanup" CLEANUP_DRYRUN=false SOURCE_CLEANUP_DESTDIR="/srv/source-cleanup" +SOURCE_CLEANUP_DRYRUN=false LOCK_DELAY=10 LOCK_TIMEOUT=300 diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 6a86a0d..9ba003a 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -119,10 +119,10 @@ old_pkgs=($(comm -23 "${WORKDIR}/available-src-pkgs.sort" "${WORKDIR}/expected-s if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old source packages..." - ${CLEANUP_DRYRUN} && warning 'dry run mode is active' + ${SOURCE_CLEANUP_DRYRUN} && warning 'dry run mode is active' for old_pkg in ${old_pkgs[@]}; do msg2 "${old_pkg}" - ${CLEANUP_DRYRUN} || mv "$FTP_BASE/${SRCPOOL}/${old_pkg}" "${SOURCE_CLEANUP_DESTDIR}" + ${SOURCE_CLEANUP_DRYRUN} || mv "$FTP_BASE/${SRCPOOL}/${old_pkg}" "${SOURCE_CLEANUP_DESTDIR}" done fi diff --git a/test/lib/common.inc b/test/lib/common.inc index 6619c0a..d7ea3d4 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -68,6 +68,7 @@ setUp() { STAGING="${TMP}/staging" TMPDIR="${TMP}/tmp" CLEANUP_DRYRUN=false + SOURCE_CLEANUP_DRYRUN=false eot . "${curdir}/../config" } -- cgit v1.2.3-54-g00ecf From 5f72b8029c07f3357014d8716f18f21ce649c98a Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 25 Nov 2010 06:55:03 +0100 Subject: Provide more real test packages * Use devtools instead of plain makepkg * This is a preparation for some more advanced test cases. --- .gitignore | 1 + test/lib/common.inc | 39 ++++++++++-- test/lib/makepkg-i686.conf | 115 ------------------------------------ test/lib/makepkg-x86_64.conf | 115 ------------------------------------ test/packages/pkg-any-a/PKGBUILD | 3 +- test/packages/pkg-any-b/PKGBUILD | 3 +- test/packages/pkg-simple-a/Makefile | 1 + test/packages/pkg-simple-a/PKGBUILD | 13 +++- test/packages/pkg-simple-a/test.c | 1 + test/packages/pkg-simple-b/Makefile | 1 + test/packages/pkg-simple-b/PKGBUILD | 13 +++- test/packages/pkg-simple-b/test.c | 1 + test/packages/pkg-split-a/Makefile | 1 + test/packages/pkg-split-a/PKGBUILD | 16 ++++- test/packages/pkg-split-a/test.c | 1 + test/packages/pkg-split-b/Makefile | 1 + test/packages/pkg-split-b/PKGBUILD | 17 +++++- test/packages/pkg-split-b/test.c | 1 + test/runTest | 24 ++++---- test/src/Makefile | 5 ++ test/src/test.c | 7 +++ 21 files changed, 121 insertions(+), 258 deletions(-) delete mode 100644 test/lib/makepkg-i686.conf delete mode 100644 test/lib/makepkg-x86_64.conf create mode 120000 test/packages/pkg-simple-a/Makefile create mode 120000 test/packages/pkg-simple-a/test.c create mode 120000 test/packages/pkg-simple-b/Makefile create mode 120000 test/packages/pkg-simple-b/test.c create mode 120000 test/packages/pkg-split-a/Makefile create mode 120000 test/packages/pkg-split-a/test.c create mode 120000 test/packages/pkg-split-b/Makefile create mode 120000 test/packages/pkg-split-b/test.c create mode 100644 test/src/Makefile create mode 100644 test/src/test.c (limited to 'test/lib/common.inc') diff --git a/.gitignore b/.gitignore index 01daf28..de95927 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ /config.local +test/packages/*/*.pkg.tar.* diff --git a/test/lib/common.inc b/test/lib/common.inc index d7ea3d4..34de9eb 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -5,15 +5,42 @@ set -E oneTimeSetUp() { local p + local d + local a + local pkgname + local pkgarch + local pkgversion + local build pkgdir="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" cp -r ${curdir}/packages/* "${pkgdir}" msg 'Building packages...' - for p in "${pkgdir}"/*; do - pushd $p >/dev/null - linux32 makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 || die 'makepkg failed' - [ -f *-any.pkg.tar.* ] \ - || linux64 makepkg -cf --config ${curdir}/lib/makepkg-x86_64.conf >/dev/null 2>&1 \ - || die 'makepkg failed' + for d in "${pkgdir}"/*; do + pushd $d >/dev/null + pkgname=($(. PKGBUILD; echo ${pkgname[@]})) + pkgarch=($(. PKGBUILD; echo ${arch[@]})) + pkgversion=$(. PKGBUILD; echo ${pkgver}-${pkgrel}) + + build=true + for a in ${pkgarch[@]}; do + for p in ${pkgname[@]}; do + [ ! -f ${p}-${pkgversion}-${a}${PKGEXT} ] && build=false + done + done + + if ! ${build}; then + if [ "${pkgarch[0]}" == 'any' ]; then + extra-x86_64-build || die 'extra-x86_64-build failed' + else + for a in ${pkgarch[@]}; do + extra-${a}-build || die "extra-${a}-build failed" + done + fi + for a in ${pkgarch[@]}; do + for p in ${pkgname[@]}; do + cp ${p}-${pkgversion}-${a}${PKGEXT} ${curdir}/packages/$(basename ${d}) + done + done + fi popd >/dev/null done echo diff --git a/test/lib/makepkg-i686.conf b/test/lib/makepkg-i686.conf deleted file mode 100644 index 553f943..0000000 --- a/test/lib/makepkg-i686.conf +++ /dev/null @@ -1,115 +0,0 @@ -# -# /etc/makepkg.conf -# - -######################################################################### -# SOURCE ACQUISITION -######################################################################### -# -#-- The download utilities that makepkg should use to acquire sources -# Format: 'protocol::agent' -DLAGENTS=('ftp::/usr/bin/wget -c --passive-ftp -t 3 --waitretry=3 -O %o %u' - 'http::/usr/bin/wget -c -t 3 --waitretry=3 -O %o %u' - 'https::/usr/bin/wget -c -t 3 --waitretry=3 --no-check-certificate -O %o %u' - 'rsync::/usr/bin/rsync -z %u %o' - 'scp::/usr/bin/scp -C %u %o') - -# Other common tools: -# /usr/bin/snarf -# /usr/bin/lftpget -c -# /usr/bin/curl - -######################################################################### -# ARCHITECTURE, COMPILE FLAGS -######################################################################### -# -CARCH="i686" -CHOST="i686-pc-linux-gnu" - -#-- Exclusive: will only run on i686 -# -march (or -mcpu) builds exclusively for an architecture -# -mtune optimizes for an architecture, but builds for whole processor family -CFLAGS="-march=i686 -mtune=generic -O2 -pipe" -CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe" -LDFLAGS="-Wl,--hash-style=gnu -Wl,--as-needed" -#-- Make Flags: change this for DistCC/SMP systems -#MAKEFLAGS="-j2" - -######################################################################### -# BUILD ENVIRONMENT -######################################################################### -# -# Defaults: BUILDENV=(fakeroot !distcc color !ccache) -# A negated environment option will do the opposite of the comments below. -# -#-- fakeroot: Allow building packages as a non-root user -#-- distcc: Use the Distributed C/C++/ObjC compiler -#-- color: Colorize output messages -#-- ccache: Use ccache to cache compilation -# -BUILDENV=(fakeroot !distcc color !ccache) -# -#-- If using DistCC, your MAKEFLAGS will also need modification. In addition, -#-- specify a space-delimited list of hosts running in the DistCC cluster. -#DISTCC_HOSTS="" - -######################################################################### -# GLOBAL PACKAGE OPTIONS -# These are default values for the options=() settings -######################################################################### -# -# Default: OPTIONS=(strip docs libtool emptydirs zipman purge) -# A negated option will do the opposite of the comments below. -# -#-- strip: Strip symbols from binaries/libraries in STRIP_DIRS -#-- docs: Save doc directories specified by DOC_DIRS -#-- libtool: Leave libtool (.la) files in packages -#-- emptydirs: Leave empty directories in packages -#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip -#-- purge: Remove files specified by PURGE_TARGETS -# -OPTIONS=(strip docs libtool emptydirs zipman purge) - -#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512 -INTEGRITY_CHECK=(md5) -#-- Options to be used when stripping binaries. See `man strip' for details. -STRIP_BINARIES="--strip-all" -#-- Options to be used when stripping shared libraries. See `man strip' for details. -STRIP_SHARED="--strip-unneeded" -#-- Options to be used when stripping static libraries. See `man strip' for details. -STRIP_STATIC="--strip-debug" -#-- Manual (man and info) directories to compress (if zipman is specified) -MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info}) -#-- Doc directories to remove (if !docs is specified) -DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) -#-- Directories to be searched for the strip option (if strip is specified) -STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}} opt/*/{bin,lib,sbin}) -#-- Files to be removed from all packages (if purge is specified) -PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod) - -######################################################################### -# PACKAGE OUTPUT -######################################################################### -# -# Default: put built package and cached source in build directory -# -#-- Destination: specify a fixed directory where all packages will be placed -#PKGDEST=/home/packages -#-- Source cache: specify a fixed directory where source files will be cached -#SRCDEST=/home/sources -#-- Source packages: specify a fixed directory where all src packages will be placed -#SRCPKGDEST=/home/srcpackages -#-- Packager: name/email of the person or organization building packages -#PACKAGER="John Doe " - -######################################################################### -# EXTENSION DEFAULTS -######################################################################### -# -# WARNING: Do NOT modify these variables unless you know what you are -# doing. -# -PKGEXT='.pkg.tar.xz' -SRCEXT='.src.tar.gz' - -# vim: set ft=sh ts=2 sw=2 et: diff --git a/test/lib/makepkg-x86_64.conf b/test/lib/makepkg-x86_64.conf deleted file mode 100644 index e53375f..0000000 --- a/test/lib/makepkg-x86_64.conf +++ /dev/null @@ -1,115 +0,0 @@ -# -# /etc/makepkg.conf -# - -######################################################################### -# SOURCE ACQUISITION -######################################################################### -# -#-- The download utilities that makepkg should use to acquire sources -# Format: 'protocol::agent' -DLAGENTS=('ftp::/usr/bin/wget -c --passive-ftp -t 3 --waitretry=3 -O %o %u' - 'http::/usr/bin/wget -c -t 3 --waitretry=3 -O %o %u' - 'https::/usr/bin/wget -c -t 3 --waitretry=3 --no-check-certificate -O %o %u' - 'rsync::/usr/bin/rsync -z %u %o' - 'scp::/usr/bin/scp -C %u %o') - -# Other common tools: -# /usr/bin/snarf -# /usr/bin/lftpget -c -# /usr/bin/curl - -######################################################################### -# ARCHITECTURE, COMPILE FLAGS -######################################################################### -# -CARCH="x86_64" -CHOST="x86_64-unknown-linux-gnu" - -#-- Exclusive: will only run on x86_64 -# -march (or -mcpu) builds exclusively for an architecture -# -mtune optimizes for an architecture, but builds for whole processor family -CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe" -CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe" -LDFLAGS="-Wl,--hash-style=gnu -Wl,--as-needed" -#-- Make Flags: change this for DistCC/SMP systems -#MAKEFLAGS="-j2" - -######################################################################### -# BUILD ENVIRONMENT -######################################################################### -# -# Defaults: BUILDENV=(fakeroot !distcc color !ccache) -# A negated environment option will do the opposite of the comments below. -# -#-- fakeroot: Allow building packages as a non-root user -#-- distcc: Use the Distributed C/C++/ObjC compiler -#-- color: Colorize output messages -#-- ccache: Use ccache to cache compilation -# -BUILDENV=(fakeroot !distcc color !ccache) -# -#-- If using DistCC, your MAKEFLAGS will also need modification. In addition, -#-- specify a space-delimited list of hosts running in the DistCC cluster. -#DISTCC_HOSTS="" - -######################################################################### -# GLOBAL PACKAGE OPTIONS -# These are default values for the options=() settings -######################################################################### -# -# Default: OPTIONS=(strip docs libtool emptydirs zipman purge) -# A negated option will do the opposite of the comments below. -# -#-- strip: Strip symbols from binaries/libraries in STRIP_DIRS -#-- docs: Save doc directories specified by DOC_DIRS -#-- libtool: Leave libtool (.la) files in packages -#-- emptydirs: Leave empty directories in packages -#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip -#-- purge: Remove files specified by PURGE_TARGETS -# -OPTIONS=(strip docs libtool emptydirs zipman purge) - -#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512 -INTEGRITY_CHECK=(md5) -#-- Options to be used when stripping binaries. See `man strip' for details. -STRIP_BINARIES="--strip-all" -#-- Options to be used when stripping shared libraries. See `man strip' for details. -STRIP_SHARED="--strip-unneeded" -#-- Options to be used when stripping static libraries. See `man strip' for details. -STRIP_STATIC="--strip-debug" -#-- Manual (man and info) directories to compress (if zipman is specified) -MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info}) -#-- Doc directories to remove (if !docs is specified) -DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) -#-- Directories to be searched for the strip option (if strip is specified) -STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}} opt/*/{bin,lib,sbin}) -#-- Files to be removed from all packages (if purge is specified) -PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod) - -######################################################################### -# PACKAGE OUTPUT -######################################################################### -# -# Default: put built package and cached source in build directory -# -#-- Destination: specify a fixed directory where all packages will be placed -#PKGDEST=/home/packages -#-- Source cache: specify a fixed directory where source files will be cached -#SRCDEST=/home/sources -#-- Source packages: specify a fixed directory where all src packages will be placed -#SRCPKGDEST=/home/srcpackages -#-- Packager: name/email of the person or organization building packages -#PACKAGER="John Doe " - -######################################################################### -# EXTENSION DEFAULTS -######################################################################### -# -# WARNING: Do NOT modify these variables unless you know what you are -# doing. -# -PKGEXT='.pkg.tar.xz' -SRCEXT='.src.tar.gz' - -# vim: set ft=sh ts=2 sw=2 et: diff --git a/test/packages/pkg-any-a/PKGBUILD b/test/packages/pkg-any-a/PKGBUILD index 348bc4b..8749a35 100644 --- a/test/packages/pkg-any-a/PKGBUILD +++ b/test/packages/pkg-any-a/PKGBUILD @@ -7,5 +7,6 @@ url='http://www.archlinux.org/' license=('GPL') package() { - true + install -d -m755 ${pkgdir}/usr/share/${pkgname} + echo 'test' > ${pkgdir}/usr/share/${pkgname}/test } diff --git a/test/packages/pkg-any-b/PKGBUILD b/test/packages/pkg-any-b/PKGBUILD index fd42748..e6a0498 100644 --- a/test/packages/pkg-any-b/PKGBUILD +++ b/test/packages/pkg-any-b/PKGBUILD @@ -7,5 +7,6 @@ url='http://www.archlinux.org/' license=('GPL') package() { - true + install -d -m755 ${pkgdir}/usr/share/${pkgname} + echo 'test' > ${pkgdir}/usr/share/${pkgname}/test } diff --git a/test/packages/pkg-simple-a/Makefile b/test/packages/pkg-simple-a/Makefile new file mode 120000 index 0000000..50be211 --- /dev/null +++ b/test/packages/pkg-simple-a/Makefile @@ -0,0 +1 @@ +../../src/Makefile \ No newline at end of file diff --git a/test/packages/pkg-simple-a/PKGBUILD b/test/packages/pkg-simple-a/PKGBUILD index 78f3c8e..953ecfa 100644 --- a/test/packages/pkg-simple-a/PKGBUILD +++ b/test/packages/pkg-simple-a/PKGBUILD @@ -5,7 +5,18 @@ pkgdesc="A package called ${pkgname}" arch=('i686' 'x86_64') url='http://www.archlinux.org/' license=('GPL') +depends=('glibc') +makedepends=('gcc') +source=('Makefile' 'test.c') +md5sums=('c6cb8dcc86253355fed559416d0c8dcf' + '3c1e4279feb678fd9cabaccdb28e40d0') + +build() { + cd ${srcdir} + make +} package() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname} } diff --git a/test/packages/pkg-simple-a/test.c b/test/packages/pkg-simple-a/test.c new file mode 120000 index 0000000..ed5b5ac --- /dev/null +++ b/test/packages/pkg-simple-a/test.c @@ -0,0 +1 @@ +../../src/test.c \ No newline at end of file diff --git a/test/packages/pkg-simple-b/Makefile b/test/packages/pkg-simple-b/Makefile new file mode 120000 index 0000000..50be211 --- /dev/null +++ b/test/packages/pkg-simple-b/Makefile @@ -0,0 +1 @@ +../../src/Makefile \ No newline at end of file diff --git a/test/packages/pkg-simple-b/PKGBUILD b/test/packages/pkg-simple-b/PKGBUILD index 1ef298e..95ffd09 100644 --- a/test/packages/pkg-simple-b/PKGBUILD +++ b/test/packages/pkg-simple-b/PKGBUILD @@ -5,7 +5,18 @@ pkgdesc="A package called ${pkgname}" arch=('i686' 'x86_64') url='http://www.archlinux.org/' license=('GPL') +depends=('glibc') +makedepends=('gcc') +source=('Makefile' 'test.c') +md5sums=('c6cb8dcc86253355fed559416d0c8dcf' + '3c1e4279feb678fd9cabaccdb28e40d0') + +build() { + cd ${srcdir} + make +} package() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname} } diff --git a/test/packages/pkg-simple-b/test.c b/test/packages/pkg-simple-b/test.c new file mode 120000 index 0000000..ed5b5ac --- /dev/null +++ b/test/packages/pkg-simple-b/test.c @@ -0,0 +1 @@ +../../src/test.c \ No newline at end of file diff --git a/test/packages/pkg-split-a/Makefile b/test/packages/pkg-split-a/Makefile new file mode 120000 index 0000000..50be211 --- /dev/null +++ b/test/packages/pkg-split-a/Makefile @@ -0,0 +1 @@ +../../src/Makefile \ No newline at end of file diff --git a/test/packages/pkg-split-a/PKGBUILD b/test/packages/pkg-split-a/PKGBUILD index 6ac77ea..e941976 100644 --- a/test/packages/pkg-split-a/PKGBUILD +++ b/test/packages/pkg-split-a/PKGBUILD @@ -6,11 +6,23 @@ pkgdesc="A split package called ${pkgbase}" arch=('i686' 'x86_64') url='http://www.archlinux.org/' license=('GPL') +depends=('glibc') +makedepends=('gcc') +source=('Makefile' 'test.c') +md5sums=('c6cb8dcc86253355fed559416d0c8dcf' + '3c1e4279feb678fd9cabaccdb28e40d0') + +build() { + cd ${srcdir} + make +} package_pkg-split-a1() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname[0]} } package_pkg-split-a2() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname[1]} } diff --git a/test/packages/pkg-split-a/test.c b/test/packages/pkg-split-a/test.c new file mode 120000 index 0000000..ed5b5ac --- /dev/null +++ b/test/packages/pkg-split-a/test.c @@ -0,0 +1 @@ +../../src/test.c \ No newline at end of file diff --git a/test/packages/pkg-split-b/Makefile b/test/packages/pkg-split-b/Makefile new file mode 120000 index 0000000..50be211 --- /dev/null +++ b/test/packages/pkg-split-b/Makefile @@ -0,0 +1 @@ +../../src/Makefile \ No newline at end of file diff --git a/test/packages/pkg-split-b/PKGBUILD b/test/packages/pkg-split-b/PKGBUILD index e1817b7..6ddbc45 100644 --- a/test/packages/pkg-split-b/PKGBUILD +++ b/test/packages/pkg-split-b/PKGBUILD @@ -7,10 +7,23 @@ arch=('i686' 'x86_64') url='http://www.archlinux.org/' license=('GPL') +depends=('glibc') +makedepends=('gcc') +source=('Makefile' 'test.c') +md5sums=('c6cb8dcc86253355fed559416d0c8dcf' + '3c1e4279feb678fd9cabaccdb28e40d0') + +build() { + cd ${srcdir} + make +} + package_pkg-split-b1() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname[0]} } package_pkg-split-b2() { - true + cd ${srcdir} + make install DESTDIR=${pkgdir} DESTBIN=${pkgname[1]} } diff --git a/test/packages/pkg-split-b/test.c b/test/packages/pkg-split-b/test.c new file mode 120000 index 0000000..ed5b5ac --- /dev/null +++ b/test/packages/pkg-split-b/test.c @@ -0,0 +1 @@ +../../src/test.c \ No newline at end of file diff --git a/test/runTest b/test/runTest index f438704..0fcdf18 100755 --- a/test/runTest +++ b/test/runTest @@ -8,12 +8,8 @@ curdir=$(readlink -e $(dirname $0)) # testPackages() { - local p - for p in "${pkgdir}"/*; do - pushd $p >/dev/null - namcap *.pkg.tar.* || fail 'namcap failed' - popd >/dev/null - done + # TODO: namcap -r depends fails with i686 packages + find "${pkgdir}" -name "*${PKGEXT}" -exec namcap -e depends {} + || fail 'namcap failed' } @@ -94,7 +90,7 @@ testUpdateAnyPackage() { pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD svn commit -q -m"update pkg to pkgrel=2" >/dev/null - makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 + extra-i686-build >/dev/null 2>&1 mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" popd >/dev/null @@ -103,7 +99,7 @@ testUpdateAnyPackage() { checkAnyPackage extra pkg-any-a-1-2-any.pkg.tar.xz any - rm "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" } testUpdateAnyPackageToDifferentRepositoriesAtOnce() { @@ -112,7 +108,7 @@ testUpdateAnyPackageToDifferentRepositoriesAtOnce() { pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD svn commit -q -m"update pkg to pkgrel=2" >/dev/null - makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 + extra-i686-build >/dev/null 2>&1 mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" popd >/dev/null @@ -123,7 +119,7 @@ testUpdateAnyPackageToDifferentRepositoriesAtOnce() { checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz any checkAnyPackage testing pkg-any-a-1-2-any.pkg.tar.xz any - rm "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" } testUpdateSameAnyPackageToDifferentRepositories() { @@ -279,13 +275,13 @@ testTesting2xAnyPackage() { pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD svn commit -q -m"update pkg to pkgrel=2" >/dev/null - makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 + extra-i686-build >/dev/null 2>&1 mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" popd >/dev/null releasePackage testing pkg-any-a any ../db-update - rm "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" ../testing2x pkg-any-a @@ -449,13 +445,13 @@ testUpdateAnyPackageWithoutPool() { pushd "${TMP}/svn-packages-copy/${pkgname}/trunk/" >/dev/null sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD svn commit -q -m"update pkg to pkgrel=2" >/dev/null - makepkg -cf --config ${curdir}/lib/makepkg-i686.conf >/dev/null 2>&1 + extra-i686-build >/dev/null 2>&1 mv "${pkg2}" "${pkgdir}/${pkgname}/" popd >/dev/null releasePackage extra ${pkgname} any ../db-update - rm "${pkgdir}/${pkgname}/${pkg2}" + rm -f "${pkgdir}/${pkgname}/${pkg2}" ../cron-jobs/ftpdir-cleanup >/dev/null diff --git a/test/src/Makefile b/test/src/Makefile new file mode 100644 index 0000000..105b730 --- /dev/null +++ b/test/src/Makefile @@ -0,0 +1,5 @@ +all: + gcc $(CFLAGS) -o test test.c + +install: + install -D -m755 test $(DESTDIR)/usr/bin/$(DESTBIN) diff --git a/test/src/test.c b/test/src/test.c new file mode 100644 index 0000000..a661689 --- /dev/null +++ b/test/src/test.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + printf("Arch is the best!\n"); + return EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf From 793d78130ba808ee688c8b7139a2bc6180b29534 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 25 Nov 2010 08:18:26 +0100 Subject: Split tests into several files * tests can be run seperatly * runTest will run all tests that have the x bit set --- test/lib/common.inc | 17 +- test/runTest | 628 +---------------------------------------- test/test.d/db-move.sh | 76 +++++ test/test.d/db-remove.sh | 52 ++++ test/test.d/db-update.sh | 127 +++++++++ test/test.d/ftpdir-cleanup.sh | 93 ++++++ test/test.d/packages.sh | 11 + test/test.d/pool-transition.sh | 152 ++++++++++ test/test.d/sourceballs.sh | 85 ++++++ test/test.d/testing2x.sh | 27 ++ 10 files changed, 644 insertions(+), 624 deletions(-) create mode 100755 test/test.d/db-move.sh create mode 100755 test/test.d/db-remove.sh create mode 100755 test/test.d/db-update.sh create mode 100755 test/test.d/ftpdir-cleanup.sh create mode 100755 test/test.d/packages.sh create mode 100755 test/test.d/pool-transition.sh create mode 100755 test/test.d/sourceballs.sh create mode 100755 test/test.d/testing2x.sh (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index 34de9eb..ba5d685 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,7 +1,7 @@ set -E -. "${curdir}/../config" -. "${curdir}/../db-functions" +. "$(dirname ${BASH_SOURCE[0]})/../../config" +. "$(dirname ${BASH_SOURCE[0]})/../../db-functions" oneTimeSetUp() { local p @@ -12,7 +12,7 @@ oneTimeSetUp() { local pkgversion local build pkgdir="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" - cp -r ${curdir}/packages/* "${pkgdir}" + cp -r $(dirname ${BASH_SOURCE[0]})/../packages/* "${pkgdir}" msg 'Building packages...' for d in "${pkgdir}"/*; do pushd $d >/dev/null @@ -37,13 +37,12 @@ oneTimeSetUp() { fi for a in ${pkgarch[@]}; do for p in ${pkgname[@]}; do - cp ${p}-${pkgversion}-${a}${PKGEXT} ${curdir}/packages/$(basename ${d}) + cp ${p}-${pkgversion}-${a}${PKGEXT} $(dirname ${BASH_SOURCE[0]})/../packages/$(basename ${d}) done done fi popd >/dev/null done - echo } oneTimeTearDown() { @@ -56,7 +55,7 @@ setUp() { local r local a - [ -f "${curdir}/../config.local" ] && die "${curdir}/../config.local exists" + [ -f "$(dirname ${BASH_SOURCE[0]})/../../config.local" ] && die "$(dirname ${BASH_SOURCE[0]})/../../config.local exists" TMP="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #msg "Using ${TMP}" @@ -85,7 +84,7 @@ setUp() { svn commit -q -m"initial commit of ${pkg}" "${TMP}/svn-packages-copy" done - cat < "${curdir}/../config.local" + cat < "$(dirname ${BASH_SOURCE[0]})/../../config.local" FTP_BASE="${TMP}/ftp" SVNREPO="file://${TMP}/svn-packages-repo" PKGREPOS=(${PKGREPOS[@]}) @@ -97,12 +96,12 @@ setUp() { CLEANUP_DRYRUN=false SOURCE_CLEANUP_DRYRUN=false eot - . "${curdir}/../config" + . "$(dirname ${BASH_SOURCE[0]})/../../config" } tearDown() { rm -rf "${TMP}" - rm -f "${curdir}/../config.local" + rm -f "$(dirname ${BASH_SOURCE[0]})/../../config.local" echo } diff --git a/test/runTest b/test/runTest index 0fcdf18..b8713d8 100755 --- a/test/runTest +++ b/test/runTest @@ -1,617 +1,15 @@ #!/bin/bash -curdir=$(readlink -e $(dirname $0)) -. "${curdir}/lib/common.inc" - -# -# self test -# - -testPackages() { - # TODO: namcap -r depends fails with i686 packages - find "${pkgdir}" -name "*${PKGEXT}" -exec namcap -e depends {} + || fail 'namcap failed' -} - - -# -# db-update -# - -testAddSimplePackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - checkPackage extra ${pkgbase}-1-1-${arch}.pkg.tar.xz ${arch} - done - done -} - -testAddSingleSimplePackage() { - releasePackage extra 'pkg-simple-a' 'i686' - ../db-update - checkPackage extra 'pkg-simple-a-1-1-i686.pkg.tar.xz' 'i686' -} - -testAddAnyPackages() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - - for pkgbase in ${pkgs[@]}; do - releasePackage extra ${pkgbase} any - done - - ../db-update - - for pkgbase in ${pkgs[@]}; do - checkAnyPackage extra ${pkgbase}-1-1-any.pkg.tar.xz - done -} - -testAddSplitPackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-split-a' 'pkg-split-b') - local pkg - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - for pkg in "${pkgdir}/${pkgbase}"/*-${arch}.pkg.tar.*; do - checkPackage extra $(basename ${pkg}) ${arch} - done - done - done -} - -testUpdateAnyPackage() { - releasePackage extra pkg-any-a any - ../db-update - - pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null - sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD - svn commit -q -m"update pkg to pkgrel=2" >/dev/null - extra-i686-build >/dev/null 2>&1 - mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" - popd >/dev/null - - releasePackage extra pkg-any-a any - ../db-update - - checkAnyPackage extra pkg-any-a-1-2-any.pkg.tar.xz any - - rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" -} - -testUpdateAnyPackageToDifferentRepositoriesAtOnce() { - releasePackage extra pkg-any-a any - - pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null - sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD - svn commit -q -m"update pkg to pkgrel=2" >/dev/null - extra-i686-build >/dev/null 2>&1 - mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" - popd >/dev/null - - releasePackage testing pkg-any-a any - - ../db-update - - checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz any - checkAnyPackage testing pkg-any-a-1-2-any.pkg.tar.xz any - - rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" -} - -testUpdateSameAnyPackageToDifferentRepositories() { - releasePackage extra pkg-any-a any - ../db-update - checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz any - - releasePackage testing pkg-any-a any - ../db-update >/dev/null 2>&1 && (fail 'Adding an existing package to another repository should fail'; return 1) - - local arch - for arch in i686 x86_64; do - ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ - && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase}) \ - && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" - done -} - -# -# db-remove -# - -testRemovePackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - ../db-remove ${pkgbase} extra ${arch} - done - done - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - checkRemovedPackage extra ${pkgbase} ${arch} - done - done -} - -testRemoveAnyPackages() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - - for pkgbase in ${pkgs[@]}; do - releasePackage extra ${pkgbase} any - done - - ../db-update - - for pkgbase in ${pkgs[@]}; do - ../db-remove ${pkgbase} extra any - done - - for pkgbase in ${pkgs[@]}; do - checkRemovedAnyPackage extra ${pkgbase} - done -} - - -# -# db-move -# - -testMoveSimplePackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage testing ${pkgbase} ${arch} - done - done - - ../db-update - - ../db-move testing extra pkg-simple-a - - for arch in ${arches[@]}; do - checkPackage extra pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} - checkRemovedPackage testing pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} - - checkPackage testing pkg-simple-b-1-1-${arch}.pkg.tar.xz ${arch} - done -} - -testMoveAnyPackages() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - - for pkgbase in ${pkgs[@]}; do - releasePackage testing ${pkgbase} any - done - - ../db-update - ../db-move testing extra pkg-any-a - - checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz - checkRemovedAnyPackage testing pkg-any-a - checkAnyPackage testing pkg-any-b-1-1-any.pkg.tar.xz -} - -testMoveSplitPackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-split-a' 'pkg-split-b') - local pkg - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage testing ${pkgbase} ${arch} - done - done - - ../db-update - ../db-move testing extra pkg-split-a - - for arch in ${arches[@]}; do - for pkg in "${pkgdir}/pkg-split-a"/*-${arch}.pkg.tar.*; do - checkPackage extra $(basename ${pkg}) ${arch} - done - done - for arch in ${arches[@]}; do - for pkg in "${pkgdir}/pkg-split-b"/*-${arch}.pkg.tar.*; do - checkPackage testing $(basename ${pkg}) ${arch} - done - done - - checkRemovedAnyPackage testing pkg-split-a -} - - -# -# testing2x -# - -testTesting2xAnyPackage() { - releasePackage core pkg-any-a any - ../db-update - - pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null - sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD - svn commit -q -m"update pkg to pkgrel=2" >/dev/null - extra-i686-build >/dev/null 2>&1 - mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" - popd >/dev/null - - releasePackage testing pkg-any-a any - ../db-update - rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" - - ../testing2x pkg-any-a - - checkAnyPackage core pkg-any-a-1-2-any.pkg.tar.xz any - checkRemovedAnyPackage testing pkg-any-a -} - - -# -# ftpdir-cleanup -# - -testCleanupSimplePackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - for arch in ${arches[@]}; do - ../db-remove pkg-simple-a extra ${arch} - done - - ../cron-jobs/ftpdir-cleanup >/dev/null - - for arch in ${arches[@]}; do - local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" - checkRemovedPackage extra 'pkg-simple-a' ${arch} - [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" - [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" - - local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz" - checkPackage extra ${pkg2} ${arch} - done -} - -testCleanupAnyPackages() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - local arch='any' - - for pkgbase in ${pkgs[@]}; do - releasePackage extra ${pkgbase} any - done - - ../db-update - ../db-remove pkg-any-a extra any - ../cron-jobs/ftpdir-cleanup >/dev/null - - local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' - checkRemovedAnyPackage extra 'pkg-any-a' - [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" - [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" - - local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz" - checkAnyPackage extra ${pkg2} -} - -testCleanupSplitPackages() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-split-a' 'pkg-split-b') - local pkg - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - for arch in ${arches[@]}; do - ../db-remove ${pkgs[0]} extra ${arch} - done - - ../cron-jobs/ftpdir-cleanup >/dev/null - - for arch in ${arches[@]}; do - for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do - checkRemovedPackage extra ${pkgs[0]} ${arch} - [ -f "${FTP_BASE}/${PKGPOOL}/${pkg}" ] && fail "${PKGPOOL}/${pkg} found" - [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] && fail "${repo}/os/${arch}/${pkg} found" - done - - for pkg in "${pkgdir}/${pkgs[1]}"/*-${arch}.pkg.tar.*; do - checkPackage extra $(basename ${pkg}) ${arch} - done - done -} - -# -# transition tests -# - -testMovePackagesWithoutPool() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') - local pkgbase - local arch - local pkg - local old - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage testing ${pkgbase} ${arch} - done - done - - ../db-update - - # transform two packages to old style layout - for arch in ${arches[@]}; do - for old in 0 2; do - for pkg in "${pkgdir}/${pkgs[${old}]}"/*-${arch}.pkg.tar.*; do - pkg=$(basename $pkg) - mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" - done - done - done - - ../cron-jobs/ftpdir-cleanup >/dev/null - - ../db-move testing extra ${pkgs[@]} - - ../cron-jobs/ftpdir-cleanup >/dev/null - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - for pkg in "${pkgdir}/${pkgbase}"/*-${arch}.pkg.tar.*; do - checkPackage extra $(basename ${pkg}) ${arch} - done - checkRemovedPackage testing ${pkgbase} ${arch} - done - done -} - -testUpdateAnyPackageWithoutPool() { - local pkgname='pkg-any-a' - local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' - local pkg2='pkg-any-a-1-2-any.pkg.tar.xz' - local arch - - - releasePackage extra pkg-any-a any - ../db-update - # transform two packages to old style layout - mv -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" "${FTP_BASE}/extra/os/any" - for arch in i686 x86_64; do - ln -sf "../any/${pkg1}" "${FTP_BASE}/extra/os/${arch}" - done - - pushd "${TMP}/svn-packages-copy/${pkgname}/trunk/" >/dev/null - sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD - svn commit -q -m"update pkg to pkgrel=2" >/dev/null - extra-i686-build >/dev/null 2>&1 - mv "${pkg2}" "${pkgdir}/${pkgname}/" - popd >/dev/null - - releasePackage extra ${pkgname} any - ../db-update - rm -f "${pkgdir}/${pkgname}/${pkg2}" - - ../cron-jobs/ftpdir-cleanup >/dev/null - - checkAnyPackage extra "${pkg2}" - - [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" - for arch in any i686 x86_64; do - [ -f "${FTP_BASE}/extra/os/${arch}/${pkg1}" ] && fail "extra/os/${arch}/${pkg1} found" - done -} - -testMoveAnyPackagesWithoutPool() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - local arch - local pkg - - for pkgbase in ${pkgs[@]}; do - releasePackage testing ${pkgbase} any - done - - ../db-update - - # transform a package to old style layout - for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do - pkg=$(basename $pkg) - mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" - for arch in i686 x86_64; do - ln -sf "../any/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" - done - done - - ../cron-jobs/ftpdir-cleanup >/dev/null - - ../db-move testing extra ${pkgs[@]} - - ../cron-jobs/ftpdir-cleanup >/dev/null - - for pkgbase in ${pkgs[@]}; do - for pkg in "${pkgdir}/${pkgbase}"/*-any.pkg.tar.*; do - checkAnyPackage extra $(basename ${pkg}) - done - checkRemovedAnyPackage testing ${pkgbase} - done - - for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do - pkg=$(basename $pkg) - for arch in any i686 x86_64; do - [ -f "${FTP_BASE}/testing/os/${arch}/${pkg}" ] && fail "testing/os/${arch}/${pkg} found" - done - done -} - -testUpdateSameAnyPackageToDifferentRepositoriesWithoutPool() { - local pkg - local arch - - releasePackage extra pkg-any-a any - ../db-update - - # transform a package to old style layout - for pkg in "${pkgdir}/pkg-any-a"/*-any.pkg.tar.*; do - pkg=$(basename $pkg) - mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/extra/os/any/${pkg}" - for arch in i686 x86_64; do - ln -sf "../any/${pkg}" "${FTP_BASE}/extra/os/${arch}/${pkg}" - done - done - - releasePackage testing pkg-any-a any - ../db-update >/dev/null 2>&1 && (fail 'Adding an existing package to another repository should fail'; return 1) - - for arch in i686 x86_64; do - ( [ -r "${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" ] \ - && bsdtar -xf "${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" -O | grep -q pkg-any-a) \ - && fail "pkg-any-a should not be in testing/os/${arch}/testing${DBEXT%.tar.*}" - done -} - -# -#sourceballs tests -# - -testSourceballs() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - ../db-update - - ../cron-jobs/sourceballs - for pkgbase in ${pkgs[@]}; do - [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" - done -} - -testAnySourceballs() { - local pkgs=('pkg-any-a' 'pkg-any-b') - local pkgbase - - for pkgbase in ${pkgs[@]}; do - releasePackage extra ${pkgbase} any - done - ../db-update - - ../cron-jobs/sourceballs - for pkgbase in ${pkgs[@]}; do - [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" - done -} - -testSplitSourceballs() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-split-a' 'pkg-split-b') - local pkg - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - - ../db-update - - ../cron-jobs/sourceballs - for pkgbase in ${pkgs[@]}; do - [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" - done -} - -testSourceballsCleanup() { - local arches=('i686' 'x86_64') - local pkgs=('pkg-simple-a' 'pkg-simple-b') - local pkgbase - local arch - - for pkgbase in ${pkgs[@]}; do - for arch in ${arches[@]}; do - releasePackage extra ${pkgbase} ${arch} - done - done - ../db-update - ../cron-jobs/sourceballs - - for arch in ${arches[@]}; do - ../db-remove pkg-simple-a extra ${arch} - done - ../cron-jobs/ftpdir-cleanup >/dev/null - - ../cron-jobs/sourceballs - [ -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-a-*${SRCEXT} ] && fail "source package was not removed!" - [ ! -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-b-*${SRCEXT} ] && fail "source package not found!" -} - -. "${curdir}/lib/shunit2" +. "$(dirname ${BASH_SOURCE[0]})/lib/common.inc" + +for t in "$(dirname ${BASH_SOURCE[0]})/test.d/"*.sh; do + l=$(basename ${t} .sh) + if [ -x ${t} ]; then + msg "Running test '${l}'" + ${t} + [ $? -ne 0 ] && die "Test '${l}' failed" + echo -e "\n\n\n" + else + warning "Skipping test ${l}" + fi +done diff --git a/test/test.d/db-move.sh b/test/test.d/db-move.sh new file mode 100755 index 0000000..57cbf71 --- /dev/null +++ b/test/test.d/db-move.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testMoveSimplePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage testing ${pkgbase} ${arch} + done + done + + ../db-update + + ../db-move testing extra pkg-simple-a + + for arch in ${arches[@]}; do + checkPackage extra pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} + checkRemovedPackage testing pkg-simple-a-1-1-${arch}.pkg.tar.xz ${arch} + + checkPackage testing pkg-simple-b-1-1-${arch}.pkg.tar.xz ${arch} + done +} + +testMoveAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + releasePackage testing ${pkgbase} any + done + + ../db-update + ../db-move testing extra pkg-any-a + + checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz + checkRemovedAnyPackage testing pkg-any-a + checkAnyPackage testing pkg-any-b-1-1-any.pkg.tar.xz +} + +testMoveSplitPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage testing ${pkgbase} ${arch} + done + done + + ../db-update + ../db-move testing extra pkg-split-a + + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/pkg-split-a"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + done + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/pkg-split-b"/*-${arch}.pkg.tar.*; do + checkPackage testing $(basename ${pkg}) ${arch} + done + done + + checkRemovedAnyPackage testing pkg-split-a +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-remove.sh b/test/test.d/db-remove.sh new file mode 100755 index 0000000..b66466d --- /dev/null +++ b/test/test.d/db-remove.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testRemovePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + ../db-remove ${pkgbase} extra ${arch} + done + done + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + checkRemovedPackage extra ${pkgbase} ${arch} + done + done +} + +testRemoveAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + + ../db-update + + for pkgbase in ${pkgs[@]}; do + ../db-remove ${pkgbase} extra any + done + + for pkgbase in ${pkgs[@]}; do + checkRemovedAnyPackage extra ${pkgbase} + done +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-update.sh b/test/test.d/db-update.sh new file mode 100755 index 0000000..3c41b39 --- /dev/null +++ b/test/test.d/db-update.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testAddSimplePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + checkPackage extra ${pkgbase}-1-1-${arch}.pkg.tar.xz ${arch} + done + done +} + +testAddSingleSimplePackage() { + releasePackage extra 'pkg-simple-a' 'i686' + ../db-update + checkPackage extra 'pkg-simple-a-1-1-i686.pkg.tar.xz' 'i686' +} + +testAddAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + + ../db-update + + for pkgbase in ${pkgs[@]}; do + checkAnyPackage extra ${pkgbase}-1-1-any.pkg.tar.xz + done +} + +testAddSplitPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/${pkgbase}"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + done + done +} + +testUpdateAnyPackage() { + releasePackage extra pkg-any-a any + ../db-update + + pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null + sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD + svn commit -q -m"update pkg to pkgrel=2" >/dev/null + extra-i686-build >/dev/null 2>&1 + mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" + popd >/dev/null + + releasePackage extra pkg-any-a any + ../db-update + + checkAnyPackage extra pkg-any-a-1-2-any.pkg.tar.xz any + + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" +} + +testUpdateAnyPackageToDifferentRepositoriesAtOnce() { + releasePackage extra pkg-any-a any + + pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null + sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD + svn commit -q -m"update pkg to pkgrel=2" >/dev/null + extra-i686-build >/dev/null 2>&1 + mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" + popd >/dev/null + + releasePackage testing pkg-any-a any + + ../db-update + + checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz any + checkAnyPackage testing pkg-any-a-1-2-any.pkg.tar.xz any + + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" +} + +testUpdateSameAnyPackageToDifferentRepositories() { + releasePackage extra pkg-any-a any + ../db-update + checkAnyPackage extra pkg-any-a-1-1-any.pkg.tar.xz any + + releasePackage testing pkg-any-a any + ../db-update >/dev/null 2>&1 && (fail 'Adding an existing package to another repository should fail'; return 1) + + local arch + for arch in i686 x86_64; do + ( [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep -q ${pkgbase}) \ + && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" + done +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/ftpdir-cleanup.sh b/test/test.d/ftpdir-cleanup.sh new file mode 100755 index 0000000..e9b977b --- /dev/null +++ b/test/test.d/ftpdir-cleanup.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testCleanupSimplePackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + for arch in ${arches[@]}; do + ../db-remove pkg-simple-a extra ${arch} + done + + ../cron-jobs/ftpdir-cleanup >/dev/null + + for arch in ${arches[@]}; do + local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz" + checkRemovedPackage extra 'pkg-simple-a' ${arch} + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" + + local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz" + checkPackage extra ${pkg2} ${arch} + done +} + +testCleanupAnyPackages() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + local arch='any' + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + + ../db-update + ../db-remove pkg-any-a extra any + ../cron-jobs/ftpdir-cleanup >/dev/null + + local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' + checkRemovedAnyPackage extra 'pkg-any-a' + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ] && fail "${repo}/os/${arch}/${pkg1} found" + + local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz" + checkAnyPackage extra ${pkg2} +} + +testCleanupSplitPackages() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + for arch in ${arches[@]}; do + ../db-remove ${pkgs[0]} extra ${arch} + done + + ../cron-jobs/ftpdir-cleanup >/dev/null + + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/${pkgs[0]}"/*-${arch}.pkg.tar.*; do + checkRemovedPackage extra ${pkgs[0]} ${arch} + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg}" ] && fail "${PKGPOOL}/${pkg} found" + [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ] && fail "${repo}/os/${arch}/${pkg} found" + done + + for pkg in "${pkgdir}/${pkgs[1]}"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + done +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/packages.sh b/test/test.d/packages.sh new file mode 100755 index 0000000..324f73a --- /dev/null +++ b/test/test.d/packages.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testPackages() { + # TODO: namcap -r depends fails with i686 packages + find "${pkgdir}" -name "*${PKGEXT}" -exec namcap -e depends {} + || fail 'namcap failed' +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/pool-transition.sh b/test/test.d/pool-transition.sh new file mode 100755 index 0000000..6d82e00 --- /dev/null +++ b/test/test.d/pool-transition.sh @@ -0,0 +1,152 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testMovePackagesWithoutPool() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-split-a' 'pkg-split-b') + local pkgbase + local arch + local pkg + local old + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage testing ${pkgbase} ${arch} + done + done + + ../db-update + + # transform two packages to old style layout + for arch in ${arches[@]}; do + for old in 0 2; do + for pkg in "${pkgdir}/${pkgs[${old}]}"/*-${arch}.pkg.tar.*; do + pkg=$(basename $pkg) + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" + done + done + done + + ../cron-jobs/ftpdir-cleanup >/dev/null + + ../db-move testing extra ${pkgs[@]} + + ../cron-jobs/ftpdir-cleanup >/dev/null + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + for pkg in "${pkgdir}/${pkgbase}"/*-${arch}.pkg.tar.*; do + checkPackage extra $(basename ${pkg}) ${arch} + done + checkRemovedPackage testing ${pkgbase} ${arch} + done + done +} + +testUpdateAnyPackageWithoutPool() { + local pkgname='pkg-any-a' + local pkg1='pkg-any-a-1-1-any.pkg.tar.xz' + local pkg2='pkg-any-a-1-2-any.pkg.tar.xz' + local arch + + + releasePackage extra pkg-any-a any + ../db-update + # transform two packages to old style layout + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" "${FTP_BASE}/extra/os/any" + for arch in i686 x86_64; do + ln -sf "../any/${pkg1}" "${FTP_BASE}/extra/os/${arch}" + done + + pushd "${TMP}/svn-packages-copy/${pkgname}/trunk/" >/dev/null + sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD + svn commit -q -m"update pkg to pkgrel=2" >/dev/null + extra-i686-build >/dev/null 2>&1 + mv "${pkg2}" "${pkgdir}/${pkgname}/" + popd >/dev/null + + releasePackage extra ${pkgname} any + ../db-update + rm -f "${pkgdir}/${pkgname}/${pkg2}" + + ../cron-jobs/ftpdir-cleanup >/dev/null + + checkAnyPackage extra "${pkg2}" + + [ -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ] && fail "${PKGPOOL}/${pkg1} found" + for arch in any i686 x86_64; do + [ -f "${FTP_BASE}/extra/os/${arch}/${pkg1}" ] && fail "extra/os/${arch}/${pkg1} found" + done +} + +testMoveAnyPackagesWithoutPool() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + local arch + local pkg + + for pkgbase in ${pkgs[@]}; do + releasePackage testing ${pkgbase} any + done + + ../db-update + + # transform a package to old style layout + for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do + pkg=$(basename $pkg) + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/testing/os/any/${pkg}" + for arch in i686 x86_64; do + ln -sf "../any/${pkg}" "${FTP_BASE}/testing/os/${arch}/${pkg}" + done + done + + ../cron-jobs/ftpdir-cleanup >/dev/null + + ../db-move testing extra ${pkgs[@]} + + ../cron-jobs/ftpdir-cleanup >/dev/null + + for pkgbase in ${pkgs[@]}; do + for pkg in "${pkgdir}/${pkgbase}"/*-any.pkg.tar.*; do + checkAnyPackage extra $(basename ${pkg}) + done + checkRemovedAnyPackage testing ${pkgbase} + done + + for pkg in "${pkgdir}/${pkgs[0]}"/*-any.pkg.tar.*; do + pkg=$(basename $pkg) + for arch in any i686 x86_64; do + [ -f "${FTP_BASE}/testing/os/${arch}/${pkg}" ] && fail "testing/os/${arch}/${pkg} found" + done + done +} + +testUpdateSameAnyPackageToDifferentRepositoriesWithoutPool() { + local pkg + local arch + + releasePackage extra pkg-any-a any + ../db-update + + # transform a package to old style layout + for pkg in "${pkgdir}/pkg-any-a"/*-any.pkg.tar.*; do + pkg=$(basename $pkg) + mv -f "${FTP_BASE}/${PKGPOOL}/${pkg}" "${FTP_BASE}/extra/os/any/${pkg}" + for arch in i686 x86_64; do + ln -sf "../any/${pkg}" "${FTP_BASE}/extra/os/${arch}/${pkg}" + done + done + + releasePackage testing pkg-any-a any + ../db-update >/dev/null 2>&1 && (fail 'Adding an existing package to another repository should fail'; return 1) + + for arch in i686 x86_64; do + ( [ -r "${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" ] \ + && bsdtar -xf "${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" -O | grep -q pkg-any-a) \ + && fail "pkg-any-a should not be in testing/os/${arch}/testing${DBEXT%.tar.*}" + done +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/sourceballs.sh b/test/test.d/sourceballs.sh new file mode 100755 index 0000000..45e9b1d --- /dev/null +++ b/test/test.d/sourceballs.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testSourceballs() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + ../db-update + + ../cron-jobs/sourceballs + for pkgbase in ${pkgs[@]}; do + [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" + done +} + +testAnySourceballs() { + local pkgs=('pkg-any-a' 'pkg-any-b') + local pkgbase + + for pkgbase in ${pkgs[@]}; do + releasePackage extra ${pkgbase} any + done + ../db-update + + ../cron-jobs/sourceballs + for pkgbase in ${pkgs[@]}; do + [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" + done +} + +testSplitSourceballs() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-split-a' 'pkg-split-b') + local pkg + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + + ../db-update + + ../cron-jobs/sourceballs + for pkgbase in ${pkgs[@]}; do + [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ] && fail "source package not found!" + done +} + +testSourceballsCleanup() { + local arches=('i686' 'x86_64') + local pkgs=('pkg-simple-a' 'pkg-simple-b') + local pkgbase + local arch + + for pkgbase in ${pkgs[@]}; do + for arch in ${arches[@]}; do + releasePackage extra ${pkgbase} ${arch} + done + done + ../db-update + ../cron-jobs/sourceballs + + for arch in ${arches[@]}; do + ../db-remove pkg-simple-a extra ${arch} + done + ../cron-jobs/ftpdir-cleanup >/dev/null + + ../cron-jobs/sourceballs + [ -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-a-*${SRCEXT} ] && fail "source package was not removed!" + [ ! -r ${FTP_BASE}/${SRCPOOL}/pkg-simple-b-*${SRCEXT} ] && fail "source package not found!" +} + +. "${curdir}/../lib/shunit2" diff --git a/test/test.d/testing2x.sh b/test/test.d/testing2x.sh new file mode 100755 index 0000000..436716d --- /dev/null +++ b/test/test.d/testing2x.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +curdir=$(readlink -e $(dirname $0)) +. "${curdir}/../lib/common.inc" + +testTesting2xAnyPackage() { + releasePackage core pkg-any-a any + ../db-update + + pushd "${TMP}/svn-packages-copy/pkg-any-a/trunk/" >/dev/null + sed 's/pkgrel=1/pkgrel=2/g' -i PKGBUILD + svn commit -q -m"update pkg to pkgrel=2" >/dev/null + extra-i686-build >/dev/null 2>&1 + mv pkg-any-a-1-2-any.pkg.tar.xz "${pkgdir}/pkg-any-a/" + popd >/dev/null + + releasePackage testing pkg-any-a any + ../db-update + rm -f "${pkgdir}/pkg-any-a/pkg-any-a-1-2-any.pkg.tar.xz" + + ../testing2x pkg-any-a + + checkAnyPackage core pkg-any-a-1-2-any.pkg.tar.xz any + checkRemovedAnyPackage testing pkg-any-a +} + +. "${curdir}/../lib/shunit2" -- cgit v1.2.3-54-g00ecf From 69721f4e42fa296de2d5a568d07758888c354328 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Nov 2010 03:08:59 +0100 Subject: Fix test: copy target of symlinks --- test/lib/common.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/lib/common.inc') diff --git a/test/lib/common.inc b/test/lib/common.inc index ba5d685..208400c 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -12,7 +12,7 @@ oneTimeSetUp() { local pkgversion local build pkgdir="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" - cp -r $(dirname ${BASH_SOURCE[0]})/../packages/* "${pkgdir}" + cp -Lr $(dirname ${BASH_SOURCE[0]})/../packages/* "${pkgdir}" msg 'Building packages...' for d in "${pkgdir}"/*; do pushd $d >/dev/null @@ -79,7 +79,7 @@ setUp() { for p in "${pkgdir}"/*; do pkg=$(basename $p) mkdir -p "${TMP}/svn-packages-copy/${pkg}"/{trunk,repos} - cp "${p}/PKGBUILD" "${TMP}/svn-packages-copy"/${pkg}/trunk/ + cp "${p}"/* "${TMP}/svn-packages-copy"/${pkg}/trunk/ svn add -q "${TMP}/svn-packages-copy"/${pkg} svn commit -q -m"initial commit of ${pkg}" "${TMP}/svn-packages-copy" done -- cgit v1.2.3-54-g00ecf