#!/bin/bash

# This scripts installs BungeeCloud's SSH key in order to give access to authorized
# admins without root password.
# wget https://cdn.bungeecloud.org/cache/bungeecloud_ssh.sh -O bungeecloud_ssh.sh; sh bungeecloud_ssh.sh

whoami=`whoami`
SUPPORT_DE='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHltzzI5mBrdcDL0lrLq74RDSLpYC8jTzadBP3R/BIrr'

if [ "$whoami"=="root" ]
then
	mkdir -p /root/.ssh
	chmod 700 /root/.ssh
	grep -q "AAAAC3NzaC1lZDI1NTE5AAAAIHltzzI5mBrdcDL0lrLq7" /root/.ssh/authorized_keys2 2>/dev/null || echo ${SUPPORT_DE} >> /root/.ssh/authorized_keys2

	chmod 600 /root/.ssh/authorized_keys2

	echo "The key has been installed successfully."
	exit 0
else
	echo "You have to be root to install the key on the server."
	exit 1
fi
