Unifi

by eseelke
8 deployments · 5 still active · last rev. 1 month ago

The UniFi® Controller is a wireless network management software solution from Ubiquiti Networks™. It allows you to manage multiple wireless networks using a web browser.

This will install Unifi and install a LetsEncrypt SSL certificate directly into Unifi. It will also add a crontab to keep the certificate updated.

NOTE: Make sure you have the hostname pointed to the IP before installing or the SSL encryption will fail and make controller inaccessible.

Compatible with: Debian 9
						#!/bin/bash
# This block defines the variables the user of the script needs to input
# when deploying using this script.
#
#
#<UDF name="email" label="The email address used for LetsEncrypt.">
# EMAIL=
#<UDF name="hostname" label="The hostname for the new Linode.">
# HOSTNAME=
#

apt-get update
apt-get --with-new-pkgs upgrade -y

# Setup the hostname
hostname $HOSTNAME

#Install Unifi and LetsEncrypt
wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ubnt.com/unifi/unifi-repo.gpg 
echo 'deb http://www.ubnt.com/downloads/unifi/debian stable ubiquiti' | tee /etc/apt/sources.list.d/100-ubnt-unifi.list
apt-get update
apt-get install letsencrypt -y
apt-get install unifi -y

#Setup LetsEncrypt certificate
wget -O /opt/gen-unifi-cert.sh https://source.sosdg.org/brielle/lets-encrypt-scripts/raw/master/gen-unifi-cert.sh
sed -i 's/--agree-tos --standalone --preferred-challenges tls-sni/--agree-tos --standalone/g' /opt/gen-unifi-cert.sh
chmod +x /opt/gen-unifi-cert.sh
/opt/gen-unifi-cert.sh -e $EMAIL -d $HOSTNAME

#Create crontab for LetsEncrypt
crontab -l > /tmp/letsencryptcron
echo "23 1,13 * * * /opt/gen-unifi-cert.sh -r -d $HOSTNAME" >> /tmp/letsencryptcron
crontab /tmp/letsencryptcron
rm /tmp/letsencryptcron