2016-01-12 13:08:43 +01:00
|
|
|
#!/usr/bin/env bash
|
2013-01-11 21:16:42 +01:00
|
|
|
#
|
2013-08-06 21:32:15 +02:00
|
|
|
# Delete the "guest" default user and replace it with a Zulip user
|
2013-01-11 21:16:42 +01:00
|
|
|
# with a real password
|
2016-01-12 13:08:43 +01:00
|
|
|
set -e
|
|
|
|
set -x
|
2013-01-11 21:16:42 +01:00
|
|
|
|
2020-10-15 23:52:45 +02:00
|
|
|
if [ "$EUID" -eq 0 ]; then
|
|
|
|
rabbitmqctl=(rabbitmqctl)
|
|
|
|
else
|
|
|
|
rabbitmqctl=(sudo rabbitmqctl)
|
|
|
|
fi
|
|
|
|
|
2017-04-19 07:48:40 +02:00
|
|
|
if [ -n "$RABBITMQ_NODE" ]; then
|
2020-10-15 23:52:45 +02:00
|
|
|
rabbitmqctl+=(-n "$RABBITMQ_NODE")
|
2017-04-19 07:48:40 +02:00
|
|
|
fi
|
2016-05-08 04:02:32 +02:00
|
|
|
RABBITMQ_USERNAME=$("$(dirname "$0")/../get-django-setting" RABBITMQ_USERNAME)
|
|
|
|
RABBITMQ_PASSWORD=$("$(dirname "$0")/../get-django-setting" RABBITMQ_PASSWORD)
|
2019-03-15 01:08:55 +01:00
|
|
|
|
2020-10-16 00:14:26 +02:00
|
|
|
# Wait for RabbitMQ to start up
|
|
|
|
try_ping() {
|
|
|
|
# `rabbitmqctl ping` requires 3.7.6 or newer
|
|
|
|
out="$("${rabbitmqctl[@]}" eval 'net_adm:ping(node()).')" && [ "$out" = 'pong' ]
|
|
|
|
}
|
|
|
|
retries=9
|
|
|
|
while ! try_ping 2>/dev/null; do
|
|
|
|
sleep 1
|
|
|
|
if ! ((retries -= 1)); then
|
|
|
|
try_ping
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-10-15 23:52:45 +02:00
|
|
|
"${rabbitmqctl[@]}" delete_user "$RABBITMQ_USERNAME" || true
|
|
|
|
"${rabbitmqctl[@]}" delete_user zulip || true
|
|
|
|
"${rabbitmqctl[@]}" delete_user guest || true
|
|
|
|
"${rabbitmqctl[@]}" add_user "$RABBITMQ_USERNAME" "$RABBITMQ_PASSWORD"
|
|
|
|
"${rabbitmqctl[@]}" set_user_tags "$RABBITMQ_USERNAME" administrator
|
|
|
|
"${rabbitmqctl[@]}" set_permissions -p / "$RABBITMQ_USERNAME" '.*' '.*' '.*'
|