1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#!/bin/sh
## This Source Code Form is subject to the terms of the Mozilla Public
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
##
# Exit immediately if a pipeline, which may consist of a single simple command,
# a list, or a compound command returns a non-zero status
set -e
# Each variable or function that is created or modified is given the export
# attribute and marked for export to the environment of subsequent commands.
set -a
# shellcheck source=/dev/null
#
# TODO: when shellcheck adds support for relative paths, change to
# shellcheck source=./rabbitmq-env
. "${0%/*}"/rabbitmq-env
# Uncomment for debugging
# echo "\$# : $#"
# echo "\$0: $0"
# echo "\$1: $1"
# echo "\$2: $2"
# echo "\$3: $3"
# echo "\$4: $4"
# echo "\$5: $5"
# set -x
_tmp_help_requested='false'
for _tmp_argument in "$@"
do
if [ "$_tmp_argument" = '--help' ]
then
_tmp_help_requested='true'
break
fi
done
if [ "$1" = 'help' ] || [ "$_tmp_help_requested" = 'true' ]
then
unset _tmp_help_requested
# In this case, we do not require input and can exit early since
# help was requested
#
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmqctl 'noinput' "$@"
exit "$?"
fi
unset _tmp_help_requested
maybe_noinput='noinput'
case "$@" in
*add_user*)
if [ "$#" -eq 2 ]
then
# In this case, input is required to provide the password:
#
# rabbitmqctl add_user bob
#
maybe_noinput='input'
elif [ "$#" -eq 3 ]
then
# In these cases, input depends on the arguments provided:
#
# rabbitmqctl add_user bob --pre-hashed-password (input needed)
# rabbitmqctl add_user bob bobpassword (NO input needed)
# rabbitmqctl add_user --pre-hashed-password bob (input needed)
#
for _tmp_argument in "$@"
do
if [ "$_tmp_argument" = '--pre-hashed-password' ]
then
maybe_noinput='input'
break
fi
done
elif [ "$#" -gt 3 ]
then
# If there are 4 or more arguments, no input is needed:
#
# rabbitmqctl add_user bob --pre-hashed-password HASHVALUE
# rabbitmqctl add_user bob bobpassword IGNORED
# rabbitmqctl add_user --pre-hashed-password bob HASHVALUE
#
maybe_noinput='noinput'
fi
;;
*authenticate_user*)
if [ "$#" -eq 2 ]
then
# In this case, input is required to provide the password:
#
# rabbitmqctl authenticate_user bob
#
maybe_noinput='input'
elif [ "$#" -gt 2 ]
then
# If there are 2 or more arguments, no input is needed:
#
maybe_noinput='noinput'
fi
;;
*change_password*)
maybe_noinput='input'
if [ "$#" -gt 2 ]
then
# If there are 3 or more arguments, no input is needed:
#
# rabbitmqctl change_password sue foobar
# rabbitmqctl change_password sue newpassword IGNORED
#
maybe_noinput='noinput'
fi
;;
*decode*|*encode*)
# It is unlikely that these commands will be run in a shell script loop
# with redirection, so always assume that stdin input is needed
#
maybe_noinput='input'
;;
*eval*)
if [ "$#" -eq 1 ]
then
# If there is only one argument, 'eval', then input is required
#
# rabbitmqctl eval
#
maybe_noinput='input'
fi
;;
*hash_password*)
if [ "$#" -eq 1 ]
then
# If there is only one argument, 'hash_password', then input is required
#
# rabbitmqctl hash_password
#
maybe_noinput='input'
fi
;;
*)
maybe_noinput='noinput'
;;
esac
unset _tmp_argument
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmqctl "$maybe_noinput" "$@"
|