During check_sanity, use regex and abstract the series of variable checks into
a list.

Also add descriptive error message to exceptions involving backup array
members, given that "invalid backup entry" isn't all that communicative.

Signed-off-by: Andres P <[email protected]>
---
 scripts/makepkg.sh.in |   55 +++++++++++++++++-------------------------------
 1 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 81a842e..0958797 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1170,6 +1170,19 @@ install_package() {
        fi
 }
 
+var_lint() {
+       local pattern="$1"
+       local message="$2"
+       shift 2
+
+       local i
+       for i; do
+               [[ $i =~ $pattern ]] || continue
+               error "$(gettext "%s")" "$message"
+               return 1
+       done
+}
+
 check_sanity() {
        # check for no-no's in the build script
        local i
@@ -1179,27 +1192,15 @@ check_sanity() {
                        return 1
                fi
        done
+               
+       var_lint '-' "pkgver is not allowed to contain hyphens" "$pkgver"
+       var_lint '-' "pkgrel is not allowed to contain hyphens" "$pkgrel"
 
-       local name
-       for name in "${pkgna...@]}"; do
-               if [[ ${name:0:1} = "-" ]]; then
-                       error "$(gettext "%s is not allowed to start with a 
hyphen.")" "pkgname"
-                       return 1
-               fi
-       done
+       var_lint '^-' "pkgname entries are not allowed to start with a hyphen" 
"${pkgna...@]}"
+       var_lint '^-' "pkgbase is not allowed to start with a hyphen" "$pkgbase"
 
-       if [[ ${pkgbase:0:1} = "-" ]]; then
-               error "$(gettext "%s is not allowed to start with a hyphen.")" 
"pkgbase"
-               return 1
-       fi
-       if [[ $pkgver != ${pkgver//-/} ]]; then
-               error "$(gettext "%s is not allowed to contain hyphens.")" 
"pkgver"
-               return 1
-       fi
-       if [[ $pkgrel != ${pkgrel//-/} ]]; then
-               error "$(gettext "%s is not allowed to contain hyphens.")" 
"pkgrel"
-               return 1
-       fi
+       var_lint '[<>]' "provides entries are not allowed to contain comparison 
(< or >) characters" "${provid...@]}"
+       var_lint '^/'   "backup entries are not allowed to start with a slash" 
"${back...@]}"
 
        if [[ $arch != 'any' ]]; then
                if ! in_array $CARCH ${ar...@]}; then
@@ -1212,22 +1213,6 @@ check_sanity() {
                fi
        fi
 
-       local provide
-       for provide in ${provid...@]}; do
-               if [[ $provide != ${provide//</} || $provide != ${provide//>/} 
]]; then
-                       error "$(gettext "Provides array cannot contain 
comparison (< or >) operators.")"
-                       return 1
-               fi
-       done
-
-       local file
-       for file in "${back...@]}"; do
-               if [[ ${file:0:1} = "/" ]]; then
-                       error "$(gettext "Invalid backup entry : %s")" "$file"
-                       return 1
-               fi
-       done
-
        local optdepend
        for optdepend in "${optdepen...@]}"; do
                local pkg=${optdepend%%:*}
-- 
1.7.1


Reply via email to