Created
October 1, 2021 09:41
-
-
Save cam8001/456f5dbb1872bf974ac42a55269c18ad to your computer and use it in GitHub Desktop.
Unifi controller on Ubuntu 20.04 arm64 - AWS userdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo -e "Running custom Unifi userdata" | |
AWS_DEFAULT_REGION=ap-southeast-2 | |
# Assoicate an elastic IP | |
ALLOC_ID=eipalloc-deadbeef | |
# Set timezone | |
ln -fs /usr/share/zoneinfo/Pacific/Auckland /etc/localtime | |
apt-key adv --keyserver keyserver.ubuntu.com --recv 06E85760C0A52C50 | |
echo 'deb [arch=armhf] https://www.ui.com/downloads/unifi/debian stable ubiquiti' > /etc/apt/sources.list.d/99-unifi.list | |
apt update && apt -y upgrade | |
apt-mark hold openjdk-8-* | |
apt -y install openjdk-8-jre | |
echo JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64/ >> /etc/environment | |
source /etc/environment | |
apt -y install unifi | |
# Make sure ssm is running | |
sudo systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service | |
sudo systemctl enable snap.amazon-ssm-agent.amazon-ssm-agent.service | |
sudo systemctl start unifi | |
sudo systemctl enable unifi | |
# Associate a given elastic IP with an instance on boot. | |
# Get instance creds. | |
# @see https://github.com/pierreg256/eip/blob/master/auto-ip.sh | |
# @see https://gist.github.com/fgassert/8923461 | |
# @see https://gist.github.com/odessky/e7b8b31e3b710cf3e29e85339d4ec5e6 | |
apt install awscli jq -y | |
ROLE=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/) | |
CR=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/$ROLE/) | |
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
export AWS_ACCESS_KEY_ID=$(echo $CR | jq -r '.AccessKeyId') | |
export AWS_SECRET_ACCESS_KEY=$(echo $CR | jq -r '.SecretAccessKey') | |
export AWS_SESSION_TOKEN=$(echo $CR | jq -r '.Token') | |
# Now we can associate the address. | |
echo -e "Running: aws --region=$AWS_DEFAULT_REGION ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOC_ID --allow-reassociation" | |
aws --region=$AWS_DEFAULT_REGION ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOC_ID --allow-reassociation | |
IPv4=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) | |
echo -e "This instance now has public IPv4 $IPv4" | |
echo -e "Start setting up your controller at https://$IPv4:8080" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment