During check_sanity, use regex and abstract the series of variable checks into a list. Signed-off-by: Andres P <aepd87@gmail.com> --- scripts/makepkg.sh.in | 70 +++++++++++++++++++----------------------------- 1 files changed, 28 insertions(+), 42 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 23e3b36..991ad0f 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1161,6 +1161,19 @@ install_package() { fi } +var_lint() { + local pattern="$1" + local directive="$2" + shift 2 + + local i + for i; do + [[ $i =~ $pattern ]] || continue + error "$(gettext "'%s' is an invalid value for %s")" "$i" "$directive" + return 1 + done +} + check_sanity() { # check for no-no's in the build script local i @@ -1170,28 +1183,25 @@ check_sanity() { return 1 fi done + + local i + for i in 'pkgver' 'pkgrel'; do + var_lint '-' $i "${!i}" || return + done - local name - for name in "${pkgname[@]}"; do - if [[ ${name:0:1} = "-" ]]; then - error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" - return 1 + var_lint '^-' pkgname "${pkgname[@]}" || return + var_lint '^-' pkgbase "${pkgbase}" || return + var_lint '[<>]' provides "${provides[@]}" || return + var_lint '^/' backup "${backup[@]}" || return + + local optdepend + for optdepend in "${optdepends[@]}"; do + local pkg=${optdepend%%:*} + if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then + error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend" fi done - 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 - if [[ $arch != 'any' ]]; then if ! in_array $CARCH ${arch[@]}; then if (( ! IGNOREARCH )); then @@ -1203,30 +1213,6 @@ check_sanity() { fi fi - local provide - for provide in ${provides[@]}; 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 "${backup[@]}"; do - if [[ ${file:0:1} = "/" ]]; then - error "$(gettext "Invalid backup entry : %s")" "$file" - return 1 - fi - done - - local optdepend - for optdepend in "${optdepends[@]}"; do - local pkg=${optdepend%%:*} - if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then - error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend" - fi - done - local i for i in 'changelog' 'install'; do local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE") -- 1.7.1