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
|
2021-12-17 01:33:31 +01:00
|
|
|
sudo=()
|
2020-10-15 23:52:45 +02:00
|
|
|
else
|
2021-12-17 01:33:31 +01:00
|
|
|
sudo=(sudo)
|
2020-10-15 23:52:45 +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
|
2021-12-17 01:33:31 +01:00
|
|
|
out="$("${sudo[@]}" rabbitmqctl eval 'net_adm:ping(node()).')" && [ "$out" = 'pong' ]
|
2020-10-16 00:14:26 +02:00
|
|
|
}
|
2021-12-03 21:03:16 +01:00
|
|
|
retries=29
|
2020-10-16 00:14:26 +02:00
|
|
|
while ! try_ping 2>/dev/null; do
|
|
|
|
sleep 1
|
|
|
|
if ! ((retries -= 1)); then
|
|
|
|
try_ping
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-12-17 01:33:31 +01:00
|
|
|
"${sudo[@]}" rabbitmqctl delete_user "$RABBITMQ_USERNAME" || true
|
|
|
|
"${sudo[@]}" rabbitmqctl delete_user zulip || true
|
|
|
|
"${sudo[@]}" rabbitmqctl delete_user guest || true
|
|
|
|
"${sudo[@]}" rabbitmqctl add_user "$RABBITMQ_USERNAME" "$RABBITMQ_PASSWORD"
|
|
|
|
"${sudo[@]}" rabbitmqctl set_user_tags "$RABBITMQ_USERNAME" administrator
|
|
|
|
"${sudo[@]}" rabbitmqctl set_permissions -p / "$RABBITMQ_USERNAME" '.*' '.*' '.*'
|