various: use long options, rework usages

This commit is contained in:
Dubiousjim 2013-07-05 00:21:19 -04:00 committed by Natanael Copa
parent 7b2030a06a
commit ef9fb52908
6 changed files with 167 additions and 93 deletions

View File

@ -90,30 +90,46 @@ do_keygen() {
msg "" msg ""
} }
# print usage and exit
usage() { usage() {
echo "abuild-keygen $abuild_ver" cat >&2 <<__EOF__
echo "usage: abuild-keygen [-ih]" $prog $abuild_ver - generate signing keys
echo "options:" Usage: $prog [-a|--append] [-i|--install] [-n]
echo " -a Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf" Options:
echo " -i Install public key into /etc/apk/keys using sudo" -a, --append Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf
echo " -h Show this help" -i, --install Install public key into /etc/apk/keys using sudo
echo " -n Non-interactive. Use defaults" -n Non-interactive. Use defaults
echo " -q Quiet mode" -q, --quiet
echo "" -h, --help Show this help
exit 1
__EOF__
} }
append_config=
install_pubkey=
non_interactive=
quiet=
while getopts "ahinq" opt; do args=`getopt -o ainqh --long append,install,quiet,help -n "$prog" -- "$@"`
case $opt in if [ $? -ne 0 ]; then
a) append_config=yes;; usage
h) usage;; exit 2
i) install_pubkey=yes;; fi
n) non_interactive=yes;; eval set -- "$args"
q) quiet=-quiet;; while true; do
case $1 in
-a|--append) append_config=1;;
-i|--install) install_pubkey=1;;
-n) non_interactive=yes;;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac esac
shift
done done
shift $(( $OPTIND - 1)) if [ $# -ne 0 ]; then
usage
exit 2
fi
do_keygen do_keygen

View File

@ -40,26 +40,43 @@ do_sign() {
} }
usage() { usage() {
echo "abuild-sign $abuild_ver" cat >&2 <<__EOF__
echo "usage: abuild-sign [-hq] [-k PRIVKEY] [-p PUBKEY] INDEXFILE..." $prog $abuild_ver - sign indexes
echo "options:" Usage: $prog [-k PRIVKEY] [-p PUBKEY] INDEXFILE...
echo " -h Show this help" Options:
echo " -k The private key to use for signing" -k, --private KEY The private key to use for signing
echo " -p The name of public key. apk add will look for /etc/apk/keys/PUBKEY" -p, --public KEY The name of public key. apk add will look for /etc/apk/keys/KEY
exit 1 -q, --quiet
-h, --help Show this help
__EOF__
} }
privkey="$PACKAGER_PRIVKEY" privkey="$PACKAGER_PRIVKEY"
pubkey=
quiet=
while getopts "hk:p:q" opt; do args=`getopt -o k:p:qh --long private:,public:,quiet,help -n "$prog" -- "$@"`
case $opt in if [ $? -ne 0 ]; then
h) usage;; usage
k) privkey=$OPTARG;; exit 2
p) pubkey=$OPTARG;; fi
q) quiet=yes;; eval set -- "$args"
while true; do
case $1 in
-k|--private) privkey=$2; shift;;
-p|--public) pubkey=$2; shift;;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac esac
shift
done done
shift $(( $OPTIND - 1)) if [ $# -eq 0 ]; then
usage
exit 2
fi
if [ -z "$privkey" ]; then if [ -z "$privkey" ]; then
echo "No private key found. Use 'abuild-keygen' to generate the keys" echo "No private key found. Use 'abuild-keygen' to generate the keys"

View File

@ -56,29 +56,48 @@ fixes #${fixes#\#}
} }
usage() { usage() {
echo "$prog - utility to bump pkgver in APKBUILDs" cat >&2 <<__EOF__
echo "usage: $prog [-hR] [-s CVE-1,CVE-2,...] [-f ISSUE]" $prog $abuild_ver - bump pkgver in APKBUILDs
echo "" Usage: $prog [-s CVE-1,CVE-2,...] [-f ISSUE] [-R|--recursive] [-k|--keep] PKGNAME-1.2.3 ...
echo " -h show this help" Options:
echo " -R run abuild with -R for recursive building" -s, --security CVE1,CVE-2,... Security update
echo " -k keep existing packages" -f, --fixes ISSUE Fixes ISSUE
echo " -s security update" -R, --recursive Run abuild with -R for recursive building
echo " -f fixes ISSUE" -k, --keep Run abuild with -k to keep existing packages
exit 0 -q, --quiet
-h, --help Show this help
__EOF__
} }
keep= keep=
recursive="-r" recursive="-r"
while getopts "f:hkRs:" opt; do cvelist=
case $opt in fixes=
f) fixes="${OPTARG}";;
h) usage;; args=`getopt -o s:Rkqh --long security:,recursive,keep,quiet,help -n "$prog" -- "$@"`
k) keep="-k";; if [ $? -ne 0 ]; then
R) recursive="-R";; usage
s) cvelist="$OPTARG";; exit 2
fi
eval set -- "$args"
while true; do
case $1 in
-s|--security) cvelist="$2"; shift;;
-f|--fixes) fixes="$2"; shift;;
-R|--recursive) recursive="-R";;
-k|--keep) keep="-k";;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac esac
shift
done done
shift $(( $OPTIND - 1)) if [ $# -eq 0 ]; then
usage
exit 2
fi
abuild_opts="$recursive $keep" abuild_opts="$recursive $keep"

View File

@ -55,42 +55,51 @@ do_nothing() {
return 0 return 0
} }
do_usage() { usage() {
cat <<__EOF__ cat >&2 <<__EOF__
Usage: $prog -a|-h|-s NUM|-t|-z [-f] FILE... $prog $abuild_ver - display or bump pkgrel in APKBUILDs
Commands: Usage: $prog [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM] [-t|--test] [-f|--force] DIR or APKBUILD...
-a Add 1 to current pkgrel
-g Only do the change on files that have clean git status
-h Show this help
-s Set pkgrel to NUM
-t Only verify that files are in proper format
-z Set pkgrel to 0
Options: Options:
-f Force, even if given files are not in proper format -z, --zero Set pkgrel to 0
-a, --add Add 1 to current pkgrel
-g, --clean-git Only operate on APKBUILDs with clean git status
-s, --set NUM Set pkgrel to NUM
-t, --test Only verify that files have a valid pkgrel
-f, --force Operate on files without a valid pkgrel
-h, --help Show this help
__EOF__ __EOF__
} }
cmd=do_show cmd=do_show
force= force=
while getopts "afghs:tz" opt; do setto=
case $opt in only_clean_git=
a) cmd=do_add;;
g) only_clean_git=1;; args=`getopt -o zags:tfqh --long zero,add,clean-git,set:,test,force,quiet,help -n "$prog" -- "$@"`
f) force=1;; if [ $? -ne 0 ]; then
h) cmd=do_usage;; usage
s) setto=$OPTARG; cmd=do_set;; exit 2
t) cmd=do_nothing;; fi
z) setto=0; cmd=do_set;; eval set -- "$args"
while true; do
case $1 in
-z|--zero) setto=0; cmd=do_set;;
-a|--add) cmd=do_add;;
-g|--clean-git) only_clean_git=1;;
-s|--set) setto=$2; shift; cmd=do_set;;
-t|--test) cmd=do_nothing;;
-f|--force) force=1;;
-q|--quiet) quiet=1;; # noop
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac esac
shift
done done
shift $(( $OPTIND - 1))
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
do_usage usage
exit 1 exit 2
fi fi
do_verify "$@" || exit 1 do_verify "$@" || exit 1

