diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2010-08-14 22:38:52 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2010-08-14 22:38:52 +0200 |
commit | 7dd7a3a980b0d42295650fe5a4cf45b1eb07fd38 (patch) | |
tree | f53462c9421ffec64f6ebf94f6adc2cbf9e9df20 /db-functions | |
parent | cfa19b31cdeb6698d69ae9a82904c09d3d65a5d7 (diff) |
Add common function to check for correct repo and arch
Diffstat (limited to 'db-functions')
-rw-r--r-- | db-functions | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/db-functions b/db-functions index 16b5ad3..102f2c8 100644 --- a/db-functions +++ b/db-functions @@ -53,6 +53,21 @@ error() { 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 +} + script_lock() { local LOCKDIR="$TMPDIR/.scriptlock.$(basename $0)" if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then @@ -262,6 +277,8 @@ check_pkgfile() { local pkgarch="$(getpkgarch ${pkgfile})" [ $? -ge 1 ] && return 1 + in_array "${pkgarch}" ${ARCHES[@]} 'any' || return 1 + if echo "$(basename ${pkgfile})" | grep -q "${pkgname}-${pkgver}-${pkgarch}"; then return 0 else @@ -277,6 +294,8 @@ check_pkgsvn() { [ $? -ge 1 ] && return 1 local repo="${2}" + in_array "${repo}" $(get_repos_for_host) || return 1 + if [ ! -f "${WORKDIR}/pkgbuilds/${pkgbase}" ]; then mkdir -p "${WORKDIR}/pkgbuilds" svn export -q "${SVNREPO}/${pkgbase}/repos/${repo}-${pkgarch}/PKGBUILD" \ @@ -352,15 +371,7 @@ pkgver_from_src() { 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 + in_array "${repo}" $(get_repos_for_host) || return 1 [ -w "$FTP_BASE/$(get_pkgpool_for_host)" ] || return 1 |