summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-06-06 12:49:37 -0500
committerDan McGee <dan@archlinux.org>2009-06-07 15:07:37 -0500
commite61ab1536f4b198ac5c62cf68d706d93bc6481be (patch)
tree662c4d1e2e23fcbb9c47ccc802be28b895178762 /scripts
parent13b281d74380d9622574bd546e7f9084054ae289 (diff)
makepkg: refactor sanity checking into a function
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 <dan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/makepkg.sh.in142
1 files changed, 76 insertions, 66 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index cb63f9ae..f46b7f81 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 ${arch[@]}; 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 ${provides[@]}; 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 ${options[@]}; do
+ known=0
+ # check if option matches a known option or its inverse
+ for kopt in ${packaging_options[@]} ${other_options[@]}; 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 ${arch[@]}; 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 ${provides[@]}; 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 ${options[@]}; do
- known=0
- # check if option matches a known option or its inverse
- for kopt in ${packaging_options[@]} ${other_options[@]}; 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