@@ -20,4 +20,135 @@ set -a
2020# shellcheck source=./rabbitmq-env
2121. " ${0%/* } " /rabbitmq-env
2222
23- run_escript " ${ESCRIPT_DIR:? must be defined} " /rabbitmqctl ' noinput' " $@ "
23+ # Uncomment for debugging
24+ # echo "\$# : $#"
25+ # echo "\$0: $0"
26+ # echo "\$1: $1"
27+ # echo "\$2: $2"
28+ # echo "\$3: $3"
29+ # echo "\$4: $4"
30+ # echo "\$5: $5"
31+ # set -x
32+
33+ _tmp_help_requested=' false'
34+
35+ for _tmp_argument in " $@ "
36+ do
37+ if [ " $_tmp_argument " = ' --help' ]
38+ then
39+ _tmp_help_requested=' true'
40+ break
41+ fi
42+ done
43+
44+ if [ " $1 " = ' help' ] || [ " $_tmp_help_requested " = ' true' ]
45+ then
46+ unset _tmp_help_requested
47+ # In this case, we do not require input and can exit early since
48+ # help was requested
49+ #
50+ run_escript " ${ESCRIPT_DIR:? must be defined} " /rabbitmqctl ' noinput' " $@ "
51+ exit " $? "
52+ fi
53+
54+ unset _tmp_help_requested
55+
56+ maybe_noinput=' noinput'
57+
58+ case " $1 " in
59+ add_user)
60+ if [ " $# " -eq 2 ]
61+ then
62+ # In this case, input is required to provide the password:
63+ #
64+ # rabbitmqctl add_user bob
65+ #
66+ maybe_noinput=' input'
67+ elif [ " $# " -eq 3 ]
68+ then
69+ # In these cases, input depends on the arguments provided:
70+ #
71+ # rabbitmqctl add_user bob --pre-hashed-password (input needed)
72+ # rabbitmqctl add_user bob bobpassword (NO input needed)
73+ # rabbitmqctl add_user --pre-hashed-password bob (input needed)
74+ #
75+ for _tmp_argument in " $@ "
76+ do
77+ if [ " $_tmp_argument " = ' --pre-hashed-password' ]
78+ then
79+ maybe_noinput=' input'
80+ break
81+ fi
82+ done
83+ elif [ " $# " -gt 3 ]
84+ then
85+ # If there are 4 or more arguments, no input is needed:
86+ #
87+ # rabbitmqctl add_user bob --pre-hashed-password HASHVALUE
88+ # rabbitmqctl add_user bob bobpassword IGNORED
89+ # rabbitmqctl add_user --pre-hashed-password bob HASHVALUE
90+ #
91+ maybe_noinput=' noinput'
92+ fi
93+ ;;
94+ authenticate_user)
95+ if [ " $# " -eq 2 ]
96+ then
97+ # In this case, input is required to provide the password:
98+ #
99+ # rabbitmqctl authenticate_user bob
100+ #
101+ maybe_noinput=' input'
102+ elif [ " $# " -gt 2 ]
103+ then
104+ # If there are 2 or more arguments, no input is needed:
105+ #
106+ maybe_noinput=' noinput'
107+ fi
108+ ;;
109+ change_password)
110+ maybe_noinput=' input'
111+ if [ " $# " -gt 2 ]
112+ then
113+ # If there are 3 or more arguments, no input is needed:
114+ #
115+ # rabbitmqctl change_password sue foobar
116+ # rabbitmqctl change_password sue newpassword IGNORED
117+ #
118+ maybe_noinput=' noinput'
119+ fi
120+ ;;
121+ decode|encode)
122+ # It is unlikely that these commands will be run in a shell script loop
123+ # with redirection, so always assume that stdin input is needed
124+ #
125+ maybe_noinput=' input'
126+ ;;
127+ eval)
128+ if [ " $# " -eq 1 ]
129+ then
130+ # If there is only one argument, 'eval', then input is required
131+ #
132+ # rabbitmqctl eval
133+ #
134+ maybe_noinput=' input'
135+ fi
136+ ;;
137+ hash_password)
138+ if [ " $# " -eq 1 ]
139+ then
140+ # If there is only one argument, 'hash_password', then input is required
141+ #
142+ # rabbitmqctl hash_password
143+ #
144+ maybe_noinput=' input'
145+ fi
146+ ;;
147+ * )
148+ maybe_noinput=' noinput'
149+ ;;
150+ esac
151+
152+ unset _tmp_argument
153+
154+ run_escript " ${ESCRIPT_DIR:? must be defined} " /rabbitmqctl " $maybe_noinput " " $@ "
0 commit comments