View File

@ -16,8 +16,20 @@ fi
. "$datadir/functions.sh" . "$datadir/functions.sh"
usage() {
cat >&2 <<__EOF__
$prog $abuild_ver - find ABI breakages in package upgrades
Usage: $prog
Run in the directory of a built package.
__EOF__
}
if [ $# -gt 0 ]; then
usage
exit 2
fi
if ! [ -f "$abuild_conf" ] && ! [ -f "$abuild_userconf" ]; then if ! [ -f "$abuild_conf" ] && ! [ -f "$abuild_userconf" ]; then
die "no abuild.conf found" die "no abuild.conf found"

View File

@ -253,22 +253,23 @@ __EOF__
} }
usage() { usage() {
echo "$prog $abuild_ver" cat >&2 <<__EOF__
echo "usage: $prog [-cfh] [-d DESC] [-l LICENSE] [-n NAME] [-u URL] PKGNAME[-PKGVER]|SRCURL" $prog $abuild_ver - generate a new APKBUILD
echo "Options:" Usage: $prog [-cfh] [-d DESC] [-l LICENSE] [-n NAME] [-u URL] PKGNAME[-PKGVER]|SRCURL
echo " -a Create autotools (use ./configure ...)" Options:
echo " -c Copy a sample init.d, conf.d, and install script to new directory" -n Set package name to NAME
echo " -d Set package description (pkgdesc) to DESC" -d Set package description (pkgdesc) to DESC
echo " -f Force even if directory already exist" -l Set package license to LICENSE
echo " -h Show this help" -u Set package URL
echo " -l Set package license to LICENSE" -a Create autotools (use ./configure ...)
echo " -n Set package name to NAME" -p Create perl package (Assume Makefile.PL is there)
echo " -p Create perl package (Assume Makefile.PL is there)" -y Create python package (Assume setup.py is there)
echo " -y Create python package (Assume setup.py is there)" -s Use sourceforge source URL
echo " -u Set package URL" -c Copy a sample init.d, conf.d, and install script to new directory
echo " -s Use sourceforge source URL" -f Force even if directory already exist
echo "" -h Show this help
exit 0
__EOF__
} }
while getopts "acd:fhl:n:pyu:s" opt; do while getopts "acd:fhl:n:pyu:s" opt; do
@ -277,7 +278,7 @@ while getopts "acd:fhl:n:pyu:s" opt; do
'c') cpinitd=1;; 'c') cpinitd=1;;
'd') pkgdesc="$OPTARG";; 'd') pkgdesc="$OPTARG";;
'f') force=1;; 'f') force=1;;
'h') usage;; 'h') usage; exit;;
'l') license="$OPTARG";; 'l') license="$OPTARG";;
'n') pkgname="$OPTARG";; 'n') pkgname="$OPTARG";;
'p') buildtype="perl";; 'p') buildtype="perl";;