mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-19 19:40:37 +02:00
only short options are supported
This commit is contained in:
parent
a2ca62ed9e
commit
489a699e45
2 changed files with 5 additions and 74 deletions
|
@ -143,26 +143,26 @@ set -- "${OPTRET[@]}"
|
|||
unset _opt_short OPTRET
|
||||
while :; do
|
||||
case "$1" in
|
||||
-c|--config)
|
||||
-c)
|
||||
shift
|
||||
_f_config="$1"
|
||||
;;
|
||||
-k|--kernel)
|
||||
-k)
|
||||
shift
|
||||
KERNEL="$1"
|
||||
;;
|
||||
-d|--generatedir)
|
||||
-d)
|
||||
shift
|
||||
_opttargetdir="$1"
|
||||
;;
|
||||
-g|--generate)
|
||||
-g)
|
||||
shift
|
||||
[[ -d "$1" ]] && die 'Invalid image path -- must not be a directory'
|
||||
if ! _optgenimg="$(readlink -f "$1")" || [[ ! -e "${_optgenimg%/*}" ]]; then
|
||||
die "Unable to write to path: '%s'" "$1"
|
||||
fi
|
||||
;;
|
||||
-h|--help)
|
||||
-h)
|
||||
usage
|
||||
cleanup 0
|
||||
;;
|
||||
|
|
|
@ -4,59 +4,6 @@
|
|||
# simplified, stripped down, optimized for size and speed
|
||||
# by Tobias Powalowski <tpowa@archlinux.org>
|
||||
|
||||
# no long options support in archboot
|
||||
parseopts() {
|
||||
local opt='' i='' shortopts="$1"
|
||||
local -a unused_argv=()
|
||||
shift
|
||||
shift
|
||||
while (( $# )); do
|
||||
case "$1" in
|
||||
--) # explicit end of options
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-[!-]*) # short option
|
||||
for (( i = 1; i < ${#1}; i++ )); do
|
||||
opt=${1:i:1}
|
||||
# option doesn't exist
|
||||
if [[ $shortopts != *$opt* ]]; then
|
||||
printf "%s: invalid option -- '%s'\n" "${0##*/}" "$opt"
|
||||
OPTRET=(--)
|
||||
return 1
|
||||
fi
|
||||
OPTRET+=("-$opt")
|
||||
# option requires optarg
|
||||
if [[ "$shortopts" == *"${opt}:"* ]]; then
|
||||
# if we're not at the end of the option chunk, the rest is the optarg
|
||||
if (( i < ${#1} - 1 )); then
|
||||
OPTRET+=("${1:i+1}")
|
||||
break
|
||||
# if we're at the end, grab the the next positional, if it exists
|
||||
elif (( i == ${#1} - 1 )) && [[ -n "$2" ]]; then
|
||||
OPTRET+=("$2")
|
||||
shift
|
||||
break
|
||||
# parse failure
|
||||
else
|
||||
printf "%s: option '%s' requires an argument\n" "${0##*/}" "-$opt"
|
||||
OPTRET=(--)
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
;;
|
||||
*) # non-option arg encountered, add it as a parameter
|
||||
unused_argv+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
# add end-of-opt terminator and any leftover positional parameters
|
||||
OPTRET+=('--' "${unused_argv[@]}" "$@")
|
||||
return 0
|
||||
}
|
||||
|
||||
msg() {
|
||||
local mesg="$1"; shift
|
||||
# shellcheck disable=SC2059
|
||||
|
@ -368,22 +315,6 @@ run_build_hook() {
|
|||
return 0
|
||||
}
|
||||
|
||||
try_enable_color() {
|
||||
local colors
|
||||
if ! colors="$(tput colors 2>"${_NO_LOG}")"; then
|
||||
warning "Failed to enable color. Check your TERM environment variable"
|
||||
return
|
||||
fi
|
||||
if (( colors > 0 )) && tput setaf 0 &>"${_NO_LOG}"; then
|
||||
_color_none="$(tput sgr0)"
|
||||
_color_bold="$(tput bold)"
|
||||
_color_blue="$_color_bold$(tput setaf 4)"
|
||||
_color_green="$_color_bold$(tput setaf 2)"
|
||||
_color_red="$_color_bold$(tput setaf 1)"
|
||||
_color_yellow="$_color_bold$(tput setaf 3)"
|
||||
fi
|
||||
}
|
||||
|
||||
install_modules() {
|
||||
command tar --hard-dereference -C / -cpf - "$@" | tar -C "${BUILDROOT}" -xpf -
|
||||
msg "Generating module dependencies"
|
||||
|
|
Loading…
Reference in a new issue