set -E source "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.cfg" source "$(dirname ${BASH_SOURCE[0]})/../../share/db-functions" oneTimeSetUp() { local p local d local a local pkgname local pkgarch local pkgversion local build pkgdir="$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX)" cp -Lr $(dirname ${BASH_SOURCE[0]})/../packages/* "${pkgdir}" msg 'Building packages...' for d in "${pkgdir}"/*; do pushd $d >/dev/null pkgname=($(. PKGBUILD; echo ${pkgname[@]})) pkgarch=($(. PKGBUILD; echo ${arch[@]})) pkgversion=$(. PKGBUILD; echo $(get_full_version ${epoch:-0} ${pkgver} ${pkgrel})) build=true for a in ${pkgarch[@]}; do for p in ${pkgname[@]}; do [ ! -f ${p}-${pkgversion}-${a}${package_extension_suffixfile} ] && build=false done done if ! ${build}; then if [ "${pkgarch[0]}" == 'any' ]; then sudo extra-x86_64-build || die 'extra-x86_64-build failed' else for a in ${pkgarch[@]}; do sudo extra-${a}-build || die "extra-${a}-build failed" done fi for a in ${pkgarch[@]}; do for p in ${pkgname[@]}; do cp ${p}-${pkgversion}-${a}${package_extension_suffixfile} $(dirname ${BASH_SOURCE[0]})/../packages/$(basename ${d}) done done fi popd >/dev/null done } oneTimeTearDown() { rm -rf "${pkgdir}" } setUp() { local p local pkg local r local a [ -f "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.local.cfg" ] && die "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.local.cfg exists" temporary_directory="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #msg "Using ${temporary_directory}" native_repositories=('core' 'extra' 'testing') main_packages_pool='pool/packages' mkdir -p "${temporary_directory}/"{ftp,tmp,staging,{package,source}-cleanup,svn-packages-{copy,repo}} for r in ${native_repositories[@]}; do mkdir -p "${temporary_directory}/staging/${r}" for a in ${native_architectures[@]} any; do mkdir -p "${temporary_directory}/ftp/${r}/os/${a}" done done mkdir -p "${temporary_directory}/ftp/${main_packages_pool}" mkdir -p "${temporary_directory}/ftp/${main_sources_pool}" msg 'Creating svn repository...' svnadmin create "${temporary_directory}/svn-packages-repo" svn checkout -q "file://${temporary_directory}/svn-packages-repo" "${temporary_directory}/svn-packages-copy" for p in "${pkgdir}"/*; do pkg=$(basename $p) mkdir -p "${temporary_directory}/svn-packages-copy/${pkg}"/{trunk,repos} cp "${p}"/* "${temporary_directory}/svn-packages-copy"/${pkg}/trunk/ svn add -q "${temporary_directory}/svn-packages-copy"/${pkg} svn commit -q -m"initial commit of ${pkg}" "${temporary_directory}/svn-packages-copy" done cat < "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.local.cfg" root_dir="${temporary_directory}/ftp" SVN_repository="file://${temporary_directory}/svn-packages-repo" native_repositories=(${native_repositories[@]}) main_packages_pool="${main_packages_pool}" cleanup_destination_directory="${temporary_directory}/package-cleanup" source_cleanup_destination_directory="${temporary_directory}/source-cleanup" staging_directory="${temporary_directory}/staging" temporary_directory="${temporary_directory}/tmp" cleanup_dryrun=false source_cleanup_dryrun=false require_signature=true eot . "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.cfg" } tearDown() { rm -rf "${temporary_directory}" rm -f "$(dirname ${BASH_SOURCE[0]})/../../etc/dbscripts.local.cfg" echo } releasePackage() { local repo=$1 local pkgbase=$2 local arch=$3 pushd "${temporary_directory}/svn-packages-copy"/${pkgbase}/trunk/ >/dev/null archrelease ${repo}-${arch} >/dev/null 2&>1 pkgver=$(. PKGBUILD; echo $(get_full_version ${epoch:-0} ${pkgver} ${pkgrel})) popd >/dev/null cp "${pkgdir}/${pkgbase}"/*-${pkgver}-${arch}${package_extension_suffixfile} "${staging_directory}"/${repo}/ if ${require_signature}; then # TODO: really sign the packages with a valid key find "${staging_directory}"/${repo}/ -type f \ -name "*-${pkgver}-${arch}${package_extension_suffixfile}" \ -exec touch {}.sig \; fi } checkAnyPackageDB() { local repo=$1 local pkg=$2 local arch local db [ -r "${root_dir}/${main_packages_pool}/${pkg}" ] || fail "${main_packages_pool}/${pkg} not found" if ${require_signature}; then [ -r "${root_dir}/${main_packages_pool}/${pkg}.sig" ] || fail "${main_packages_pool}/${pkg}.sig not found" fi for arch in i686 x86_64; do [ -L "${root_dir}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} is not a symlink" [ "$(readlink -e "${root_dir}/${repo}/os/${arch}/${pkg}")" == "${root_dir}/${main_packages_pool}/${pkg}" ] \ || fail "${repo}/os/${arch}/${pkg} does not link to ${main_packages_pool}/${pkg}" if ${require_signature}; then [ -L "${root_dir}/${repo}/os/${arch}/${pkg}.sig" ] || fail "${repo}/os/${arch}/${pkg}.sig is not a symlink" [ "$(readlink -e "${root_dir}/${repo}/os/${arch}/${pkg}.sig")" == "${root_dir}/${main_packages_pool}/${pkg}.sig" ] \ || fail "${repo}/os/${arch}/${pkg}.sig does not link to ${main_packages_pool}/${pkg}.sig" fi done [ -r "${staging_directory}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging directory" [ -r "${staging_directory}"/${repo}/${pkg}.sig ] && fail "${repo}/${pkg}.sig found in staging directory" for db in ${database_extension_suffixfile} ${files_extension_suffixfile}; do ( [ -r "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" ] \ && bsdtar -xf "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep -q ${pkg}) \ || fail "${pkg} not in ${repo}/os/${arch}/${repo}${db%.tar.*}" done [ -r "${root_dir}/${repo}/os/any/${pkg}" ] && fail "${repo}/os/any/${pkg} should not exist" [ -r "${root_dir}/${repo}/os/any/${pkg}.sig" ] && fail "${repo}/os/any/${pkg}.sig should not exist" } checkAnyPackage() { local repo=$1 local pkg=$2 checkAnyPackageDB $repo $pkg local pkgbase=$(getpkgbase "${root_dir}/${main_packages_pool}/${pkg}") svn up -q "${temporary_directory}/svn-packages-copy/${pkgbase}" [ -d "${temporary_directory}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] \ || fail "svn-packages-copy/${pkgbase}/repos/${repo}-any does not exist" } checkPackageDB() { local repo=$1 local pkg=$2 local arch=$3 local db [ -r "${root_dir}/${main_packages_pool}/${pkg}" ] || fail "${main_packages_pool}/${pkg} not found" [ -L "${root_dir}/${repo}/os/${arch}/${pkg}" ] || fail "${repo}/os/${arch}/${pkg} not a symlink" [ -r "${staging_directory}"/${repo}/${pkg} ] && fail "${repo}/${pkg} found in staging directory" [ "$(readlink -e "${root_dir}/${repo}/os/${arch}/${pkg}")" == "${root_dir}/${main_packages_pool}/${pkg}" ] \ || fail "${repo}/os/${arch}/${pkg} does not link to ${main_packages_pool}/${pkg}" if ${require_signature}; then [ -r "${root_dir}/${main_packages_pool}/${pkg}.sig" ] || fail "${main_packages_pool}/${pkg}.sig not found" [ -L "${root_dir}/${repo}/os/${arch}/${pkg}.sig" ] || fail "${repo}/os/${arch}/${pkg}.sig is not a symlink" [ -r "${staging_directory}"/${repo}/${pkg}.sig ] && fail "${repo}/${pkg}.sig found in staging directory" [ "$(readlink -e "${root_dir}/${repo}/os/${arch}/${pkg}.sig")" == "${root_dir}/${main_packages_pool}/${pkg}.sig" ] \ || fail "${repo}/os/${arch}/${pkg}.sig does not link to ${main_packages_pool}/${pkg}.sig" fi for db in ${database_extension_suffixfile} ${files_extension_suffixfile}; do ( [ -r "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" ] \ && bsdtar -xf "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep -q ${pkg}) \ || fail "${pkg} not in ${repo}/os/${arch}/${repo}${db%.tar.*}" done } checkPackage() { local repo=$1 local pkg=$2 local arch=$3 checkPackageDB $repo $pkg $arch local pkgbase=$(getpkgbase "${root_dir}/${main_packages_pool}/${pkg}") svn up -q "${temporary_directory}/svn-packages-copy/${pkgbase}" [ -d "${temporary_directory}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] \ || fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} does not exist" } checkRemovedPackageDB() { local repo=$1 local pkgbase=$2 local arch=$3 local db for db in ${database_extension_suffixfile} ${files_extension_suffixfile}; do ( [ -r "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" ] \ && bsdtar -xf "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep -q ${pkgbase}) \ && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${db%.tar.*}" done } checkRemovedPackage() { local repo=$1 local pkgbase=$2 local arch=$3 checkRemovedPackageDB $repo $pkgbase $arch svn up -q "${temporary_directory}/svn-packages-copy/${pkgbase}" [ -d "${temporary_directory}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}" ] \ && fail "svn-packages-copy/${pkgbase}/repos/${repo}-${arch} should not exist" } checkRemovedAnyPackageDB() { local repo=$1 local pkgbase=$2 local arch local db for db in ${database_extension_suffixfile} ${files_extension_suffixfile}; do for arch in i686 x86_64; do ( [ -r "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" ] \ && bsdtar -xf "${root_dir}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep -q ${pkgbase}) \ && fail "${pkgbase} should not be in ${repo}/os/${arch}/${repo}${db%.tar.*}" done done } checkRemovedAnyPackage() { local repo=$1 local pkgbase=$2 checkRemovedAnyPackageDB $repo $pkgbase svn up -q "${temporary_directory}/svn-packages-copy/${pkgbase}" [ -d "${temporary_directory}/svn-packages-copy/${pkgbase}/repos/${repo}-any" ] \ && fail "svn-packages-copy/${pkgbase}/repos/${repo}-any should not exist" }