mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-16 01:16:59 +02:00
eclass/estack: Sync with gentoo
It's from gentoo commit 2f653f03c381cd6c4b1c7fc3aa7b25901fc8b47f.
This commit is contained in:
parent
27432830c2
commit
a8c0b3a950
@ -1,4 +1,4 @@
|
|||||||
# Copyright 1999-2017 Gentoo Foundation
|
# Copyright 1999-2020 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# @ECLASS: estack.eclass
|
# @ECLASS: estack.eclass
|
||||||
@ -115,7 +115,8 @@ evar_pop() {
|
|||||||
local cnt=${1:-bad}
|
local cnt=${1:-bad}
|
||||||
case $# in
|
case $# in
|
||||||
0) cnt=1 ;;
|
0) cnt=1 ;;
|
||||||
1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;;
|
1) [[ -z ${cnt//[0-9]} ]] \
|
||||||
|
|| die "${FUNCNAME}: first arg must be a number: $*" ;;
|
||||||
*) die "${FUNCNAME}: only accepts one arg: $*" ;;
|
*) die "${FUNCNAME}: only accepts one arg: $*" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -153,12 +154,13 @@ evar_pop() {
|
|||||||
# eshopts_pop
|
# eshopts_pop
|
||||||
# @CODE
|
# @CODE
|
||||||
eshopts_push() {
|
eshopts_push() {
|
||||||
|
# Save both "shopt" and "set -o" option sets, because otherwise
|
||||||
|
# restoring posix would disable expand_aliases by side effect. #662586
|
||||||
|
estack_push eshopts "$(shopt -p -o) $(shopt -p)"
|
||||||
if [[ $1 == -[su] ]] ; then
|
if [[ $1 == -[su] ]] ; then
|
||||||
estack_push eshopts "$(shopt -p)"
|
[[ $# -le 1 ]] && return 0
|
||||||
[[ $# -eq 0 ]] && return 0
|
|
||||||
shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
|
shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
|
||||||
else
|
else
|
||||||
estack_push eshopts "$(shopt -p -o)"
|
|
||||||
[[ $# -eq 0 ]] && return 0
|
[[ $# -eq 0 ]] && return 0
|
||||||
set "$@" || die "${FUNCNAME}: bad options to set: $*"
|
set "$@" || die "${FUNCNAME}: bad options to set: $*"
|
||||||
fi
|
fi
|
||||||
@ -196,17 +198,5 @@ eumask_pop() {
|
|||||||
umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
|
umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: isdigit
|
|
||||||
# @USAGE: <number> [more numbers]
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Return true if all arguments are numbers.
|
|
||||||
isdigit() {
|
|
||||||
local d
|
|
||||||
for d ; do
|
|
||||||
[[ ${d:-bad} == *[!0-9]* ]] && return 1
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_ESTACK_ECLASS=1
|
_ESTACK_ECLASS=1
|
||||||
fi #_ESTACK_ECLASS
|
fi #_ESTACK_ECLASS
|
||||||
|
Loading…
Reference in New Issue
Block a user