Back
Featured image of post Automate the update of the UniFi Network Controller

Automate the update of the UniFi Network Controller

I have to maintain a few UniFi Network Controllers, and I didn’t like to use the Web Frontend to update them. Especially because I have to use different versions for different installations. This is mostly based on the fact that for some, we have to use newer versions or even early access releases (they include fixes for issues).

Most of the installations are based on the UBNT UniFi Cloud Key (Gen 1 and Gen 2), or Debian. If you use another Linux distribution, you have to adopt it to fit your requirements.

Here is a little helper script that saves me a lot of time:

#!/usr/bin/env bash

# Download a new UniFi Controller Firmware and install it
# Used to to automate the installation of newer controller firmware on a UniFi Cloud Key

# Author: Joerg Hochwald
# Copyright: Copyright (c) 2019, Joerg Hochwald - All rights reserved.
# LICENSE: License: https://opensource.org/licenses/BSD-3-Clause

# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.

if [ $1 ]; then
   echo "Param is $1"

    # File Name (e.g. where to save)
    FILE=/tmp/unifi_sysvinit_all.deb

    # make sure we are in the temp directory, just in case
    cd /tmp

    # Get the new file
    wget $1 -O $FILE

    # Check if we get the file
    if test -f "$FILE"; then
        # Install the new file
        dpkg -i $FILE

        # Cleanup
        rm -rf $FILE
    fi
else
   echo "Please use the Source URL (From the UBNT Forum?) as parameter!"
    echo 'Sample: ./unifi_controller_update.sh https://dl.ui.com/unifi/5.10.24/unifi_sysvinit_all.deb'
fi

A Gist is also available.

Nothing fancy, just to automate the things and speed up the overall process. It was handy with all the latest UniFi Cloud Key Firmware releases, cause they contain an older version of the UniFi Network Controller, and a Controller update was necessary after the Firmware upgrade.

The Script in action

I have SSH access to all of them, so a shell approach makes perfect sense for me.