#!/usr/bin/env bash timestamp() { date "+%H:%M:%S.%3N" } info(){ local msg=$1 echo -e "\e[1;32m===> $(timestamp) ${msg}\e[0m" } warn(){ local msg=$1 echo -e "\e[1;33m===> $(timestamp) ${msg}\e[0m" } fail(){ local msg=$1 echo -e "\e[1;31m===> $(timestamp) ERROR: ${msg}\e[0m" exit 1 } dsinit(){ apt -qq update &> /dev/null info "Updating system software..." info "This may take a while depending on your connection speed." apt -qqy dist-upgrade &> /dev/null } install_or_update(){ local pkg=$1 present=$(apt list --installed 2> /dev/nul | grep "$pkg" | cut -f1 -d"/") if [ "$present" != "$pkg" ]; then info "Installing $pkg" apt install -qqy $pkg &> /dev/null info "Ensuring dependices are installed" apt-get -qqf install &> /dev/null else info "Checking for $pkg updates" upgrade_needed=$(apt --just-print upgrade 2> /dev/null | grep "$pkg" | cut -f1 -d"/") if [ "$upgrade_needed" == "$pkg" ]; then info "Upgrading $pkg" apt install -qqy --only-upgrade $pkg &> /dev/null else info "$1 already on the latest version." fi fi } main(){ info "Unifi Video installer - 0.1.0" dsinit info "Ensuring previous installs are complete" dpkg --configure -a &> /dev/null install_or_update curl FILENAME="unifi-video.deb" info "Downloading unifi-video installer" if ! curl -fsSL -o $FILENAME https://dl.ubnt.com/firmwares/unifi-video/3.7.2/unifi-video_3.7.2-Ubuntu16.04_amd64.deb; then fail "failed to download unifi-video installer" exit $? fi info "Installing unifi-video" dpkg -i $FILENAME &> /dev/null info "Installing unifi-video deps... This may take a while!" apt-get -qqf install &> /dev/null info "Install complete!" MYIP=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') info "You can view the controller interface here: https://$MYIP:7443/" } main