Skip to content
Branch: master
Find file Copy path
Find file Copy path
20 contributors

Users who have contributed to this file

@gozoinks @jmcphail @DanMc85 @ReinaldoFeitosa @shaneallgeier @frankcrook @Forsaked @esbernhansen @fenichelar @StephenRadachy @ardichoke @byeskille @kleper @jmbcpi @jgarland79 @idarlund @devangsheth @inickt @celevra @aaaustin10
219 lines (183 sloc) 6.87 KB
# Installs the Uni-Fi controller software on a FreeBSD machine (presumably running pfSense).
# The latest version of UniFi:
# The rc script associated with this branch or fork:
# If pkg-ng is not yet installed, bootstrap it:
if ! /usr/sbin/pkg -N 2> /dev/null; then
echo "FreeBSD pkgng not installed. Installing..."
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg bootstrap
echo " done."
# If installation failed, exit:
if ! /usr/sbin/pkg -N 2> /dev/null; then
echo "ERROR: pkgng installation failed. Exiting."
exit 1
# Determine this installation's Application Binary Interface
ABI=`/usr/sbin/pkg config abi`
# FreeBSD package source:
# FreeBSD package list:
# Stop the controller if it's already running...
# First let's try the rc script if it exists:
if [ -f /usr/local/etc/rc.d/ ]; then
echo -n "Stopping the unifi service..."
/usr/sbin/service stop
echo " done."
# Then to be doubly sure, let's make sure ace.jar isn't running for some other reason:
if [ $(ps ax | grep -c "/usr/local/UniFi/lib/[a]ce.jar start") -ne 0 ]; then
echo -n "Killing ace.jar process..."
/bin/kill -15 `ps ax | grep "/usr/local/UniFi/lib/[a]ce.jar start" | awk '{ print $1 }'`
echo " done."
# And then make sure mongodb doesn't have the db file open:
if [ $(ps ax | grep -c "/usr/local/UniFi/data/[d]b") -ne 0 ]; then
echo -n "Killing mongod process..."
/bin/kill -15 `ps ax | grep "/usr/local/UniFi/data/[d]b" | awk '{ print $1 }'`
echo " done."
# If an installation exists, we'll need to back up configuration:
if [ -d /usr/local/UniFi/data ]; then
echo "Backing up UniFi data..."
BACKUPFILE=/var/backups/unifi-`date +"%Y%m%d_%H%M%S"`.tgz
/usr/bin/tar -vczf ${BACKUPFILE} /usr/local/UniFi/data
# Add the fstab entries apparently required for OpenJDKse:
if [ $(grep -c fdesc /etc/fstab) -eq 0 ]; then
echo -n "Adding fdesc filesystem to /etc/fstab..."
echo -e "fdesc\t\t\t/dev/fd\t\tfdescfs\trw\t\t0\t0" >> /etc/fstab
echo " done."
if [ $(grep -c proc /etc/fstab) -eq 0 ]; then
echo -n "Adding procfs filesystem to /etc/fstab..."
echo -e "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0" >> /etc/fstab
echo " done."
# Run mount to mount the two new filesystems:
echo -n "Mounting new filesystems..."
/sbin/mount -a
echo " done."
# Install mongodb, OpenJDK, and unzip (required to unpack Ubiquiti's download):
# -F skips a package if it's already installed, without throwing an error.
echo "Installing required packages..."
tar xv -C / -f /usr/local/share/pfSense/base.txz ./usr/bin/install
#uncomment below for pfSense 2.2.x:
#env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg install mongodb openjdk unzip pcre v8 snappy
tar vfx packagesite.txz
AddPkg () {
pkginfo=`grep "\"name\":\"$pkgname\"" packagesite.yaml`
pkgvers=`echo $pkginfo | pcregrep -o1 '"version":"(.*?)"' | head -1`
# compare version for update/install
if [ `pkg info | grep -c $pkgname-$pkgvers` -eq 1 ]; then
echo "Package $pkgname-$pkgvers already installed."
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add -f ${FREEBSD_PACKAGE_URL}${pkgname}-${pkgvers}.txz
# if update openjdk8 then force detele snappyjava to reinstall for new version of openjdk
if [ "$pkgname" == "openjdk8" ]; then
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg delete snappyjava
AddPkg snappy
AddPkg cyrus-sasl
AddPkg xorgproto
AddPkg python2
AddPkg v8
AddPkg icu
AddPkg boost-libs
AddPkg mongodb34
AddPkg unzip
AddPkg pcre
AddPkg alsa-lib
AddPkg freetype2
AddPkg fontconfig
AddPkg libXdmcp
AddPkg libpthread-stubs
AddPkg libXau
AddPkg libxcb
AddPkg libICE
AddPkg libSM
AddPkg java-zoneinfo
AddPkg libX11
AddPkg libXfixes
AddPkg libXext
AddPkg libXi
AddPkg libXt
AddPkg libfontenc
AddPkg mkfontscale
AddPkg dejavu
AddPkg libXtst
AddPkg libXrender
AddPkg libinotify
AddPkg javavmwrapper
AddPkg giflib
AddPkg openjdk8
AddPkg snappyjava
# Clean up downloaded package manifest:
rm packagesite.*
echo " done."
# Switch to a temp directory for the Unifi download:
cd `mktemp -d -t unifi`
# Download the controller from Ubiquiti (assuming acceptance of the EULA):
echo -n "Downloading the UniFi controller software..."
/usr/bin/fetch ${UNIFI_SOFTWARE_URL}
echo " done."
# Unpack the archive into the /usr/local directory:
# (the -o option overwrites the existing files without complaining)
echo -n "Installing UniFi controller in /usr/local..."
/usr/local/bin/unzip -o -d /usr/local
echo " done."
# Update Unifi's symbolic link for mongod to point to the version we just installed:
echo -n "Updating mongod link..."
/bin/ln -sf /usr/local/bin/mongod /usr/local/UniFi/bin/mongod
echo " done."
# If partition size is < 4GB, add smallfiles option to mongodb
echo -n "Checking partition size..."
if [ `df -k | awk '$NF=="/"{print $2}'` -le 4194302 ]; then
echo -e "\nunifi.db.extraargs=--smallfiles\n" >> /usr/local/UniFi/data/
echo " done."
# Replace snappy java library to support AP adoption with latest firmware:
echo -n "Updating snappy java..."
unifizipcontents=`zipinfo -1`
# Make sure exactly one match is found
if [ $(echo "${unifizipcontents}" | egrep -c ${upstreamsnappyjavapattern}) -eq 1 ]; then
upstreamsnappyjava="/usr/local/UniFi/lib/`echo \"${unifizipcontents}\" | pcregrep -o1 ${upstreamsnappyjavapattern}`"
mv "${upstreamsnappyjava}" "${upstreamsnappyjava}.backup"
cp /usr/local/share/java/classes/snappy-java.jar "${upstreamsnappyjava}"
echo " done."
echo "ERROR: Could not locate UniFi's snappy java! AP adoption will most likely fail"
# Fetch the rc script from github:
echo -n "Installing rc script..."
/usr/bin/fetch -o /usr/local/etc/rc.d/ ${RC_SCRIPT_URL}
echo " done."
# Fix permissions so it'll run
chmod +x /usr/local/etc/rc.d/
# Add the startup variable to rc.conf.local.
# Eventually, this step will need to be folded into pfSense, which manages the main rc.conf.
# In the following comparison, we expect the 'or' operator to short-circuit, to make sure the file exists and avoid grep throwing an error.
if [ ! -f /etc/rc.conf.local ] || [ $(grep -c unifi_enable /etc/rc.conf.local) -eq 0 ]; then
echo -n "Enabling the unifi service..."
echo "unifi_enable=YES" >> /etc/rc.conf.local
echo " done."
# Restore the backup:
if [ ! -z "${BACKUPFILE}" ] && [ -f ${BACKUPFILE} ]; then
echo "Restoring UniFi data..."
mv /usr/local/UniFi/data /usr/local/UniFi/data-`date +%Y%m%d-%H%M`
/usr/bin/tar -vxzf ${BACKUPFILE} -C /
# Start it up:
echo -n "Starting the unifi service..."
/usr/sbin/service start
echo " done."
You can’t perform that action at this time.