Optimised code to validate build variables and error redirection in bldpkg
This commit is contained in:
parent
b4fea8960e
commit
78dcdc078b
1 changed files with 16 additions and 8 deletions
24
bldpkg
24
bldpkg
|
@ -120,18 +120,26 @@ validatebldfile() {
|
|||
|
||||
if [[ ! -f $buildfile ]] ; then
|
||||
err "No build file to validate from!"
|
||||
else
|
||||
source $buildfile
|
||||
fi
|
||||
|
||||
|
||||
for reqvars in app version build homepage desc requires ; do
|
||||
if [[ ! ${!reqvars} ]] ; then
|
||||
err "Required variable '$reqvars' is not set in $buildfile!"
|
||||
fi
|
||||
done
|
||||
|
||||
# Validate $app
|
||||
if ! grep -E -q '^app=[a-z0-9-]' "$buildfile" ; then
|
||||
if ! echo "$app" | grep -E -q '\w[a-z0-9-]+\w'; then
|
||||
err "Only lower case, numeric characters and dash allowed in the 'app' variable in the build file."
|
||||
|
||||
# Validate $version
|
||||
elif ! grep -E -q '^version=[a-z0-9.]' "$buildfile" ; then
|
||||
elif ! echo "$version" | grep -E -q '\w[a-z0-9.]+\w'; then
|
||||
err "Only lower case, numeric characters and a period allowed in the 'version' variable in the build file."
|
||||
|
||||
# Validate $homepage
|
||||
elif ! grep -E -q '^homepage="\(https|http||ftp)://' "$buildfile" ; then
|
||||
elif ! echo "$homepage" | grep -E -q '(https|http|ftp)://[^"]+' ; then
|
||||
err "Invalid URL in the 'homepage' variable in the build file."
|
||||
|
||||
# Validate $desc using bash shell's ability to count variable length
|
||||
|
@ -148,8 +156,8 @@ validatebldfile() {
|
|||
fi
|
||||
|
||||
# Validate the download variable separately because it's optional
|
||||
if grep -q '^download=' "$buildfile" ; then
|
||||
if ! grep -q '^download=[*p*://]*' "$buildfile" ; then
|
||||
if [[ -n $download ]] ; then
|
||||
if ! echo "$download" | grep -E -q '(https|http|ftp)://[^"]+' ; then
|
||||
err "Invalid URL in the 'download' variable in the build file."
|
||||
fi
|
||||
fi
|
||||
|
@ -575,7 +583,7 @@ EOF
|
|||
fi
|
||||
|
||||
# Discard install directory if it's empty but don't error out
|
||||
rmdir --ignore-fail-on-non-empty install
|
||||
rmdir lib &> /dev/null || true
|
||||
|
||||
# Discard charset.alias
|
||||
if [[ -f lib/charset.alias ]] ; then
|
||||
|
@ -584,7 +592,7 @@ EOF
|
|||
fi
|
||||
|
||||
# Also discard the lib directory if it's empty but don't error out
|
||||
rmdir --ignore-fail-on-non-empty lib
|
||||
rmdir lib &> /dev/null || true
|
||||
|
||||
tar cvf - . --format gnu \
|
||||
--xform 'sx^\./\(.\)x\1x' \
|
||||
|
|
Loading…
Reference in a new issue