Commit a68354eb authored by Oliver Smith's avatar Oliver Smith Committed by Natanael Copa
Browse files

newapkbuild: check arguments and improve usage()

* argument sanity checks:
    * check if missing
    * check if specified more than once (see below)
  * specifying more than one buildtype flag
  * `-n` (set pkgname) without using SRCURL as last argument
  * `-s` (sourceforge source) without using PKGNAME as last argument
* Typo fix: exist -> exists
* `usage()`:
  * always print PKGNAME and PKGDESC (instead of NAME and DESC,
    NAME was used in one place and PKGNAME in another)
  * link to <>
  * `-m` (meson) flag was missing in short usage line at the top
  * indicate that the buildtypes are exclusive
  * `-c` flag: remove "to new directory" wording to make the
    message shorter (this should be obvious)
  * remove empty line at the end

NOTE: Before this commit, the `PKGNAME[-PKGVER] | SRCURL` was allowed
to be specified more than once, and the code looped over the arguments.
But this was not documented in `usage()` and had unexpected results:

$ newapkbuild first second third
$ tree
___ first
    ___ APKBUILD
    ___ first
    ___ ___ APKBUILD
    ___ ___ first
    ___ ___ ___ APKBUILD
    ___ ___ ___ src
    ___ ___ src
    ___ src
parent 0bb0bd84
......@@ -344,13 +344,14 @@ __EOF__
usage() {
cat >&2 <<-__EOF__
$program $program_version - generate a new APKBUILD
Usage: $program [-n NAME] [-d DESC] [-l LICENSE] [-u URL]
[-aCpy] [-s] [-cfh]
Usage: $program [-n PKGNAME] [-d PKGDESC] [-l LICENSE] [-u URL]
[-a | -C | -m | -p | -y] [-s] [-c] [-f] [-h]
-n Set package name to NAME
-d Set package description (pkgdesc) to DESC
-l Set package license to LICENSE
-n Set package name to PKGNAME (only use with SRCURL)
-d Set package description to PKGDESC
-l Set package license to LICENSE, use identifiers from:
-u Set package URL
-a Create autotools package (use ./configure ...)
-C Create CMake package (Assume cmake/ is there)
......@@ -358,33 +359,58 @@ usage() {
-p Create perl package (Assume Makefile.PL is there)
-y Create python package (Assume is there)
-s Use sourceforge source URL
-c Copy a sample init.d, conf.d, and install script to new directory
-f Force even if directory already exist
-c Copy a sample init.d, conf.d, and install script
-f Force even if directory already exists
-h Show this help
set_buildtype() {
if [ -n "$buildtype" ]; then
error "More than one buildtype flag specified ($buildtype and $1)"
exit 1
check_arguments() {
if [ $# -eq 0 ]; then
error "Missing required argument: PKGNAME[-PKGVER] | SRCURL"
exit 1
if [ $# -gt 1 ]; then
error "Unrecognized arguments: $*"
exit 1
if ! is_url "$1" && [ -n "$pkgname" ]; then
error "-n is only allowed when using SRCURL as last argument"
exit 1
if is_url "$1" && [ -n "$sourceforge" ]; then
error "-s is only allowed when using PKGNAME as last argument"
exit 1
while getopts "acCmd:fhl:n:pyu:s" opt; do
case $opt in
'a') buildtype="autotools";;
'a') set_buildtype "autotools";;
'c') cpinitd=1;;
'C') buildtype="cmake";;
'm') buildtype="meson";;
'C') set_buildtype "cmake";;
'm') set_buildtype "meson";;
'd') pkgdesc="$OPTARG";;
'f') force=1;;
'h') usage; exit;;
'l') license="$OPTARG";;
'n') pkgname="$OPTARG";;
'p') buildtype="perl";;
'y') buildtype="python";;
'p') set_buildtype "perl";;
'y') set_buildtype "python";;
'u') url="$OPTARG";;
's') sourceforge=1;;
shift $(( $OPTIND - 1 ))
while [ $# -gt 0 ]; do
newaport $1 || exit 1
check_arguments "$@"
newaport $1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment