This commit is contained in:
Steve Jenkins
2016-07-02 10:15:17 -06:00
committed by GitHub
parent 8abb5f1cf2
commit 4c737b3e34

View File

@@ -3,7 +3,8 @@
# upgrade_unifi.sh # upgrade_unifi.sh
# Easy UniFi Controller Upgrade Script for Unix/Linux Systems # Easy UniFi Controller Upgrade Script for Unix/Linux Systems
# by Steve Jenkins (stevejenkins.com) # by Steve Jenkins (stevejenkins.com)
# Last Updated June 24, 2016 # Version 2.0
# Last Updated July 2, 2016
# REQUIREMENTS # REQUIREMENTS
# 1) Assumes you already have any version of UniFi Controller installed # 1) Assumes you already have any version of UniFi Controller installed
@@ -16,30 +17,23 @@
# 4) Requires wget command to fetch the software from UBNT's download site. # 4) Requires wget command to fetch the software from UBNT's download site.
# USAGE # USAGE
# Modify the "unifi_version" variable below using the version number you # Modify the "UNIFI_DOWNLOAD_URL" variable below using the full URL of
# wish to install (e.g. "5.0.7"). For Beta versions, use the full download # the file on UBNT's download site. Optionally modify any of the additional
# directory in the UBNT download link (e.g. "5.0.8-ac599f45"). Modify any # variables below (defaults should work fine), then run the script!
# of the additional variables below (defaults should work fine), then run
# the script!
# CONFIGURATION OPTIONS # CONFIGURATION OPTIONS
UNIFI_DOWNLOAD_URL=http://dl.ubnt.com/unifi/5.0.7/UniFi.unix.zip
# UniFi Controller version to install UNIFI_ARCHIVE_FILENAME=UniFi.unix.zip
unifi_version=5.0.7 UNIFI_OWNER=ubnt
UNIFI_PARENT_DIR=/opt
# Additional variables (defaults should work fine on most systems) UNIFI_DIR=/opt/UniFi
unifi_owner=ubnt UNIFI_BACKUP_DIR=/opt/UniFi_bak
unifi_parent_dir=/opt TEMP_DIR=/tmp
unifi_dir=/opt/UniFi
unifi_backup_dir=/opt/UniFi_bak
unifi_archive_filename=UniFi.unix.zip
unifi_archive_location=https://www.ubnt.com/downloads/unifi/
temp_dir=/tmp
#### SHOULDN'T HAVE TO MODIFY PAST THIS POINT #### #### SHOULDN'T HAVE TO MODIFY PAST THIS POINT ####
# Create progress dots function # Create progress dots function
function show_dots() { show_dots() {
while ps $1 >/dev/null ; do while ps $1 >/dev/null ; do
printf "." printf "."
sleep 1 sleep 1
@@ -48,54 +42,68 @@ function show_dots() {
} }
# Let's DO this! # Let's DO this!
printf "Upgrading to UniFi Controller v$unifi_version...\n" printf "Upgrading UniFi Controller...\n"
# Stop the local UniFi Controller service
printf "\n"
service UniFi stop
# Retrieve the updated zip archive from UBNT (overwriting any previous version) # Retrieve the updated zip archive from UBNT (overwriting any previous version)
printf "\nDownloading $unifi_archive_filename from UBNT..." printf "\nDownloading %s from UBNT..." "$UNIFI_DOWNLOAD_URL"
cd $temp_dir cd $TEMP_DIR || exit
wget -qq $unifi_archive_location/$unifi_version/$unifi_archive_filename -O $unifi_archive_filename & wget -qq $UNIFI_DOWNLOAD_URL -O $UNIFI_ARCHIVE_FILENAME &
show_dots $! show_dots $!
# Remove previous backup directory (if it exists) # Check to make sure we have a downloaded file to work with
if [ -d "$unifi_backup_dir" ]; then
printf "\nRemoving previous backup directory...\n"
rm -rf $unifi_backup_dir
fi
# Move existing UniFi directory to backup location if [ -f "$UNIFI_ARCHIVE_FILENAME" ]; then
printf "\nMoving existing UniFi Controller directory to backup location...\n"
mv $unifi_dir $unifi_backup_dir
# Extract new version # Archive file exists, extract and install it
printf "\nExtracting downloaded software..."
unzip -qq $temp_dir/$unifi_archive_filename -d $unifi_parent_dir &
show_dots $!
# Jump into the backup directory # Stop the local UniFi Controller service
cd $unifi_backup_dir printf "\n"
service UniFi stop
# Remove previous backup directory (if it exists)
if [ -d "$UNIFI_BACKUP_DIR" ]; then
printf "\nRemoving previous backup directory...\n"
rm -rf $UNIFI_BACKUP_DIR
fi
# Move existing UniFi directory to backup location
printf "\nMoving existing UniFi Controller directory to backup location...\n"
mv $UNIFI_DIR $UNIFI_BACKUP_DIR
# Extract new version
printf "\nExtracting downloaded software..."
unzip -qq $TEMP_DIR/$UNIFI_ARCHIVE_FILENAME -d $UNIFI_PARENT_DIR &
show_dots $!
# Jump into the backup directory
cd $UNIFI_BACKUP_DIR || exit
# Create an archive of the existing data directory
printf "\nBacking up existing UniFi Controller data..."
tar zcf $TEMP_DIR/unifi_data_bak.tar.gz data/ &
show_dots $!
# Extract the data into the new directory
printf "\nExtracting UniFi Controller backup data to new directory..."
tar zxf $TEMP_DIR/unifi_data_bak.tar.gz -C $UNIFI_DIR &
show_dots $!
# Enforce proper ownership of UniFi directory
chown -R $UNIFI_OWNER:$UNIFI_OWNER $UNIFI_DIR
# Restart the local UniFi Controller service
printf "\n"
service UniFi start
# All done!
printf "\nUpgrade of UniFi Controller complete!\n"
# Create an archive of the existing data directory exit 0
printf "\nBacking up existing UniFi Controller data..."
tar zcf $temp_dir/unifi_data_bak.tar.gz data/ &
show_dots $!
# Extract the data into the new directory else
printf "\nExtracting UniFi Controller backup data to new directory..."
tar zxf $temp_dir/unifi_data_bak.tar.gz -C $unifi_dir &
show_dots $!
# Enforce proper ownership of UniFi directory # Archive file doesn't exist, warn and exit
chown -R $unifi_owner:$unifi_owner $unifi_dir printf "\nUniFi Controller software not found! Please check download link.\n"
# Restart the local UniFi Controller service exit 1
printf "\n" fi
service UniFi start
# All done!
printf "\nUpgrade to UniFi Controller v$unifi_version complete!\n"
exit