yum__maintenance() {
command yum -y update
command yum -y upgrade
command yum clean all
}
yum__download() {
command yum -y install --downloadonly "$@"
}
yum() {
local cmdname=$1; shift
if type "yum__$cmdname" >/dev/null 2>&1; then
"yum__$cmdname" "$@"
else
command yum "$cmdname" "$@" # call the **real** yum command
fi
}
# if the functions above are sourced into an interactive interpreter, the user can
# just call "yum download" or "yum maintenance" with no further code needed.
# if invoked as a script rather than sourced, call function named on argv via the below;
# note that this must be the first operation other than a function definition
# for $_ to successfully distinguish between sourcing and invocation:
[[ $_ != $0 ]] && return
# make sure we actually *did* get passed a valid function name
if declare -f "$1" >/dev/null 2>&1; then
# invoke that function, passing arguments through
"$@" # same as "$1" "$2" "$3" ... for full argument list
else
echo "Function $1 not recognized" >&2
exit 1
fi