forked from openhab/openhabian
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for FIND3 and remove FIND
Fixes openhab#632 Signed-off-by: Ethan Dye <[email protected]>
- Loading branch information
Showing
9 changed files
with
160 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
## Function for installing FIND to allow for indoor localization of WiFi devices. | ||
## This function can only be invoked in INTERACTIVE with userinterface. | ||
## | ||
## find3_setup() | ||
## | ||
find3_setup() { | ||
if [[ -z $INTERACTIVE ]]; then | ||
echo "$(timestamp) [openHABian] FIND3 setup must be run in interactive mode! Canceling FIND3 setup!" | ||
return 0 | ||
fi | ||
|
||
local find3Dir | ||
local mqttPass | ||
local mqttMissingText | ||
local introText | ||
local MQTT_SERVER | ||
local MQTT_PASS | ||
local MQTT_ADMIN | ||
local findPass1 | ||
local findPass2 | ||
local brokerText | ||
|
||
mqttPass="/etc/mosquitto/passwd" | ||
find3Dir="/opt/find3" | ||
mqttMissingText="FIND3 requires an MQTT broker to run, but Mosquitto could not be found on this system.\\n\\nYou can configure FIND to use any existing MQTT broker (in the next step) or you can go back and install Mosquitto from the openHABian menu.\\n\\nDo you want to continue with the FIND3 installation?" | ||
introText="Framework for Internal Navigation and Discovery (FIND) version 3 will be installed to allow for the indoor localization of Bluetooth and WiFi devices.\\n\\nThis will install the FIND3 server and the fingerprinting client.\\n\\nYou must manually activate the fingerprinting client, for more information see:\\nhttps://www.internalpositioning.com/doc/passive_tracking.md\\n\\nThere is also an Android app to collect fingerprints. There is no iOS app for fingerprinting for details on why see:\\nhttps://www.internalpositioning.com/doc/faq.md#iphone\\n\\nFor more information see:\\nhttps://www.internalpositioning.com/doc/" | ||
brokerText="You've chosen to work with an external MQTT broker.\\n\\nPlease be aware that you might need to add authentication credentials. You can do so after the installation.\\n\\nConsult with the FIND3 documentation or the openHAB community for details." | ||
successText="FIND3 setup was successful.\\n\\nSettings can be configured in '/etc/default/find3server'. Be sure to restart the service after.\\n\\nYou must manually activate the fingerprinting client, for more information see:\\nhttps://www.internalpositioning.com/doc/passive_tracking.md\\n\\nThere is also an Android app to collect fingerprints. There is no iOS app for fingerprinting for details on why see:\\nhttps://www.internalpositioning.com/doc/faq.md#iphone\\n\\nCheck out your FIND3 server's dashboard at: http://${HOSTNAME}:8003\\n\\nFor more information see:\\nhttps://www.internalpositioning.com/doc/" | ||
|
||
echo -n "$(timestamp) [openHABian] Beginning setup of FIND3, the Framework for Internal Navigation and Discovery... " | ||
|
||
if ! [[ -f "/etc/mosquitto/mosquitto.conf" ]]; then | ||
if ! (whiptail --title "Mosquitto not installed, continue?" --defaultno --yes-button "Continue" --no-button "Cancel" --yesno "$mqttMissingText" 13 80); then echo "CANCELED"; return 0; fi | ||
fi | ||
|
||
if (whiptail --title "FIND3 installation?" --yes-button "Continue" --no-button "Cancel" --yesno "$introText" 22 80); then echo "OK"; else echo "CANCELED"; return 0; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Configuring FIND3... " | ||
if ! MQTT_SERVER="$(whiptail --title "FIND3 Setup" --inputbox "\\nPlease enter the hostname and port of the device your MQTT broker is running on:" 10 80 localhost:1883 3>&1 1>&2 2>&3)"; then echo "CANCELED"; return 0; fi | ||
if [[ $MQTT_SERVER != "localhost:1883" ]]; then | ||
if ! (whiptail --title "MQTT Broker Notice" --yes-button "Continue" --no-button "Cancel" --yesno "$brokerText" 12 80); then echo "CANCELED"; return 0; fi | ||
fi | ||
if [[ -f $mqttPass ]]; then | ||
if ! MQTT_ADMIN=$(whiptail --title "FIND3 MQTT Setup" --inputbox "\\nEnter a username for FIND3 to connect with on your MQTT broker:" 9 80 find 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi | ||
while [[ -z $MQTT_PASS ]]; do | ||
if ! findPass1=$(whiptail --title "FIND3 MQTT Setup" --passwordbox "\\nEnter a password for the FIND3 user on your MQTT broker:" 9 80 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi | ||
if ! findPass2=$(whiptail --title "FIND3 MQTT Setup" --passwordbox "\\nPlease confirm the password for the FIND3 user on your MQTT broker:" 9 80 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi | ||
if [[ $findPass1 == "$findPass2" ]] && [[ ${#findPass1} -ge 8 ]] && [[ ${#findPass2} -ge 8 ]]; then | ||
MQTT_PASS="$findPass1" | ||
else | ||
whiptail --title "FIND3 MQTT Setup" --msgbox "Password mismatched, blank, or less than 8 characters... Please try again!" 7 80 | ||
fi | ||
done | ||
if ! cond_redirect mosquitto_passwd -b "$mqttPass" "$MQTT_ADMIN" "$MQTT_PASS"; then echo "FAILED (mosquitto password)"; return 1; fi | ||
if ! cond_redirect systemctl restart mosquitto.service; then echo "FAILED (restart service)"; return 1; fi | ||
fi | ||
echo "OK" | ||
|
||
echo -n "$(timestamp) [openHABian] Installing required packages for FIND3... " | ||
if ! cond_redirect apt-get install --yes libc6-dev make pkg-config g++ gcc python3-dev python3-numpy python3-scipy python3-matplotlib supervisor libfreetype6-dev libopenblas-dev libblas-dev liblapack-dev gfortran wireless-tools net-tools libpcap-dev bluetooth; then echo "FAILED (apt)"; return 1; fi | ||
if cond_redirect python3 -m pip install cython --install-option="--no-cython-compile"; then echo "OK"; else echo "FAILED (cython)"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Downloading FIND3 source... " | ||
if ! [[ -d $find3Dir ]]; then | ||
cond_echo "\nFresh Installation... " | ||
if cond_redirect git clone https://github.com/schollz/find3.git $find3Dir; then echo "OK"; else echo "FAILED (git clone)"; return 1; fi | ||
else | ||
cond_echo "\nUpdate... " | ||
if cond_redirect update_git_repo "$find3Dir" "master"; then echo "OK"; else echo "FAILED (update git repo)"; return 1; fi | ||
fi | ||
|
||
echo -n "$(timestamp) [openHABian] Installing Go... " | ||
if cond_redirect go_setup; then echo "OK"; else echo "FAILED"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Building FIND3 server... " | ||
if ! cond_redirect cd $find3Dir/server/main; then echo "FAILED (cd)"; return 1; fi | ||
if cond_redirect /usr/lib/go-1.14/bin/go build -o find3server -v; then echo "OK"; else echo "FAILED (build)"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Installing FIND3 server... " | ||
if cond_redirect ln -sf $find3Dir/server/main/find3server /usr/sbin/find3server; then echo "OK"; else echo "FAILED (link)"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Installing FIND3 AI... " | ||
if ! cond_redirect cd $find3Dir/server/ai; then echo "FAILED (cd)"; return 1; fi | ||
if cond_redirect python3 -m pip install -r requirements.txt; then echo "OK"; else echo "FAILED (pip)"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Setting up FIND3 service... " | ||
if ! cond_redirect install -m 644 "${BASEDIR:-/opt/openhabian}"/includes/find3ai.service /etc/systemd/system/find3ai.service; then echo "FAILED (copy service)"; return 1; fi | ||
if ! (sed -e 's|%MQTT_SERVER|'"${MQTT_SERVER}"'|g; s|%MQTT_ADMIN|'"${MQTT_ADMIN}"'|g; s|%MQTT_PASS|'"${MQTT_PASS}"'|g; s|%FIND3_PORT|8003|g' "${BASEDIR:-/opt/openhabian}"/includes/find3server.service > /etc/systemd/system/find3server.service); then echo "FAILED (service file creation)"; return 1; fi | ||
if ! cond_redirect chmod 644 /etc/systemd/system/find3server.service; then echo "FAILED (permissions)"; return 1; fi | ||
if ! (sed -e 's|%MQTT_SERVER|'"${MQTT_SERVER}"'|g; s|%MQTT_ADMIN|'"${MQTT_ADMIN}"'|g; s|%MQTT_PASS|'"${MQTT_PASS}"'|g' "${BASEDIR:-/opt/openhabian}"/includes/find3server > /etc/default/find3server); then echo "FAILED (service configuration creation)"; return 1; fi | ||
cond_redirect systemctl -q daemon-reload &> /dev/null | ||
if ! cond_redirect systemctl enable find3ai.service; then echo "FAILED (enable service)"; return 1; fi | ||
if ! cond_redirect systemctl enable find3server.service; then echo "FAILED (enable service)"; return 1; fi | ||
if ! cond_redirect systemctl restart find3ai.service; then echo "FAILED (enable service)"; return 1; fi | ||
if cond_redirect systemctl restart find3server.service; then echo "OK"; else echo "FAILED (restart service)"; return 1; fi | ||
|
||
echo -n "$(timestamp) [openHABian] Installing FIND3 fingerprinting client... " | ||
GO111MODULE="on" | ||
GOPATH="$(/usr/lib/go-1.14/bin/go env | grep "GOPATH" | sed 's|GOPATH=||g; s|"||g')" | ||
export GO111MODULE GOPATH | ||
if ! cond_redirect /usr/lib/go-1.14/bin/go get -v github.com/schollz/find3-cli-scanner/v3; then echo "FAILED (get)"; return 1; fi | ||
if cond_redirect install -m 755 "$GOPATH"/bin/find3-cli-scanner /usr/local/bin/find3-cli-scanner; then echo "OK"; else echo "FAILED"; return 1; fi | ||
|
||
if [[ -z $BATS_TEST_NAME ]]; then | ||
dashboard_add_tile find | ||
fi | ||
|
||
whiptail --title "Operation Successful!" --msgbox "$successText" 23 80 | ||
} | ||
|
||
## Function to install Go on the current system | ||
## | ||
## go_setup() | ||
## | ||
go_setup() { | ||
if [[ -x $(command -v /usr/lib/go-1.14/bin/go) ]]; then return 0; fi | ||
|
||
echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/golang.list | ||
if ! cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC; then echo "FAILED (add keys)"; return 1; fi | ||
if ! cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138; then echo "FAILED (add keys)"; return 1; fi | ||
|
||
echo -e "Package: *\\nPin: release a=buster-backports\\nPin-Priority: 90\\n" > /etc/apt/preferences.d/limit-buster-backports | ||
|
||
if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi | ||
if cond_redirect apt-get install --yes golang-1.14; then echo "OK"; else echo "FAILED"; return 1; fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Framework for Internal Navigation and Discovery AI | ||
Documentation=https://www.internalpositioning.com/doc/ | ||
After=mosquitto.service | ||
|
||
[Service] | ||
ExecStart=/usr/bin/make --always-make --directory=/opt/find3/server/ai production | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# FIND server service configuration | ||
# see https://www.internalpositioning.com/server/ | ||
# | ||
MQTT_SERVER=%MQTT_SERVER | ||
MQTT_ADMIN=%MQTT_ADMIN | ||
MQTT_PASS=%MQTT_PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Framework for Internal Navigation and Discovery server | ||
Documentation=https://www.internalpositioning.com/doc/ | ||
After=mosquitto.service find3ai.service | ||
|
||
[Service] | ||
EnvironmentFile=-/etc/default/find3server | ||
WorkingDirectory=/opt/find3/server/main | ||
ExecStart=/usr/sbin/find3server -mqtt-server %MQTT_SERVER -mqtt-admin %MQTT_ADMIN -mqtt-pass %MQTT_PASS -port %FIND3_PORT | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.