From 5ae04681c60705185f5a4556ba32cfe7d7f9fe73 Mon Sep 17 00:00:00 2001 From: Shane Allgeier Date: Tue, 4 Apr 2023 19:47:38 -0500 Subject: [PATCH 1/3] Try multiple URLs when grabbing packagelist --- install-unifi/install-unifi.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/install-unifi/install-unifi.sh b/install-unifi/install-unifi.sh index 4ba0ce6..cb2209f 100644 --- a/install-unifi/install-unifi.sh +++ b/install-unifi/install-unifi.sh @@ -31,9 +31,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 @@ -95,6 +92,20 @@ done echo " done." +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." + + # Install mongodb, OpenJDK, and unzip (required to unpack Ubiquiti's download): # -F skips a package if it's already installed, without throwing an error. @@ -102,9 +113,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 From c2220efb1dfbc0e41ad7bcca08bf041b64f23edd Mon Sep 17 00:00:00 2001 From: Shane Allgeier Date: Tue, 4 Apr 2023 19:56:02 -0500 Subject: [PATCH 2/3] Support multiple mongodb versions and install the latest available --- install-unifi/install-unifi.sh | 35 +++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/install-unifi/install-unifi.sh b/install-unifi/install-unifi.sh index cb2209f..008bfc2 100644 --- a/install-unifi/install-unifi.sh +++ b/install-unifi/install-unifi.sh @@ -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 @@ -82,16 +84,6 @@ 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} -done -echo " done." - - echo "Gathering package list from remote repository..." # Build a list of possible packagesite.* URLs for ext in pkg txz; do @@ -106,6 +98,27 @@ 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 + +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 + + # Install mongodb, OpenJDK, and unzip (required to unpack Ubiquiti's download): # -F skips a package if it's already installed, without throwing an error. From 9e51186157536059106760151d24b748d430ae1a Mon Sep 17 00:00:00 2001 From: Shane Allgeier Date: Mon, 24 Apr 2023 21:14:12 -0500 Subject: [PATCH 3/3] Only attempt to install MongoDB if $CURRENT_MONGODB_VERSION is set --- install-unifi/install-unifi.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install-unifi/install-unifi.sh b/install-unifi/install-unifi.sh index 008bfc2..a8c52f7 100644 --- a/install-unifi/install-unifi.sh +++ b/install-unifi/install-unifi.sh @@ -182,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