No new checks, just move it into a function and return 1 rather than exit
directly. This also allows the use of local variables.

Signed-off-by: Dan McGee <[email protected]>
---
 scripts/makepkg.sh.in |  142 ++++++++++++++++++++++++++-----------------------
 1 files changed, 76 insertions(+), 66 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index cb63f9a..f46b7f8 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1103,6 +1103,79 @@ install_package() {
        fi
 }
 
+check_sanity() {
+       # check for no-no's in the build script
+       if [ -z "$pkgname" ]; then
+               error "$(gettext "%s is not allowed to be empty.")" "pkgname"
+               return 1
+       fi
+       if [ -z "$pkgver" ]; then
+               error "$(gettext "%s is not allowed to be empty.")" "pkgver"
+               return 1
+       fi
+       if [ -z "$pkgrel" ]; then
+               error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
+               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
+
+       if [ "$arch" = 'any' ]; then
+               CARCH='any'
+       fi
+
+       pkgbase=${pkgbase:-${pkgname[0]}}
+
+       if ! in_array $CARCH ${ar...@]}; then
+               if [ "$IGNOREARCH" -eq 0 ]; then
+                       error "$(gettext "%s is not available for the '%s' 
architecture.")" "$pkgbase" "$CARCH"
+                       plain "$(gettext "Note that many packages may need a 
line added to their %s")" "$BUILDSCRIPT"
+                       plain "$(gettext "such as arch=('%s').")" "$CARCH"
+                       return 1
+               fi
+       fi
+
+       local provide
+       for provide in ${provid...@]}; do
+               if [ $provide != ${provide//</} -o $provide != ${provide//>/} 
]; then
+                       error "$(gettext "Provides array cannot contain 
comparison (< or >) operators.")"
+                       return 1
+               fi
+       done
+
+       if [ "$install" -a ! -f "$install" ]; then
+               error "$(gettext "Install scriptlet (%s) does not exist.")" 
"$install"
+               return 1
+       fi
+
+       local valid_options=1
+       local opt known kopt
+       for opt in ${optio...@]}; do
+               known=0
+               # check if option matches a known option or its inverse
+               for kopt in ${packaging_optio...@]} ${other_optio...@]}; do
+                       if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; 
then
+                               known=1
+                       fi
+               done
+               if [ $known -eq 0 ]; then
+                       error "$(gettext "options array contains unknown option 
'%s'")" "$opt"
+                       valid_options=0
+               fi
+       done
+       if [ $valid_options -eq 0 ]; then
+               return 1
+       fi
+
+       return 0
+}
+
 devel_check() {
        newpkgver=""
 
@@ -1556,74 +1629,11 @@ if [ "$(type -t package)" = "function" ]; then
        PKGFUNC=1
 fi
 
-# check for no-no's in the build script
-if [ -z "$pkgname" ]; then
-       error "$(gettext "%s is not allowed to be empty.")" "pkgname"
-       exit 1
-fi
-if [ -z "$pkgver" ]; then
-       error "$(gettext "%s is not allowed to be empty.")" "pkgver"
-       exit 1
-fi
-if [ -z "$pkgrel" ]; then
-       error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
-       exit 1
-fi
-if [ "$pkgver" != "${pkgver//-/}" ]; then
-       error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
-       exit 1
-fi
-if [ "$pkgrel" != "${pkgrel//-/}" ]; then
-       error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
-       exit 1
-fi
-
-if [ "$arch" = 'any' ]; then
-       CARCH='any'
-fi
-
-pkgbase=${pkgbase:-${pkgname[0]}}
-
-if ! in_array $CARCH ${ar...@]}; then
-       if [ "$IGNOREARCH" -eq 0 ]; then
-               error "$(gettext "%s is not available for the '%s' 
architecture.")" "$pkgbase" "$CARCH"
-               plain "$(gettext "Note that many packages may need a line added 
to their %s")" "$BUILDSCRIPT"
-               plain "$(gettext "such as arch=('%s').")" "$CARCH"
-               exit 1
-       fi
-fi
-
-for provide in ${provid...@]}; do
-       if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
-               error "$(gettext "Provides array cannot contain comparison (< 
or >) operators.")"
-               exit 1
-       fi
-done
-unset provide
-
-if [ "$install" -a ! -f "$install" ]; then
-       error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
-       exit 1
-fi
-
-valid_options=1
-for opt in ${optio...@]}; do
-       known=0
-       # check if option matches a known option or its inverse
-       for kopt in ${packaging_optio...@]} ${other_optio...@]}; do
-               if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
-                       known=1
-               fi
-       done
-       if [ $known -eq 0 ]; then
-               error "$(gettext "options array contains unknown option '%s'")" 
"$opt"
-               valid_options=0
-       fi
-done
-if [ $valid_options -eq 0 ]; then
+# check the PKGBUILD for some basic requirements
+check_sanity || insane=1
+if [ $insane -eq 1 ]; then
        exit 1
 fi
-unset valid_options opt known kopt
 
 # We need to run devel_update regardless of whether we are in the fakeroot
 # build process so that if the user runs makepkg --forcever manually, we
-- 
1.6.3.2

_______________________________________________
pacman-dev mailing list
[email protected]
http://www.archlinux.org/mailman/listinfo/pacman-dev

Reply via email to