mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Use non-Bashism indirect reference in parse_options. Change $@ to ${@:-} and update parse_options in all tools.
This commit is contained in:
@@ -119,9 +119,11 @@ usage_or_errors() {
|
|||||||
echo
|
echo
|
||||||
echo "Options and values after processing arguments:"
|
echo "Options and values after processing arguments:"
|
||||||
echo
|
echo
|
||||||
for opt in $(ls "$PO_DIR"); do
|
(
|
||||||
|
cd "$PO_DIR"
|
||||||
|
for opt in *; do
|
||||||
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
||||||
local varvalue="${!varname}"
|
eval local varvalue=\$$varname
|
||||||
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
||||||
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
||||||
then varvalue="TRUE"
|
then varvalue="TRUE"
|
||||||
@@ -132,6 +134,7 @@ usage_or_errors() {
|
|||||||
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -191,7 +194,7 @@ parse_options() {
|
|||||||
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_parse_command_line "$@"
|
_parse_command_line "${@:-""}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_parse_pod() {
|
_parse_pod() {
|
||||||
@@ -283,7 +286,7 @@ _eval_po() {
|
|||||||
|
|
||||||
_parse_config_files() {
|
_parse_config_files() {
|
||||||
|
|
||||||
for config_file in "$@"; do
|
for config_file in "${@:-""}"; do
|
||||||
test -f "$config_file" || continue
|
test -f "$config_file" || continue
|
||||||
|
|
||||||
while read config_opt; do
|
while read config_opt; do
|
||||||
@@ -317,7 +320,7 @@ _parse_command_line() {
|
|||||||
local required_arg=""
|
local required_arg=""
|
||||||
local spec=""
|
local spec=""
|
||||||
|
|
||||||
for opt in "$@"; do
|
for opt in "${@:-""}"; do
|
||||||
if [ "$opt" = "--" -o "$opt" = "----" ]; then
|
if [ "$opt" = "--" -o "$opt" = "----" ]; then
|
||||||
HAVE_EXT_ARGV=1
|
HAVE_EXT_ARGV=1
|
||||||
continue
|
continue
|
||||||
|
@@ -121,9 +121,11 @@ usage_or_errors() {
|
|||||||
echo
|
echo
|
||||||
echo "Options and values after processing arguments:"
|
echo "Options and values after processing arguments:"
|
||||||
echo
|
echo
|
||||||
for opt in $(ls "$PO_DIR"); do
|
(
|
||||||
|
cd "$PO_DIR"
|
||||||
|
for opt in *; do
|
||||||
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
||||||
local varvalue="${!varname}"
|
eval local varvalue=\$$varname
|
||||||
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
||||||
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
||||||
then varvalue="TRUE"
|
then varvalue="TRUE"
|
||||||
@@ -134,6 +136,7 @@ usage_or_errors() {
|
|||||||
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -588,7 +588,7 @@ main() {
|
|||||||
# possible to include without executing, and thus test.
|
# possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
||||||
main "$@"
|
main "${@:-""}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
19
bin/pt-stalk
19
bin/pt-stalk
@@ -121,9 +121,11 @@ usage_or_errors() {
|
|||||||
echo
|
echo
|
||||||
echo "Options and values after processing arguments:"
|
echo "Options and values after processing arguments:"
|
||||||
echo
|
echo
|
||||||
for opt in $(ls "$PO_DIR"); do
|
(
|
||||||
|
cd "$PO_DIR"
|
||||||
|
for opt in *; do
|
||||||
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
||||||
local varvalue="${!varname}"
|
eval local varvalue=\$$varname
|
||||||
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
||||||
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
||||||
then varvalue="TRUE"
|
then varvalue="TRUE"
|
||||||
@@ -134,6 +136,7 @@ usage_or_errors() {
|
|||||||
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -193,7 +196,7 @@ parse_options() {
|
|||||||
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_parse_command_line "$@"
|
_parse_command_line "${@:-""}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_parse_pod() {
|
_parse_pod() {
|
||||||
@@ -285,7 +288,7 @@ _eval_po() {
|
|||||||
|
|
||||||
_parse_config_files() {
|
_parse_config_files() {
|
||||||
|
|
||||||
for config_file in "$@"; do
|
for config_file in "${@:-""}"; do
|
||||||
test -f "$config_file" || continue
|
test -f "$config_file" || continue
|
||||||
|
|
||||||
while read config_opt; do
|
while read config_opt; do
|
||||||
@@ -319,7 +322,7 @@ _parse_command_line() {
|
|||||||
local required_arg=""
|
local required_arg=""
|
||||||
local spec=""
|
local spec=""
|
||||||
|
|
||||||
for opt in "$@"; do
|
for opt in "${@:-""}"; do
|
||||||
if [ "$opt" = "--" -o "$opt" = "----" ]; then
|
if [ "$opt" = "--" -o "$opt" = "----" ]; then
|
||||||
HAVE_EXT_ARGV=1
|
HAVE_EXT_ARGV=1
|
||||||
continue
|
continue
|
||||||
@@ -1197,7 +1200,7 @@ if [ "${0##*/}" = "$TOOL" ] \
|
|||||||
# Parse command line options. We must do this first so we can
|
# Parse command line options. We must do this first so we can
|
||||||
# see if --daemonize was specified.
|
# see if --daemonize was specified.
|
||||||
mk_tmpdir
|
mk_tmpdir
|
||||||
parse_options "$0" "$@"
|
parse_options "$0" "${@:-""}"
|
||||||
|
|
||||||
# Verify and set TRIGGER_FUNCTION based on --function.
|
# Verify and set TRIGGER_FUNCTION based on --function.
|
||||||
if ! set_trg_func "$OPT_FUNCTION"; then
|
if ! set_trg_func "$OPT_FUNCTION"; then
|
||||||
@@ -1264,7 +1267,7 @@ if [ "${0##*/}" = "$TOOL" ] \
|
|||||||
# the child's PID.
|
# the child's PID.
|
||||||
make_pid_file "$OPT_PID" $$
|
make_pid_file "$OPT_PID" $$
|
||||||
|
|
||||||
main "$@" </dev/null 1>>"$OPT_LOG" 2>&1 &
|
main "${@:-""}" </dev/null 1>>"$OPT_LOG" 2>&1 &
|
||||||
|
|
||||||
# Update PID file with the child's PID.
|
# Update PID file with the child's PID.
|
||||||
# The child PID is $BASHPID but that special var is only
|
# The child PID is $BASHPID but that special var is only
|
||||||
@@ -1273,7 +1276,7 @@ if [ "${0##*/}" = "$TOOL" ] \
|
|||||||
echo "$!" > "$OPT_PID"
|
echo "$!" > "$OPT_PID"
|
||||||
else
|
else
|
||||||
[ "$OPT_STALK" ] && make_pid_file "$OPT_PID" $$
|
[ "$OPT_STALK" ] && make_pid_file "$OPT_PID" $$
|
||||||
main "$@"
|
main "${@:-""}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -128,9 +128,11 @@ usage_or_errors() {
|
|||||||
echo
|
echo
|
||||||
echo "Options and values after processing arguments:"
|
echo "Options and values after processing arguments:"
|
||||||
echo
|
echo
|
||||||
for opt in $(ls "$PO_DIR"); do
|
(
|
||||||
|
cd "$PO_DIR"
|
||||||
|
for opt in *; do
|
||||||
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
||||||
local varvalue="${!varname}"
|
eval local varvalue=\$$varname
|
||||||
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
||||||
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
if [ "$varvalue" -a "$varvalue" = "yes" ];
|
||||||
then varvalue="TRUE"
|
then varvalue="TRUE"
|
||||||
@@ -141,6 +143,7 @@ usage_or_errors() {
|
|||||||
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -118,9 +118,11 @@ usage_or_errors() {
|
|||||||
echo
|
echo
|
||||||
echo "Options and values after processing arguments:"
|
echo "Options and values after processing arguments:"
|
||||||
echo
|
echo
|
||||||
for opt in $(ls "$PO_DIR"); do
|
(
|
||||||
|
cd "$PO_DIR"
|
||||||
|
for opt in *; do
|
||||||
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
|
||||||
local varvalue="${!varname}"
|
eval local varvalue=\$$varname
|
||||||
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
|
||||||
# Typeless option, like --version, so it's given/TRUE
|
# Typeless option, like --version, so it's given/TRUE
|
||||||
# or not given/FALSE.
|
# or not given/FALSE.
|
||||||
@@ -133,6 +135,7 @@ usage_or_errors() {
|
|||||||
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user