#!/bin/sh

apt-key adv --keyserver "hkps://keys.openpgp.org" --recv-keys "0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
## Launchpad PPA that provides modern Erlang releases
apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC"
## PackageCloud RabbitMQ repository
curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | apt-key add -

sh -c 'echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/rabbitmq.list'
sh -c 'echo "deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu $(lsb_release -cs) main" >> /etc/apt/sources.list.d/rabbitmq.list'

## Update package indices
apt autoremove
apt-get update -y
apt install -y rabbitmq-server

rabbitmq-plugins enable rabbitmq_management