unifi-pfsense
unifi-pfsense copied to clipboard
Add automatic version checking
This is more of a base to work off of. Unfortunately adds dependency on jq
and curl
. I don't know FreeBSD or pfSense, but I noticed fetch
was used to download the file. Maybe that could replace curl
? Some other changes will need to be made, because you can no longer assume the version is valid.
This is great!
We use fetch because historically it was included with FreeBSD/pfSense while curl was not.
Curl is now included, but jq is not. So for your technique to work, we would need to fetch and install jq.
We should also make sure this behaves correctly if and when UBNT changes the pages you’re scraping.
I would suggest adding some error handling and or sensible fallback behavior, and a complete solution would also install jq before getting to this step.
How should jq
be installed if it wasn't found? Their site says run pkg install jq
as root, but I don't know if installing something for a user is a good idea. Maybe just tell them that jq
is required and exit?
Automatic installation of dependencies is expected in most installation scripts. Install-time dependencies can be removed after install if they weren't present beforehand.
Thanks to shaneallgeier for finding/posting the URL.
Think this should work. Just update install script
UNIFI_SOFTWARE_URL=$(curl -s 'https://fw-update.ubnt.com/api/firmware?filter=eq~~product~~unifi-controller&filter=eq~~platform~~unix&filter=eq~~channel~~release&sort=-version&limit=1' | jq '._embedded.firmware[0]._links.data.href' ) echo "Installing version - $UNIFI_SOFTWARE_URL";
Requirements are jq and curl.
How do we feel about the prompt?
The current behavior is completely automatic and unattended. It is predictable because the version is hard coded.
With this patch, the behavior is more difficult to predict because the version comes from the API. The prompt helps prevent an unintentional upgrade (or downgrade, or general failure).
Thoughts?
Is this a major change in behavior? If so, bad or good?
@jmbwell I do not see the prompt as a negative thing, I think it is kind of necessary, however I will say this, that current API still redirects to the newest version under https://www.ui.com/download/unifi/ ...
With that being said, I do not find this API with prompt to be a negative. I did however notice that the latest version (6.0.24) is not up on that site yet... I did find it under UI release https://community.ui.com/releases/UniFi-Network-Controller-6-0-24/81cd5842-c3f2-4c55-8ab5-c877bb6fe535?page=1 , and the download link is https://dl.ui.com/unifi/6.0.24-b200bf6446/UniFi.unix.zip .... I am thinking this is done under versions that they still classify as beta. I did however do a pull request for 6.0.23 and 6.0.24 with some changes to your PkgAdd order to get rid of dependency issues on a fresh install. Also I pulled back Python37 for Python27, as Python27 is required for V8 and Mongodb36 can run on 27...
The current coding on this script however is not able to grab the version number automatically. I tried to add this modified script to another branch, and was unsuccessful in being able to get it to grab the version number. I even added JQ to be sure... I will work on this a little bit more, when I have some time.