ubiquiti:controller:upgrade_controller
Table of Contents
Ubiquiti - Controller - Upgrade Controller
Read the synopsis for the specific upgrade release at https://community.ui.com/releases.
Obtain the URL from the Download Links.
Use SSH
ssh ubnt@192.168.1.10 ubnt@192.168.1.10's password:
cd /tmp ls -l rm unifi_sysvinit_all.deb wget https://dl.ui.com/unifi/6.0.36/unifi_sysvinit_all.deb sudo dpkg -i unifi_sysvinit_all.deb rm unifi_sysvinit_all.deb
On UDMP
unifi-os shell rm /tmp/unifi_sysvinit_all.deb &> /dev/null; curl -o "/tmp/unifi_sysvinit_all.deb" https://dl.ui.com/unifi/6.0.36/unifi_sysvinit_all.deb && dpkg -i /tmp/unifi_sysvinit_all.deb && rm /tmp/unifi_sysvinit_all.deb
Use Bash Script
#!/bin/bash https_url='https://dl.ui.com' package_name='unifi_sysvinit_all.deb' upgrade_log="${HOME}/ssh_upgrade.log" # CLI opts checksum='' version='' function cleanup { echo "$(timestamp) Removing temp directory ${output_dir}" | tee -a "${upgrade_log}" rm -rf "${output_dir}" } function timestamp { local __tstamp=$1 local mytstamp=$(date '+%Y-%m-%d %H:%M:%S') if [[ "$__tstamp" ]] then eval $__tstamp="'${mytstamp}'" else echo "${mytstamp}" fi } function usage { echo "Usage: $0 [-v <version>] [-c <sha256 checksum>]" 1>&2 exit 1 } # Get command line args while getopts ":c:v:" opt do case "${opt}" in c) checksum="${OPTARG}" ;; v) version="${OPTARG}" ;; *) usage ;; esac done shift $((OPTIND-1)) # Make sure required args are passed if [ -z "${version}" ] || [ -z "${checksum}" ] then usage fi # Make sure checksum looks like a sha256 hash if ! [[ ${checksum} =~ ^[0-9a-f]{64}$ ]] then echo "$(timestamp) Error: checksum must be a sha256 hash string" | tee -a "${upgrade_log}" exit 1 fi # Get currently installed unifi package version current_ver=$(dpkg -s unifi | grep '^Version:' | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+') target_ver=$(echo "${version}" | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+') # Don't bother upgrading to same version as installed if [ "${current_ver}" = "${target_ver}" ] then echo "$(timestamp) Error: Current controller version and target controller version are the same (${current_ver})" | tee -a "${upgrade_log}" exit 1 fi # Create a temp dir to store downloads if ! output_dir=$(mktemp -d -t unifi_${version}_$(date +%Y-%m-%d-%H-%M-%S)_XXXXXXXXXX) then echo "$(timestamp) Error: Failed to create output directory" | tee -a "${upgrade_log}" exit 1 fi trap cleanup 0 # Download package echo "$(timestamp) Downloading ${https_url}/unifi/${version}/${package_name}" | tee -a "${upgrade_log}" cd "${output_dir}" && wget -O "${output_dir}/${package_name}" "${https_url}/unifi/${version}/${package_name}" retval=$? if [[ ! ${retval} -eq 0 ]] then echo "$(timestamp) Error: wget exited with error ${retval}" | tee -a "${upgrade_log}" exit 1 fi # Verify package checksum echo "${checksum} ${output_dir}/${package_name}" > "${output_dir}/${package_name}.sha256" if [ -f "${output_dir}/${package_name}.sha256" ] then echo "$(timestamp) Checking downloaded file integrity..." | tee -a "${upgrade_log}" if ! shasum -c "${output_dir}/${package_name}.sha256" -a 256 -s then echo "$(timestamp) Error: File failed integrity check" | tee -a "${upgrade_log}" exit 1 else echo "$(timestamp) File passed integrity check, performing package update" | tee -a "${upgrade_log}" dpkg --debug=1 --install "${output_dir}/${package_name}" | tee -a "${upgrade_log}" fi else echo "$(timestamp) Error: Cannot verify downloaded file integrity (missing checksum)" | tee -a "${upgrade_log}" exit 1 fi echo "$(timestamp) Done." | tee -a "${upgrade_log}" exit 0
Run it as:
./ssh_upgrade.sh -v 6.0.26-dfb550c0bf -c b4496144e3a9feb4a6779622611407b59d5cd48b8379c0c81525776aa068ffb0
References
ubiquiti/controller/upgrade_controller.txt · Last modified: 2022/10/11 10:28 by peter