From fa5484c81c40e0a5a05194909600716f39ce0faf Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 17 Apr 2012 19:23:15 -0400 Subject: mkinitcpio: adopt parseopts for option parsing Updates the doc and bash-completion, as well. Also adds the previously unmentioned -A option to the --help output. Signed-off-by: Dave Reisner --- mkinitcpio | 152 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 58 deletions(-) (limited to 'mkinitcpio') diff --git a/mkinitcpio b/mkinitcpio index 4618baa..9a3c343 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -41,21 +41,22 @@ mkinitcpio $version usage: ${0##*/} [options] Options: - -b BASEDIR Use BASEDIR. default: / - -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf - -g IMAGE Generate a cpio image as IMAGE. default: no - -H HOOKNAME Output help for hook 'HOOKNAME'. - -h Display this message. - -k KERNELVERSION Use KERNELVERSION. default: $(uname -r) - -L List all available hooks. - -M Display modules found via autodetection. - -n Disable colorized output messages. - -p PRESET Build specified preset from /etc/mkinitcpio.d - -S SKIPHOOKS Skip SKIPHOOKS (comma-separated) when building the image. - -s Save build directory. default: no - -t DIR Use DIR as the temporary build directory. - -v Verbose output. Default: no. - -z COMPRESS Use COMPRESS on resulting image + -A, --add Add specified hooks, comma separated, to image + -b, --basedir Use alternate base directory. (default: /) + -c, --config Use alternate config file. (default: /etc/mkinitcpio.conf) + -g, --generate Generate cpio image and write to specified path + -H, --hookhelp Display help for given hook and exit + -h, --help Display this message and exit + -k, --kernel Use specified kernel version (default: $(uname -r)) + -L, --listhooks List all available hooks + -M, --automods Display modules found via autodetection + -n, --nocolor Disable colorized output messages + -p, --preset Build specified preset from /etc/mkinitcpio.d + -S, --skiphooks Skip specified hooks, comma-separated, during build + -s, --save Save build directory. (default: no) + -t, --builddir Use DIR as the temporary build directory + -v, --verbose Verbose output (default: no) + -z, --compress Use an alternate compressor on the image EOF cleanup 1 @@ -109,51 +110,86 @@ get_kernver() { trap 'cleanup 130' INT trap 'cleanup 143' TERM -while getopts ':A:c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do - case $arg in - A) IFS=, read -r -a add <<< "$OPTARG" - ADDHOOKS+=("${add[@]}") - unset add ;; - c) CONFIG=$OPTARG ;; - k) optkver=$OPTARG ;; - s) SAVELIST=1 ;; - b) BASEDIR=$OPTARG ;; - g) GENIMG=$OPTARG ;; - h) usage ;; - p) PRESET=$OPTARG ;; - n) COLOR=0 ;; - v) QUIET=0 ;; - S) IFS=, read -r -a skip <<< "$OPTARG" - SKIPHOOKS+=("${skip[@]}") - unset skip ;; - H) if script=$(find_in_dirs "$OPTARG" "${INSTDIR[@]}"); then - . "$script" - if [[ $(type -t help) != function ]]; then - error "No help for hook $OPTARG" - exit 1 - fi - else - error "No hook '$OPTARG'" - exit 1 - fi - msg "Help for hook '$OPTARG':" - help - exit 0 ;; - L) msg "Available hooks" - for dir in "${INSTDIR[@]}"; do - ( cd "$dir" >/dev/null; printf ' %s\n' * ) - done | column -c$(tput cols) - exit 0 ;; - M) SHOW_AUTOMODS=1 ;; - t) TMPDIR=$OPTARG ;; - z) optcompress=$OPTARG ;; - :) error "option requires an argument -- '$OPTARG' (use -h for help)" - exit 1 ;; - \?) error "invalid option -- '$OPTARG' (use -h for help)" - exit 1 ;; +OPT_SHORT='A:b:c:g:H:hk:mnLMp:S:st:vz:' +OPT_LONG=('add:' 'basedir:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks' + 'automods' 'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:') + +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case $1 in + -A|--add) + shift + IFS=, read -r -a add <<< "$1" + ADDHOOKS+=("${add[@]}") + unset add ;; + -c|--config) + shift + CONFIG=$1 ;; + -k|--kernel) + shift + optkver=$1 ;; + -s|--save) + SAVELIST=1 ;; + -b|--basedir) + shift + BASEDIR=$1 ;; + -g|--generate) + shift + GENIMG=$1 ;; + -h|--help) + usage ;; + -p|--preset) + shift + PRESET=$1 ;; + -n|--nocolor) + COLOR=0 ;; + -v|--verbose) + QUIET=0 ;; + -S|--skiphooks) + shift + IFS=, read -r -a skip <<< "$1" + SKIPHOOKS+=("${skip[@]}") + unset skip ;; + -H|--hookhelp) + shift + if script=$(find_in_dirs "$1" "${INSTDIR[@]}"); then + . "$script" + if [[ $(type -t help) != function ]]; then + error "No help for hook $1" + exit 1 + fi + else + error "No hook '$1'" + exit 1 + fi + msg "Help for hook '$1':" + help + exit 0 ;; + -L|--listhooks) + msg "Available hooks" + for dir in "${INSTDIR[@]}"; do + ( cd "$dir" >/dev/null; printf ' %s\n' * ) + done | column -c$(tput cols) + exit 0 ;; + -M|--automods) + SHOW_AUTOMODS=1 ;; + -t|--builddir) + shift + TMPDIR=$1 ;; + -z|--compress) + shift + optcompress=$1 ;; + --) + shift + break 2 ;; esac + shift done -shift $((OPTIND - 1)) if [[ -t 1 ]] && (( COLOR )); then # prefer terminal safe colored and bold text when tput is supported -- cgit v1.2.3-24-g4f1b