From 13b98e9182bad88e91e2a6d663e79499cf7263e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?coadde=20=5BM=C3=A1rcio=20Alexandre=20Silva=20Delgado=5D?= Date: Wed, 23 Sep 2015 19:49:47 -0300 Subject: fix sources --- any-to-ours | 4 +- config | 35 --- create-repo | 6 +- createrepos | 2 +- cron-jobs/ftpdir-cleanup | 4 +- cron-jobs/integrity-check | 4 +- cron-jobs/make_repo_torrents | 2 +- cron-jobs/repo-sanity-check | 4 +- cron-jobs/sourceballs | 4 +- db-check-nonfree | 4 +- db-cleanup | 4 +- db-functions | 524 ---------------------------------------- db-libremessages | 83 ------- db-list-unsigned-packages | 4 +- db-move | 4 +- db-remove | 4 +- db-repo-add | 4 +- db-repo-remove | 4 +- db-sync | 4 +- db-update | 4 +- dbscripts.cfg | 35 +++ mkrepo | 2 +- share/db-functions | 524 ++++++++++++++++++++++++++++++++++++++++ share/db-libremessages | 83 +++++++ test/lib/common.inc | 12 +- test/runTest | 2 +- test/test.d/create-filelists.sh | 4 +- test/test.d/db-move.sh | 4 +- test/test.d/db-remove.sh | 4 +- test/test.d/db-repo-add.sh | 4 +- test/test.d/db-repo-remove.sh | 4 +- test/test.d/db-update.sh | 4 +- test/test.d/ftpdir-cleanup.sh | 4 +- test/test.d/packages.sh | 4 +- test/test.d/pool-transition.sh | 4 +- test/test.d/signed-packages.sh | 4 +- test/test.d/sourceballs.sh | 4 +- test/test.d/testing2x.sh | 4 +- 38 files changed, 707 insertions(+), 707 deletions(-) delete mode 100644 config delete mode 100644 db-functions delete mode 100755 db-libremessages create mode 100644 dbscripts.cfg create mode 100644 share/db-functions create mode 100644 share/db-libremessages diff --git a/any-to-ours b/any-to-ours index ab34a1e..45d1994 100755 --- a/any-to-ours +++ b/any-to-ours @@ -7,8 +7,8 @@ trap_exit() { exit 1 } -source "$(dirname "$(readlink -e "$0")")/config" -source "$(dirname "$(readlink -e "$0")")/db-libremessages" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-libremessages" # From makepkg set -E diff --git a/config b/config deleted file mode 100644 index 12f182e..0000000 --- a/config +++ /dev/null @@ -1,35 +0,0 @@ -#!/hint/bash - -root_dir="/srv/repo/main" - -# distributions -native_distributions=() -derivative_distributions=('gnu+linux_x86_arch_legacy' 'gnu+linux_arm_arch_legacy') -distributions=("${native_distributions}" "${derivative_distributions}") - -# add compability support -source "$(dirname "$(readlink -e "$0")")/config.d/gnu+linux_x86_arch_legacy - -cleanup_destination_directory="${root_dir}/old/packages" -cleanup_dryrun=false -# Time in days to keep moved packages -cleanup_keep=30 - -source_cleanup_destination_directory="${root_dir}/old/sources" -source_cleanup_dryrun=true -# Time in days to keep moved sourcepackages -source_cleanup_keep=30 - -require_signature=true - -lock_delay=10 -lock_timeout=300 - -[ -n "${staging_directory:-}" ] || staging_directory="$HOME/staging/unknown/staging" -temporary_directory="/tmp" -database_extension_suffixfile=".db.tar.gz" -files_extension_suffixfile=".files.tar.gz" -package_extension_suffixfile=".pkg.tar.?z" -source_extension_suffixfile=".src.tar.gz" - -blacklist_file="$HOME/blacklist/blacklist.txt" diff --git a/create-repo b/create-repo index 5654078..c729e9c 100755 --- a/create-repo +++ b/create-repo @@ -1,8 +1,8 @@ #!/bin/bash # Creates repository structure -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -eq 0 ]; then msg "Usage: %s repo1 [repo2 ... repoX]" "${0##*/}" @@ -18,4 +18,4 @@ for _repo in "$@"; do done done -msg "Don't forget to add them to the PKGREPOS array on %s" "$(dirname "$(readlink -e "$0")")/config" +msg "Don't forget to add them to the PKGREPOS array on %s" "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" diff --git a/createrepos b/createrepos index 1072c7f..4ebdefe 100755 --- a/createrepos +++ b/createrepos @@ -1,7 +1,7 @@ #!/bin/bash # Creates the repo structure defined in config -source "$(dirname "$(readlink -e "$0")")/config" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" mkdir -p -- "${root_dir}"/{"${PKGPOOL}","${SRCPOOL}"} "${cleanup_destination_directory}" "${source_cleanup_destination_directory}" "${staging_directory}" diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 2b32eae..6125829 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/../config" -. "$(dirname "$(readlink -e "$0")")/../db-functions" +source "$(dirname "$(readlink -e "$0")")/../dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/../share/db-functions" clean_pkg() { local pkg diff --git a/cron-jobs/integrity-check b/cron-jobs/integrity-check index 7896f32..cb01fc6 100755 --- a/cron-jobs/integrity-check +++ b/cron-jobs/integrity-check @@ -2,8 +2,8 @@ dirname="$(dirname "$(readlink -e "$0")")" -. "${dirname}/../config" -. "${dirname}/../db-functions" +source "${dirname}/../dbscripts.cfg" +source "${dirname}/../share/db-functions" script_lock diff --git a/cron-jobs/make_repo_torrents b/cron-jobs/make_repo_torrents index bb59d2f..9b6c930 100755 --- a/cron-jobs/make_repo_torrents +++ b/cron-jobs/make_repo_torrents @@ -33,7 +33,7 @@ esac # pacman doesn't support multiple different packages of the same name, # so it's OK to just stuff all the torrents into a single directory. script_directory="$(dirname "$(readlink -e "$0")")/.." -. "$(dirname "$(readlink -e "$0")")/../config" +source "$(dirname "$(readlink -e "$0")")/../dbscripts.cfg" public_location="${root_dir}/" torrent_location="${root_dir}/torrents/" diff --git a/cron-jobs/repo-sanity-check b/cron-jobs/repo-sanity-check index 203a740..1e796cd 100755 --- a/cron-jobs/repo-sanity-check +++ b/cron-jobs/repo-sanity-check @@ -4,8 +4,8 @@ # repo", I don't know how the body of the issue is stored in the DB, # but the title says enough, I think. -. "$(dirname "$(readlink -e "$0")")/../config" -. "$(dirname "$(readlink -e "$0")")/../db-functions" +source "$(dirname "$(readlink -e "$0")")/../dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/../share/db-functions" # Traverse all repos for _repo in "${PKGREPOS[@]}"; do diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 53ffff9..8fa27a6 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -1,8 +1,8 @@ #!/bin/bash dirname="$(dirname "$(readlink -e "$0")")" -. "${dirname}/../config" -. "${dirname}/../db-functions" +source "${dirname}/../dbscripts.cfg" +source "${dirname}/../share/db-functions" pushd "${work_directory}" >/dev/null script_lock diff --git a/db-check-nonfree b/db-check-nonfree index 6fcc8ab..1d192e5 100755 --- a/db-check-nonfree +++ b/db-check-nonfree @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -ge 1 ]; then error "Calling %s with a specific repository is not supported" "${0##*/}" diff --git a/db-cleanup b/db-cleanup index 10e3840..73e2719 100755 --- a/db-cleanup +++ b/db-cleanup @@ -15,8 +15,8 @@ trap_exit() { exit 1 } -source "$(dirname "$(readlink -e "$0")")/config" -source "$(dirname "$(readlink -e "$0")")/db-libremessages" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-libremessages" # From makepkg set -E diff --git a/db-functions b/db-functions deleted file mode 100644 index 9afb9e2..0000000 --- a/db-functions +++ /dev/null @@ -1,524 +0,0 @@ -#!/hint/bash - -# Some PKGBUILDs need CARCH to be set -CARCH="x86_64" - -# Useful functions -UMASK="" -set_umask () { - [ "$UMASK" == "" ] && UMASK="$(umask)" - export UMASK - umask 002 -} - -restore_umask () { - umask "$UMASK" >/dev/null -} - -# just like mv -f, but we touch the file and then copy the content so -# default ACLs in the target dir will be applied -mv_acl() { - rm -f "$2" - touch "$2" - cat "$1" >"$2" || return 1 - rm -f "$1" -} - -# set up general environment -work_directory=$(mktemp -dt "${0##*/}.XXXXXXXXXX") -LOCKS=() -REPO_MODIFIED=0 - -# 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 -} - -## -# usage : in_array( $needle, $haystack ) -# return : 0 - found -# 1 - not found -## -in_array() { - local needle=$1; shift - [[ -z $1 ]] && return 1 # Not Found - local item - for item in "$@"; do - [[ $item = "$needle" ]] && return 0 # Found - done - return 1 # Not Found -} - -## -# usage : get_full_version( $epoch, $pkgver, $pkgrel ) -# return : full version spec, including epoch (if necessary), pkgver, pkgrel -## -get_full_version() { - if [[ $1 -eq 0 ]]; then - # zero epoch case, don't include it in version - echo "$2-$3" - else - echo "$1:$2-$3" - fi -} - -script_lock() { - local LOCKDIR="$temporary_directory/.scriptlock.${0##*/}" - if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then - local _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" - error "Script %s is already locked by %s." "${0##*/}" "$_owner" - exit 1 - else - set_umask - return 0 - fi -} - -script_unlock() { - local LOCKDIR="$temporary_directory/.scriptlock.${0##*/}" - if [ ! -d "$LOCKDIR" ]; then - warning "Script %s was not locked!" "${0##*/}" - 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 "$temporary_directory/.repolock.$repo.$arch" ]; then - msg "Removing left over lock from [%s] (%s)" "${repo}" "${arch}" - repo_unlock "$repo" "$arch" - fi - done - if [ -d "$temporary_directory/.scriptlock.${0##*/}" ]; then - msg "Removing left over lock from %s" "${0##*/}" - script_unlock - fi - rm -rf "${work_directory}" - - if (( REPO_MODIFIED )); then - date +%s > "${root_dir}/lastupdate" - date -u +%s > "${root_dir}/lastsync" - fi - - [ "$1" ] && exit "$1" -} - -abort() { - msg 'Aborting...' - cleanup 0 -} - -die() { - error "$@" - cleanup 1 -} - -trap abort INT QUIT TERM HUP -trap cleanup EXIT - - -#repo_lock [timeout] -repo_lock () { - local LOCKDIR="$temporary_directory/.repolock.$1.$2" - local DBLOCKFILE="${root_dir}/${1}/os/${2}/${1}${database_extension_suffixfile}.lck" - local FILESLOCKFILE="${root_dir}/${1}/os/${2}/${1}${files_extension_suffixfile}.lck" - local _count - local _trial - local _timeout - local _lockblock - local _owner - - # This is the lock file used by repo-add and repo-remove - if [ -f "${DBLOCKFILE}" ]; then - error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$DBLOCKFILE")" - return 1 - fi - if [ -f "${FILESLOCKFILE}" ]; then - error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$FILESLOCKFILE")" - return 1 - fi - - if [ $# -eq 2 ]; then - _lockblock=true - _trial=0 - elif [ $# -eq 3 ]; then - _lockblock=false - _timeout=$3 - let _trial=$_timeout/$lock_delay - fi - - _count=0 - while [ "$_count" -le "$_trial" ] || "$_lockblock" ; do - if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then - _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" - warning "Repo [%s] (%s) is already locked by %s." "${1}" "${2}" "$_owner" - msg2 "Retrying in %d seconds..." "$lock_delay" - else - LOCKS+=("$1.$2") - set_umask - return 0 - fi - sleep "$lock_delay" - let _count=$_count+1 - done - - error "Repo [%s] (%s) is already locked by %s. Giving up!" "${1}" "${2}" "$_owner" - return 1 -} - -repo_unlock () { #repo_unlock - local LOCKDIR="$temporary_directory/.repolock.$1.$2" - if [ ! -d "$LOCKDIR" ]; then - warning "Repo lock [%s] (%s) was not locked!" "${1}" "${2}" - restore_umask - return 1 - else - rmdir "$LOCKDIR" - restore_umask - return 0 - fi -} - -# usage: _grep_pkginfo pkgfile pattern -_grep_pkginfo() { - local _ret - - _ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | grep -m 1 "^${2} = ")" - echo "${_ret#${2} = }" -} - - -# Get the package base or name as fallback -getpkgbase() { - local _base - - _base="$(_grep_pkginfo "$1" "pkgbase")" - if [ -z "$_base" ]; then - getpkgname "$1" - else - echo "$_base" - fi -} - -issplitpkg() { - local _base - - _base="$(_grep_pkginfo "$1" "pkgbase")" - if [ -z "$_base" ]; then - return 1 - else - return 0 - fi -} - -# Get the package name -getpkgname() { - local _name - - _name="$(_grep_pkginfo "$1" "pkgname")" - if [ -z "$_name" ]; then - error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1" - exit 1 - fi - - echo "$_name" -} - -# Get the pkgver-pkgrel of this package -getpkgver() { - local _ver - - _ver="$(_grep_pkginfo "$1" "pkgver")" - if [ -z "$_ver" ]; then - error "Package '%s' has no pkgver in the PKGINFO. Fail!" "$1" - exit 1 - fi - - echo "$_ver" -} - -getpkgarch() { - local _ver - - _ver="$(_grep_pkginfo "$1" "arch")" - if [ -z "$_ver" ]; then - error "Package '%s' has no arch in the PKGINFO. Fail!" "$1" - exit 1 - fi - - echo "$_ver" -} - -getpkgfile() { - if [[ ${#} -ne 1 ]]; then - error 'No canonical package found!' - exit 1 - elif [ ! -f "${1}" ]; then - error "Package %s not found!" "${1}" - exit 1 - elif "${require_signature}" && [ ! -f "${1}.sig" ]; then - error "Package signature %s not found!" "${1}.sig" - exit 1 - fi - - echo "${1}" -} - -getpkgfiles() { - local f - if [ ! -z "$(printf '%s\n' "${@%\.*}" | sort | uniq -D)" ]; then - error 'Duplicate packages found!' - exit 1 - fi - - for f in "${@}"; do - if [ ! -f "${f}" ]; then - error "Package %s not found!" "${f}" - exit 1 - elif "${require_signature}" && [ ! -f "${f}.sig" ]; then - error "Package signature %s not found!" "${f}.sig" - exit 1 - fi - done - - echo "${@}" -} - -check_pkgfile() { - local pkgfile=$1 - - local pkgname="$(getpkgname "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local pkgver="$(getpkgver "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local pkgarch="$(getpkgarch "${pkgfile}")" - [ $? -ge 1 ] && return 1 - - in_array "${pkgarch}" "${ARCHES[@]}" 'any' || return 1 - - if echo "${pkgfile##*/}" | grep -q "${pkgname}-${pkgver}-${pkgarch}"; then - return 0 - else - return 1 - fi -} - -check_pkgxbs() { - local pkgfile="${1}" - local _pkgbase="$(getpkgbase "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local _pkgname="$(getpkgname "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local _pkgver="$(getpkgver "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local _pkgarch="$(getpkgarch "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local repo="${2}" - - in_array "${repo}" "${PKGREPOS[@]}" || return 1 - - local xbsver="$(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; get_full_version "${_pkgname}")" - [ "${xbsver}" == "${_pkgver}" ] || return 1 - - local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}")) - in_array "${_pkgname}" "${xbsnames[@]}" || return 1 - - return 0 -} - -check_splitpkgs() { - local repo="${1}" - shift - local pkgfiles=("${@}") - local pkgfile - local pkgdir - local xbsname - - mkdir -p "${work_directory}/check_splitpkgs/" - pushd "${work_directory}/check_splitpkgs" >/dev/null - - for pkgfile in "${pkgfiles[@]}"; do - issplitpkg "${pkgfile}" || continue - local _pkgbase="$(getpkgbase "${pkgfile}")" - msg2 "Checking %s" "$_pkgbase" - local _pkgname="$(getpkgname "${pkgfile}")" - local _pkgarch="$(getpkgarch "${pkgfile}")" - mkdir -p "${repo}/${_pkgarch}/${_pkgbase}" - echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging" - - local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}")) - printf '%s\n' "${xbsnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/xbs" - done - popd >/dev/null - - for pkgdir in "${work_directory}/check_splitpkgs/${repo}"/*/*; do - [ ! -d "${pkgdir}" ] && continue - sort -u "${pkgdir}/staging" -o "${pkgdir}/staging" - sort -u "${pkgdir}/xbs" -o "${pkgdir}/xbs" - if [ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/xbs")" ]; then - return 1 - fi - done - - return 0 -} - -check_pkgrepos() { - local pkgfile=$1 - - local pkgname="$(getpkgname "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local pkgver="$(getpkgver "${pkgfile}")" - [ $? -ge 1 ] && return 1 - local pkgarch="$(getpkgarch "${pkgfile}")" - [ $? -ge 1 ] && return 1 - - [ -f "${root_dir}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile} ] && return 1 - [ -f "${root_dir}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile}.sig ] && return 1 - [ -f "${root_dir}/${PKGPOOL}/${pkgfile##*/}" ] && return 1 - [ -f "${root_dir}/${PKGPOOL}/${pkgfile##*/}.sig" ] && return 1 - - local repo - local arch - for repo in "${PKGREPOS[@]}"; do - for arch in "${ARCHES[@]}"; do - [ -f "${root_dir}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile} ] && return 1 - [ -f "${root_dir}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile}.sig ] && return 1 - [ -f "${root_dir}/${repo}/os/${arch}/${pkgfile##*/}" ] && return 1 - [ -f "${root_dir}/${repo}/os/${arch}/${pkgfile##*/}.sig" ] && return 1 - done - done - - return 0 -} - -#usage: chk_license ${license[@]}" -chk_license() { - local l - for l in "${@}"; do - in_array "${l}" "${ALLOWED_LICENSES[@]}" && return 0 - done - - return 1 -} - -check_repo_permission() { - local repo=$1 - - [ ${#PKGREPOS[@]} -eq 0 ] && return 1 - [ -z "${PKGPOOL}" ] && return 1 - - in_array "${repo}" "${PKGREPOS[@]}" || return 1 - - [ -w "${root_dir}/${PKGPOOL}" ] || return 1 - - local arch - for arch in "${ARCHES[@]}"; do - local dir="${root_dir}/${repo}/os/${arch}/" - [ -w "${dir}" ] || return 1 - [ -f "${dir}${repo}"${database_extension_suffixfile} -a ! -w "${dir}${repo}"${database_extension_suffixfile} ] && return 1 - [ -f "${dir}${repo}"${files_extension_suffixfile} -a ! -w "${dir}${repo}"${files_extension_suffixfile} ] && return 1 - done - - return 0 -} - -set_repo_permission() { - local repo=$1 - local arch=$2 - local dbfile="${root_dir}/${repo}/os/${arch}/${repo}${database_extension_suffixfile}" - local filesfile="${root_dir}/${repo}/os/${arch}/${repo}${files_extension_suffixfile}" - - if [ -w "${dbfile}" ]; then - local group=$(/usr/bin/stat --printf='%G' "$(dirname "${dbfile}")") - chgrp "$group" "${dbfile}" || error "Could not change group of %s to %s" "${dbfile}" "$group" - chgrp "$group" "${filesfile}" || error "Could not change group of %s to %s" "${filesfile}" "$group" - chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "${dbfile}" - chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "${filesfile}" - else - error "You don't have permission to change %s" "${dbfile}" - fi -} - -arch_repo_add() { - local repo=$1 - local arch=$2 - local pkgs=("${@:3}") - - printf -v pkgs_str -- '%q ' "${pkgs[@]}" - # package files might be relative to repo dir - pushd "${root_dir}/${repo}/os/${arch}" >/dev/null - /usr/bin/repo-add -q "${repo}${database_extension_suffixfile}" "${pkgs[@]}" >/dev/null \ - || error 'repo-add %q %s' "${repo}${database_extension_suffixfile}" "${pkgs_str% }" - /usr/bin/repo-add -f -q "${repo}${files_extension_suffixfile}" "${pkgs[@]}" \ - || error 'repo-add -f %q %s' "${repo}${files_extension_suffixfile}" "${pkgs_str% }" - popd >/dev/null - set_repo_permission "${repo}" "${arch}" - - REPO_MODIFIED=1 -} - -arch_repo_remove() { - local repo=$1 - local arch=$2 - local pkgs=("${@:3}") - local dbfile="${root_dir}/${repo}/os/${arch}/${repo}${database_extension_suffixfile}" - local filesfile="${root_dir}/${repo}/os/${arch}/${repo}${files_extension_suffixfile}" - - if [ ! -f "${dbfile}" ]; then - error "No database found at '%s'" "${dbfile}" - return 1 - fi - printf -v pkgs_str -- '%q ' "${pkgs[@]}" - /usr/bin/repo-remove -q "${dbfile}" "${pkgs[@]}" >/dev/null \ - || error 'repo-remove %q %s' "${dbfile}" "${pkgs_str% }" - /usr/bin/repo-remove -q "${filesfile}" "${pkgs[@]}" \ - || error 'repo-remove %q %s' "${filesfile}" "${pkgs_str% }" - set_repo_permission "${repo}" "${arch}" - - REPO_MODIFIED=1 -} diff --git a/db-libremessages b/db-libremessages deleted file mode 100755 index 37df149..0000000 --- a/db-libremessages +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2006-2010 Pacman Development Team -# Copyright (c) 2002-2006 by Judd Vinet -# Copyright (c) 2005 by Aurelien Foret -# Copyright (c) 2006 by Miklos Vajna -# Copyright (c) 2005 by Christian Hamar -# Copyright (c) 2006 by Alex Smith -# Copyright (c) 2006 by Andras Voroskoi -# Copyright (c) 2011 by Joshua Haase -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# gettext initialization -export TEXTDOMAIN='libretools' -export TEXTDOMAINDIR='/usr/share/locale' - -# check if messages are to be printed using color -unset ALL_OFF BOLD BLUE GREEN RED YELLOW - -if tput setaf 0 &>/dev/null; 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)" - PURPLE="${ALL_OFF}$(tput setaf 5)" -else - ALL_OFF="\033[1;0m" - BOLD="\033[1;1m" - BLUE="${BOLD}\033[1;34m" - GREEN="${BOLD}\033[1;32m" - RED="${BOLD}\033[1;31m" - YELLOW="${BOLD}\033[1;33m" - PURPLE="${BOLD}\033[1;30;40m" -fi - -stdnull() { - local action=$1; - eval "${action} >/dev/null 2>&1" -} - -plain() { - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg() { - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg2() { - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -fatal_error() { - local mesg=$1; shift - error "$mesg" "$@" - - exit 1 -} diff --git a/db-list-unsigned-packages b/db-list-unsigned-packages index e83002f..208d770 100755 --- a/db-list-unsigned-packages +++ b/db-list-unsigned-packages @@ -20,8 +20,8 @@ set -e # unsigned packages available for architecture $1 and specified for # architecture $2 (usually $1 or any, default is to list all). -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -lt 1 ]; then msg "usage: %s " "${0##*/}" diff --git a/db-move b/db-move index b02ba3c..bebbd21 100755 --- a/db-move +++ b/db-move @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -lt 3 ]; then msg "usage: %s ..." "${0##*/}" diff --git a/db-remove b/db-remove index dcbe4b4..6f1aee3 100755 --- a/db-remove +++ b/db-remove @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -lt 3 ]; then msg "usage: %s ..." "${0##*/}" diff --git a/db-repo-add b/db-repo-add index 024fce8..3b82ef2 100755 --- a/db-repo-add +++ b/db-repo-add @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -lt 3 ]; then msg "usage: %s ..." "${0##*/}" diff --git a/db-repo-remove b/db-repo-remove index ab5f8f8..3754fa3 100755 --- a/db-repo-remove +++ b/db-repo-remove @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -lt 3 ]; then msg "usage: %s ..." "${0##*/}" diff --git a/db-sync b/db-sync index dde21e3..dbab053 100755 --- a/db-sync +++ b/db-sync @@ -188,8 +188,8 @@ trap_exit() { kill "-$signal" "$$" } -source "$(dirname "$(readlink -e "$0")")/config" -source "$(dirname "$(readlink -e "$0")")/db-libremessages" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-libremessages" # Check variables presence for var in database_extension_suffixfile files_extension_suffixfile mirror mirror_path work_directory blacklist_file root_dir ARCHSRCPOOLS ARCHPKGPOOLS; do diff --git a/db-update b/db-update index 6a62e43..ea8c22e 100755 --- a/db-update +++ b/db-update @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" +source "$(dirname "$(readlink -e "$0")")/share/db-functions" if [ $# -ge 1 ]; then warning "Calling %s with a specific repository is no longer supported" "${0##*/}" diff --git a/dbscripts.cfg b/dbscripts.cfg new file mode 100644 index 0000000..044b21f --- /dev/null +++ b/dbscripts.cfg @@ -0,0 +1,35 @@ +#!/hint/bash + +root_dir="/srv/repo/main" + +# distributions +native_distributions=() +derivative_distributions=('gnu+linux_x86_arch_legacy' 'gnu+linux_arm_arch_legacy') +distributions=("${native_distributions}" "${derivative_distributions}") + +# add compability support +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg.d/gnu+linux_x86_arch_legacy + +cleanup_destination_directory="${root_dir}/old/packages" +cleanup_dryrun=false +# Time in days to keep moved packages +cleanup_keep=30 + +source_cleanup_destination_directory="${root_dir}/old/sources" +source_cleanup_dryrun=true +# Time in days to keep moved sourcepackages +source_cleanup_keep=30 + +require_signature=true + +lock_delay=10 +lock_timeout=300 + +[ -n "${staging_directory:-}" ] || staging_directory="$HOME/staging/unknown/staging" +temporary_directory="/tmp" +database_extension_suffixfile=".db.tar.gz" +files_extension_suffixfile=".files.tar.gz" +package_extension_suffixfile=".pkg.tar.?z" +source_extension_suffixfile=".src.tar.gz" + +blacklist_file="$HOME/blacklist/blacklist.txt" diff --git a/mkrepo b/mkrepo index b7b27f7..4fb2587 100755 --- a/mkrepo +++ b/mkrepo @@ -3,7 +3,7 @@ # License: GPLv3+ # Description: A script to quickly create new [repos] -source "$(dirname "$(readlink -e "$0")")/config" +source "$(dirname "$(readlink -e "$0")")/dbscripts.cfg" for repo in "$@"; do echo ":: Creating [$repo]" diff --git a/share/db-functions b/share/db-functions new file mode 100644 index 0000000..9afb9e2 --- /dev/null +++ b/share/db-functions @@ -0,0 +1,524 @@ +#!/hint/bash + +# Some PKGBUILDs need CARCH to be set +CARCH="x86_64" + +# Useful functions +UMASK="" +set_umask () { + [ "$UMASK" == "" ] && UMASK="$(umask)" + export UMASK + umask 002 +} + +restore_umask () { + umask "$UMASK" >/dev/null +} + +# just like mv -f, but we touch the file and then copy the content so +# default ACLs in the target dir will be applied +mv_acl() { + rm -f "$2" + touch "$2" + cat "$1" >"$2" || return 1 + rm -f "$1" +} + +# set up general environment +work_directory=$(mktemp -dt "${0##*/}.XXXXXXXXXX") +LOCKS=() +REPO_MODIFIED=0 + +# 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 +} + +## +# usage : in_array( $needle, $haystack ) +# return : 0 - found +# 1 - not found +## +in_array() { + local needle=$1; shift + [[ -z $1 ]] && return 1 # Not Found + local item + for item in "$@"; do + [[ $item = "$needle" ]] && return 0 # Found + done + return 1 # Not Found +} + +## +# usage : get_full_version( $epoch, $pkgver, $pkgrel ) +# return : full version spec, including epoch (if necessary), pkgver, pkgrel +## +get_full_version() { + if [[ $1 -eq 0 ]]; then + # zero epoch case, don't include it in version + echo "$2-$3" + else + echo "$1:$2-$3" + fi +} + +script_lock() { + local LOCKDIR="$temporary_directory/.scriptlock.${0##*/}" + if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then + local _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" + error "Script %s is already locked by %s." "${0##*/}" "$_owner" + exit 1 + else + set_umask + return 0 + fi +} + +script_unlock() { + local LOCKDIR="$temporary_directory/.scriptlock.${0##*/}" + if [ ! -d "$LOCKDIR" ]; then + warning "Script %s was not locked!" "${0##*/}" + 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 "$temporary_directory/.repolock.$repo.$arch" ]; then + msg "Removing left over lock from [%s] (%s)" "${repo}" "${arch}" + repo_unlock "$repo" "$arch" + fi + done + if [ -d "$temporary_directory/.scriptlock.${0##*/}" ]; then + msg "Removing left over lock from %s" "${0##*/}" + script_unlock + fi + rm -rf "${work_directory}" + + if (( REPO_MODIFIED )); then + date +%s > "${root_dir}/lastupdate" + date -u +%s > "${root_dir}/lastsync" + fi + + [ "$1" ] && exit "$1" +} + +abort() { + msg 'Aborting...' + cleanup 0 +} + +die() { + error "$@" + cleanup 1 +} + +trap abort INT QUIT TERM HUP +trap cleanup EXIT + + +#repo_lock [timeout] +repo_lock () { + local LOCKDIR="$temporary_directory/.repolock.$1.$2" + local DBLOCKFILE="${root_dir}/${1}/os/${2}/${1}${database_extension_suffixfile}.lck" + local FILESLOCKFILE="${root_dir}/${1}/os/${2}/${1}${files_extension_suffixfile}.lck" + local _count + local _trial + local _timeout + local _lockblock + local _owner + + # This is the lock file used by repo-add and repo-remove + if [ -f "${DBLOCKFILE}" ]; then + error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$DBLOCKFILE")" + return 1 + fi + if [ -f "${FILESLOCKFILE}" ]; then + error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$FILESLOCKFILE")" + return 1 + fi + + if [ $# -eq 2 ]; then + _lockblock=true + _trial=0 + elif [ $# -eq 3 ]; then + _lockblock=false + _timeout=$3 + let _trial=$_timeout/$lock_delay + fi + + _count=0 + while [ "$_count" -le "$_trial" ] || "$_lockblock" ; do + if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then + _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" + warning "Repo [%s] (%s) is already locked by %s." "${1}" "${2}" "$_owner" + msg2 "Retrying in %d seconds..." "$lock_delay" + else + LOCKS+=("$1.$2") + set_umask + return 0 + fi + sleep "$lock_delay" + let _count=$_count+1 + done + + error "Repo [%s] (%s) is already locked by %s. Giving up!" "${1}" "${2}" "$_owner" + return 1 +} + +repo_unlock () { #repo_unlock + local LOCKDIR="$temporary_directory/.repolock.$1.$2" + if [ ! -d "$LOCKDIR" ]; then + warning "Repo lock [%s] (%s) was not locked!" "${1}" "${2}" + restore_umask + return 1 + else + rmdir "$LOCKDIR" + restore_umask + return 0 + fi +} + +# usage: _grep_pkginfo pkgfile pattern +_grep_pkginfo() { + local _ret + + _ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | grep -m 1 "^${2} = ")" + echo "${_ret#${2} = }" +} + + +# Get the package base or name as fallback +getpkgbase() { + local _base + + _base="$(_grep_pkginfo "$1" "pkgbase")" + if [ -z "$_base" ]; then + getpkgname "$1" + else + echo "$_base" + fi +} + +issplitpkg() { + local _base + + _base="$(_grep_pkginfo "$1" "pkgbase")" + if [ -z "$_base" ]; then + return 1 + else + return 0 + fi +} + +# Get the package name +getpkgname() { + local _name + + _name="$(_grep_pkginfo "$1" "pkgname")" + if [ -z "$_name" ]; then + error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1" + exit 1 + fi + + echo "$_name" +} + +# Get the pkgver-pkgrel of this package +getpkgver() { + local _ver + + _ver="$(_grep_pkginfo "$1" "pkgver")" + if [ -z "$_ver" ]; then + error "Package '%s' has no pkgver in the PKGINFO. Fail!" "$1" + exit 1 + fi + + echo "$_ver" +} + +getpkgarch() { + local _ver + + _ver="$(_grep_pkginfo "$1" "arch")" + if [ -z "$_ver" ]; then + error "Package '%s' has no arch in the PKGINFO. Fail!" "$1" + exit 1 + fi + + echo "$_ver" +} + +getpkgfile() { + if [[ ${#} -ne 1 ]]; then + error 'No canonical package found!' + exit 1 + elif [ ! -f "${1}" ]; then + error "Package %s not found!" "${1}" + exit 1 + elif "${require_signature}" && [ ! -f "${1}.sig" ]; then + error "Package signature %s not found!" "${1}.sig" + exit 1 + fi + + echo "${1}" +} + +getpkgfiles() { + local f + if [ ! -z "$(printf '%s\n' "${@%\.*}" | sort | uniq -D)" ]; then + error 'Duplicate packages found!' + exit 1 + fi + + for f in "${@}"; do + if [ ! -f "${f}" ]; then + error "Package %s not found!" "${f}" + exit 1 + elif "${require_signature}" && [ ! -f "${f}.sig" ]; then + error "Package signature %s not found!" "${f}.sig" + exit 1 + fi + done + + echo "${@}" +} + +check_pkgfile() { + local pkgfile=$1 + + local pkgname="$(getpkgname "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local pkgver="$(getpkgver "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local pkgarch="$(getpkgarch "${pkgfile}")" + [ $? -ge 1 ] && return 1 + + in_array "${pkgarch}" "${ARCHES[@]}" 'any' || return 1 + + if echo "${pkgfile##*/}" | grep -q "${pkgname}-${pkgver}-${pkgarch}"; then + return 0 + else + return 1 + fi +} + +check_pkgxbs() { + local pkgfile="${1}" + local _pkgbase="$(getpkgbase "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local _pkgname="$(getpkgname "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local _pkgver="$(getpkgver "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local _pkgarch="$(getpkgarch "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local repo="${2}" + + in_array "${repo}" "${PKGREPOS[@]}" || return 1 + + local xbsver="$(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; get_full_version "${_pkgname}")" + [ "${xbsver}" == "${_pkgver}" ] || return 1 + + local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}")) + in_array "${_pkgname}" "${xbsnames[@]}" || return 1 + + return 0 +} + +check_splitpkgs() { + local repo="${1}" + shift + local pkgfiles=("${@}") + local pkgfile + local pkgdir + local xbsname + + mkdir -p "${work_directory}/check_splitpkgs/" + pushd "${work_directory}/check_splitpkgs" >/dev/null + + for pkgfile in "${pkgfiles[@]}"; do + issplitpkg "${pkgfile}" || continue + local _pkgbase="$(getpkgbase "${pkgfile}")" + msg2 "Checking %s" "$_pkgbase" + local _pkgname="$(getpkgname "${pkgfile}")" + local _pkgarch="$(getpkgarch "${pkgfile}")" + mkdir -p "${repo}/${_pkgarch}/${_pkgbase}" + echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging" + + local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}")) + printf '%s\n' "${xbsnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/xbs" + done + popd >/dev/null + + for pkgdir in "${work_directory}/check_splitpkgs/${repo}"/*/*; do + [ ! -d "${pkgdir}" ] && continue + sort -u "${pkgdir}/staging" -o "${pkgdir}/staging" + sort -u "${pkgdir}/xbs" -o "${pkgdir}/xbs" + if [ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/xbs")" ]; then + return 1 + fi + done + + return 0 +} + +check_pkgrepos() { + local pkgfile=$1 + + local pkgname="$(getpkgname "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local pkgver="$(getpkgver "${pkgfile}")" + [ $? -ge 1 ] && return 1 + local pkgarch="$(getpkgarch "${pkgfile}")" + [ $? -ge 1 ] && return 1 + + [ -f "${root_dir}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile} ] && return 1 + [ -f "${root_dir}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile}.sig ] && return 1 + [ -f "${root_dir}/${PKGPOOL}/${pkgfile##*/}" ] && return 1 + [ -f "${root_dir}/${PKGPOOL}/${pkgfile##*/}.sig" ] && return 1 + + local repo + local arch + for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + [ -f "${root_dir}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile} ] && return 1 + [ -f "${root_dir}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${package_extension_suffixfile}.sig ] && return 1 + [ -f "${root_dir}/${repo}/os/${arch}/${pkgfile##*/}" ] && return 1 + [ -f "${root_dir}/${repo}/os/${arch}/${pkgfile##*/}.sig" ] && return 1 + done + done + + return 0 +} + +#usage: chk_license ${license[@]}" +chk_license() { + local l + for l in "${@}"; do + in_array "${l}" "${ALLOWED_LICENSES[@]}" && return 0 + done + + return 1 +} + +check_repo_permission() { + local repo=$1 + + [ ${#PKGREPOS[@]} -eq 0 ] && return 1 + [ -z "${PKGPOOL}" ] && return 1 + + in_array "${repo}" "${PKGREPOS[@]}" || return 1 + + [ -w "${root_dir}/${PKGPOOL}" ] || return 1 + + local arch + for arch in "${ARCHES[@]}"; do + local dir="${root_dir}/${repo}/os/${arch}/" + [ -w "${dir}" ] || return 1 + [ -f "${dir}${repo}"${database_extension_suffixfile} -a ! -w "${dir}${repo}"${database_extension_suffixfile} ] && return 1 + [ -f "${dir}${repo}"${files_extension_suffixfile} -a ! -w "${dir}${repo}"${files_extension_suffixfile} ] && return 1 + done + + return 0 +} + +set_repo_permission() { + local repo=$1 + local arch=$2 + local dbfile="${root_dir}/${repo}/os/${arch}/${repo}${database_extension_suffixfile}" + local filesfile="${root_dir}/${repo}/os/${arch}/${repo}${files_extension_suffixfile}" + + if [ -w "${dbfile}" ]; then + local group=$(/usr/bin/stat --printf='%G' "$(dirname "${dbfile}")") + chgrp "$group" "${dbfile}" || error "Could not change group of %s to %s" "${dbfile}" "$group" + chgrp "$group" "${filesfile}" || error "Could not change group of %s to %s" "${filesfile}" "$group" + chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "${dbfile}" + chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "${filesfile}" + else + error "You don't have permission to change %s" "${dbfile}" + fi +} + +arch_repo_add() { + local repo=$1 + local arch=$2 + local pkgs=("${@:3}") + + printf -v pkgs_str -- '%q ' "${pkgs[@]}" + # package files might be relative to repo dir + pushd "${root_dir}/${repo}/os/${arch}" >/dev/null + /usr/bin/repo-add -q "${repo}${database_extension_suffixfile}" "${pkgs[@]}" >/dev/null \ + || error 'repo-add %q %s' "${repo}${database_extension_suffixfile}" "${pkgs_str% }" + /usr/bin/repo-add -f -q "${repo}${files_extension_suffixfile}" "${pkgs[@]}" \ + || error 'repo-add -f %q %s' "${repo}${files_extension_suffixfile}" "${pkgs_str% }" + popd >/dev/null + set_repo_permission "${repo}" "${arch}" + + REPO_MODIFIED=1 +} + +arch_repo_remove() { + local repo=$1 + local arch=$2 + local pkgs=("${@:3}") + local dbfile="${root_dir}/${repo}/os/${arch}/${repo}${database_extension_suffixfile}" + local filesfile="${root_dir}/${repo}/os/${arch}/${repo}${files_extension_suffixfile}" + + if [ ! -f "${dbfile}" ]; then + error "No database found at '%s'" "${dbfile}" + return 1 + fi + printf -v pkgs_str -- '%q ' "${pkgs[@]}" + /usr/bin/repo-remove -q "${dbfile}" "${pkgs[@]}" >/dev/null \ + || error 'repo-remove %q %s' "${dbfile}" "${pkgs_str% }" + /usr/bin/repo-remove -q "${filesfile}" "${pkgs[@]}" \ + || error 'repo-remove %q %s' "${filesfile}" "${pkgs_str% }" + set_repo_permission "${repo}" "${arch}" + + REPO_MODIFIED=1 +} diff --git a/share/db-libremessages b/share/db-libremessages new file mode 100644 index 0000000..37df149 --- /dev/null +++ b/share/db-libremessages @@ -0,0 +1,83 @@ +# Copyright (c) 2006-2010 Pacman Development Team +# Copyright (c) 2002-2006 by Judd Vinet +# Copyright (c) 2005 by Aurelien Foret +# Copyright (c) 2006 by Miklos Vajna +# Copyright (c) 2005 by Christian Hamar +# Copyright (c) 2006 by Alex Smith +# Copyright (c) 2006 by Andras Voroskoi +# Copyright (c) 2011 by Joshua Haase +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# gettext initialization +export TEXTDOMAIN='libretools' +export TEXTDOMAINDIR='/usr/share/locale' + +# check if messages are to be printed using color +unset ALL_OFF BOLD BLUE GREEN RED YELLOW + +if tput setaf 0 &>/dev/null; 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)" + PURPLE="${ALL_OFF}$(tput setaf 5)" +else + ALL_OFF="\033[1;0m" + BOLD="\033[1;1m" + BLUE="${BOLD}\033[1;34m" + GREEN="${BOLD}\033[1;32m" + RED="${BOLD}\033[1;31m" + YELLOW="${BOLD}\033[1;33m" + PURPLE="${BOLD}\033[1;30;40m" +fi + +stdnull() { + local action=$1; + eval "${action} >/dev/null 2>&1" +} + +plain() { + local mesg=$1; shift + printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +msg() { + local mesg=$1; shift + printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +msg2() { + local mesg=$1; shift + printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +warning() { + local mesg=$1; shift + printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +error() { + local mesg=$1; shift + printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + +fatal_error() { + local mesg=$1; shift + error "$mesg" "$@" + + exit 1 +} diff --git a/test/lib/common.inc b/test/lib/common.inc index c549ac9..1121724 100644 --- a/test/lib/common.inc +++ b/test/lib/common.inc @@ -1,7 +1,7 @@ set -E -. "$(dirname ${BASH_SOURCE[0]})/../../config" -. "$(dirname ${BASH_SOURCE[0]})/../../db-functions" +source "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.cfg" +source "$(dirname ${BASH_SOURCE[0]})/../../share/db-functions" oneTimeSetUp() { local p @@ -55,7 +55,7 @@ setUp() { local r local a - [ -f "$(dirname ${BASH_SOURCE[0]})/../../config.local" ] && die "$(dirname ${BASH_SOURCE[0]})/../../config.local exists" + [ -f "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.local.cfg" ] && die "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.local.cfg exists" temporary_directory="$(mktemp -d /dev/shm/$(basename $0).XXXXXXXXXX)" #msg "Using ${temporary_directory}" @@ -84,7 +84,7 @@ setUp() { svn commit -q -m"initial commit of ${pkg}" "${temporary_directory}/svn-packages-copy" done - cat < "$(dirname ${BASH_SOURCE[0]})/../../config.local" + cat < "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.local.cfg" root_dir="${temporary_directory}/ftp" SVN_repository="file://${temporary_directory}/svn-packages-repo" PKGREPOS=(${PKGREPOS[@]}) @@ -97,12 +97,12 @@ setUp() { source_cleanup_dryrun=false require_signature=true eot - . "$(dirname ${BASH_SOURCE[0]})/../../config" + . "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.cfg" } tearDown() { rm -rf "${temporary_directory}" - rm -f "$(dirname ${BASH_SOURCE[0]})/../../config.local" + rm -f "$(dirname ${BASH_SOURCE[0]})/../../dbscripts.local.cfg" echo } diff --git a/test/runTest b/test/runTest index b8713d8..bb86983 100755 --- a/test/runTest +++ b/test/runTest @@ -1,6 +1,6 @@ #!/bin/bash -. "$(dirname ${BASH_SOURCE[0]})/lib/common.inc" +source "$(dirname ${BASH_SOURCE[0]})/lib/common.inc" for t in "$(dirname ${BASH_SOURCE[0]})/test.d/"*.sh; do l=$(basename ${t} .sh) diff --git a/test/test.d/create-filelists.sh b/test/test.d/create-filelists.sh index c1f43e9..b201eb2 100755 --- a/test/test.d/create-filelists.sh +++ b/test/test.d/create-filelists.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testCreateSimpleFileLists() { local arches=('i686' 'x86_64') @@ -102,4 +102,4 @@ testCleanupFileLists() { } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-move.sh b/test/test.d/db-move.sh index 04c8113..3445a46 100755 --- a/test/test.d/db-move.sh +++ b/test/test.d/db-move.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testMoveSimplePackages() { local arches=('i686' 'x86_64') @@ -119,4 +119,4 @@ testMoveSplitPackages() { checkRemovedAnyPackage testing pkg-split-a } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-remove.sh b/test/test.d/db-remove.sh index 416e693..8ec5bd6 100755 --- a/test/test.d/db-remove.sh +++ b/test/test.d/db-remove.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testRemovePackages() { local arches=('i686' 'x86_64') @@ -74,4 +74,4 @@ testRemoveAnyPackages() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-repo-add.sh b/test/test.d/db-repo-add.sh index 7a201f9..01d53c4 100755 --- a/test/test.d/db-repo-add.sh +++ b/test/test.d/db-repo-add.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testAddSimplePackages() { local arches=('i686' 'x86_64') @@ -51,4 +51,4 @@ testAddMultiplePackages() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-repo-remove.sh b/test/test.d/db-repo-remove.sh index 315d63d..45d2ef2 100755 --- a/test/test.d/db-repo-remove.sh +++ b/test/test.d/db-repo-remove.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testRemovePackages() { local arches=('i686' 'x86_64') @@ -55,4 +55,4 @@ testRemoveMultiplePackages() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/db-update.sh b/test/test.d/db-update.sh index 3ce9037..08de911 100755 --- a/test/test.d/db-update.sh +++ b/test/test.d/db-update.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testAddSimplePackages() { local arches=('i686' 'x86_64') @@ -162,4 +162,4 @@ testAddIncompleteSplitPackage() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/ftpdir-cleanup.sh b/test/test.d/ftpdir-cleanup.sh index 4e7e1f5..5ba7fb3 100755 --- a/test/test.d/ftpdir-cleanup.sh +++ b/test/test.d/ftpdir-cleanup.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testCleanupSimplePackages() { local arches=('i686' 'x86_64') @@ -118,4 +118,4 @@ testCleanupSplitPackages() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/packages.sh b/test/test.d/packages.sh index 5028448..13877d2 100755 --- a/test/test.d/packages.sh +++ b/test/test.d/packages.sh @@ -1,11 +1,11 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testPackages() { # TODO: namcap -r sodepends fails with i686 packages find "${pkgdir}" -name "*${package_extension_suffixfile}" -exec namcap -e sodepends,pkgnameindesc {} + || fail 'namcap failed' } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/pool-transition.sh b/test/test.d/pool-transition.sh index 9f13d83..e74cf8b 100755 --- a/test/test.d/pool-transition.sh +++ b/test/test.d/pool-transition.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testMovePackagesWithoutPool() { local arches=('i686' 'x86_64') @@ -149,4 +149,4 @@ testUpdateSameAnyPackageToDifferentRepositoriesWithoutPool() { done } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/signed-packages.sh b/test/test.d/signed-packages.sh index d7c5e57..8293d8a 100755 --- a/test/test.d/signed-packages.sh +++ b/test/test.d/signed-packages.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testAddUnsignedPackage() { releasePackage extra 'pkg-simple-a' 'i686' @@ -10,4 +10,4 @@ testAddUnsignedPackage() { ../db-update >/dev/null 2>&1 && fail "db-update should fail when a signature is missing!" } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/sourceballs.sh b/test/test.d/sourceballs.sh index a34093a..d1adf1e 100755 --- a/test/test.d/sourceballs.sh +++ b/test/test.d/sourceballs.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testSourceballs() { local arches=('i686' 'x86_64') @@ -81,4 +81,4 @@ testSourceballsCleanup() { [ ! -r ${root_dir}/${SRCPOOL}/pkg-simple-b-*${source_extension_suffixfile} ] && fail "source package not found!" } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" diff --git a/test/test.d/testing2x.sh b/test/test.d/testing2x.sh index d0d08d5..a291ee3 100755 --- a/test/test.d/testing2x.sh +++ b/test/test.d/testing2x.sh @@ -1,7 +1,7 @@ #!/bin/bash curdir=$(readlink -e $(dirname $0)) -. "${curdir}/../lib/common.inc" +source "${curdir}/../lib/common.inc" testTesting2xAnyPackage() { releasePackage core pkg-any-a any @@ -24,4 +24,4 @@ testTesting2xAnyPackage() { checkRemovedAnyPackage testing pkg-any-a } -. "${curdir}/../lib/shunit2" +source "${curdir}/../lib/shunit2" -- cgit v1.2.3