Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback packagelist URLs and mongodb versions #310

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions install-unifi/install-unifi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ UNIFI_SOFTWARE_URL="https://dl.ui.com/unifi/7.2.97/UniFi.unix.zip"
# The rc script associated with this branch or fork:
RC_SCRIPT_URL="https://raw.githubusercontent.com/unofficial-unifi/unifi-pfsense/master/rc.d/unifi.sh"

CURRENT_MONGODB_VERSION=mongodb42
# List of valid/supported mongodb package names, sorted with the latest being first
# As UniFi adds support for new mongodb versions, just prepend them to this list
SUPPORTED_MONGODB_PACKAGES="mongodb42 mongodb40 mongodb36 mongodb34 mongodb32 mongodb"

# If pkg-ng is not yet installed, bootstrap it:
if ! /usr/sbin/pkg -N 2> /dev/null; then
Expand All @@ -31,9 +33,6 @@ ABI=`/usr/sbin/pkg config abi`
# FreeBSD package source:
FREEBSD_PACKAGE_URL="https://pkg.freebsd.org/${ABI}/latest/"

# FreeBSD package list:
FREEBSD_PACKAGE_LIST_URL="${FREEBSD_PACKAGE_URL}packagesite.pkg"

# 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/unifi.sh ]; then
Expand Down Expand Up @@ -85,14 +84,39 @@ echo -n "Mounting new filesystems..."
echo " done."


echo "Removing discontinued packages..."
old_mongos=`pkg info | grep mongodb | grep -v ${CURRENT_MONGODB_VERSION}`
for old_mongo in "${old_mongos}"; do
package=`echo "$old_mongo" | cut -d' ' -f1`
pkg unlock -yq ${package}
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg delete ${package}
echo "Gathering package list from remote repository..."
# Build a list of possible packagesite.* URLs
for ext in pkg txz; do
FREEBSD_PACKAGE_LIST_URLS="$FREEBSD_PACKAGE_LIST_URLS ${FREEBSD_PACKAGE_URL}packagesite.${ext}"
done
# Try each of the URLs in the list and exit if they all fail
if ! fetch -q1o - $FREEBSD_PACKAGE_LIST_URLS > packagesite.pkg 2> /dev/null; then
echo "Error downloading $FREEBSD_PACKAGE_LIST_URLS"
exit 1
fi
tar fx packagesite.pkg || exit 1
echo "Done."


# Find the latest supported mongodb version that's available in the repository
for package_name in $SUPPORTED_MONGODB_PACKAGES; do
if grep -q "\"name\":\"$package_name\"" packagesite.yaml; then
CURRENT_MONGODB_VERSION="$package_name"
break
fi
done
echo " done."

if [ ! -z "$CURRENT_MONGODB_VERSION" ]; then
echo "Removing discontinued packages..."
pkg info | grep mongodb | grep -v ${CURRENT_MONGODB_VERSION} | while read -r old_mongo; do
package=`echo "$old_mongo" | cut -d' ' -f1`
pkg unlock -yq ${package}
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg delete ${package}
done
echo " done."
else
echo "Could not locate a valid mongodb package"
fi



Expand All @@ -102,9 +126,6 @@ echo "Installing required packages..."
#uncomment below for pfSense 2.2.x:
#env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg install mongodb openjdk unzip pcre v8 snappy

fetch ${FREEBSD_PACKAGE_LIST_URL}
tar vfx packagesite.pkg

AddPkg () {
pkgname=$1
pkg unlock -yq $pkgname
Expand Down Expand Up @@ -161,7 +182,9 @@ AddPkg snappy
AddPkg cyrus-sasl
AddPkg icu
AddPkg boost-libs
AddPkg ${CURRENT_MONGODB_VERSION}
if [ ! -z "$CURRENT_MONGODB_VERSION" ]; then
AddPkg ${CURRENT_MONGODB_VERSION}
fi
AddPkg unzip
AddPkg pcre

Expand Down