Skip to content

Commit

Permalink
Add support for FIND3 and remove FIND
Browse files Browse the repository at this point in the history
Fixes openhab#632

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Jul 18, 2020
1 parent aa3db07 commit 41633b7
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 129 deletions.
126 changes: 126 additions & 0 deletions functions/find.bash
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
}
4 changes: 2 additions & 2 deletions functions/menu.bash
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ show_main_menu() {
"26 | Homegear" "Homematic specific, the CCU2 emulation software Homegear" \
"27 | knxd" "KNX specific, the KNX router/gateway daemon knxd" \
"28 | 1wire" "1wire specific, owserver and related packages" \
"29 | FIND" "Framework for Internal Navigation and Discovery" \
"29 | FIND3" "Framework for Internal Navigation and Discovery" \
"2A | Telldus Core" "Telldus Core service for Tellstick USB devices" \
"2B | Mail Transfer Agent" "Install Exim4 as MTA to relay mails via public services" \
3>&1 1>&2 2>&3)
Expand All @@ -109,7 +109,7 @@ show_main_menu() {
26\ *) homegear_setup ;;
27\ *) knxd_setup ;;
28\ *) 1wire_setup ;;
29\ *) find_setup ;;
29\ *) find3_setup ;;
2A\ *) telldus_core_setup ;;
2B\ *) exim_setup ;;
"") return 0 ;;
Expand Down
103 changes: 0 additions & 103 deletions functions/packages.bash
Original file line number Diff line number Diff line change
Expand Up @@ -246,109 +246,6 @@ mqtt_setup() {
fi
}

## Function for installing FIND to allow for indoor localization of WiFi devices.
## This function can only be invoked in INTERACTIVE with userinterface.
##
## find_setup()
##
find_setup() {
if [[ -z $INTERACTIVE ]]; then
echo "$(timestamp) [openHABian] FIND setup must be run in interactive mode! Canceling FIND setup!"
return 0
fi

local brokertext
local FINDADMIN
local FINDADMINPASS
local findArch
local findClient
local findDist
local findPass1
local findPass2
local findRelease
local introtext
local mqttmissingtext
local mqttpasswd
local MQTTPORT
local MQTTSERVER
local successtext
local temp

if ! dpkg -s 'libsvm-tools' &> /dev/null; then
echo -n "$(timestamp) [openHABian] Installing FIND required packages... "
if cond_redirect apt-get install --yes libsvm-tools; then echo "OK"; else echo "FAILED"; return 1; fi
fi

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 FIND documentation or the openHAB community for details."
if is_arm; then
findArch="arm"
else
findArch="amd64"
fi
findRelease="https://github.com/schollz/find/releases/download/v2.4.1/find_2.4.1_linux_${findArch}.zip"
findClient="https://github.com/schollz/find/releases/download/v0.6client/fingerprint_0.6_linux_${findArch}.zip"
findDist="/var/lib/findserver"
introtext="Install and setup the FIND server system to allow for indoor localization of WiFi devices.\\n\\nPlease note that FIND will run together with an app that is only available on Android.\\n\\nThere is no iOS app available, for more information see: https://www.internalpositioning.com/faq/#can-i-use-an-iphone"
mqttmissingtext="FIND 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 FIND installation?"
mqttpasswd="/etc/mosquitto/passwd"
successtext="FIND setup was successful.\\n\\nSettings can be configured in '/etc/default/findserver'. Be sure to restart the service after.\\n\\nYou can obtain the FIND app for Android through the Play Store. There is no iOS app available, for more information see: https://www.internalpositioning.com/faq/#can-i-use-an-iphone\\n\\nCheck out your FIND server's dashboard at: http://${HOSTNAME}:8003\\n\\nFor further information: https://www.internalpositioning.com"
temp="$(mktemp -d "${TMPDIR:-/tmp}"/openhabian.XXXXX)"

echo "$(timestamp) [openHABian] Beginning setup of FIND, the Framework for Internal Navigation and Discovery... "

if [ ! -f "/etc/mosquitto/mosquitto.conf" ]; then
if ! (whiptail --defaultno --title "Mosquitto not installed, continue?" --yes-button "Continue" --no-button "Cancel" --yesno "$mqttmissingtext" 13 80); then echo "CANCELED"; return 0; fi
fi

if (whiptail --title "FIND installation?" --yes-button "Continue" --no-button "Cancel" --yesno "$introtext" 14 80); then echo "OK"; else echo "CANCELED"; return 0; fi

echo -n "$(timestamp) [openHABian] Configuring FIND... "
if ! MQTTSERVER=$(whiptail --title "FIND Setup" --inputbox "\\nPlease enter the hostname of the device your MQTT broker is running on:" 9 80 localhost 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi
if [[ $MQTTSERVER != "localhost" ]]; 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 ! MQTTPORT=$(whiptail --title "FIND Setup" --inputbox "\\nPlease enter the port number the MQTT broker is listening on:" 9 80 1883 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi
if [[ -f $mqttpasswd ]]; then
if ! FINDADMIN=$(whiptail --title "findserver MQTT Setup" --inputbox "\\nEnter a username for FIND to connect with on your MQTT broker:" 9 80 find 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi
while [[ -z $FINDADMINPASS ]]; do
if ! findPass1=$(whiptail --title "findserver MQTT Setup" --passwordbox "\\nEnter a password for the FIND user on your MQTT broker:" 9 80 3>&1 1>&2 2>&3); then echo "CANCELED"; return 0; fi
if ! findPass2=$(whiptail --title "findserver MQTT Setup" --passwordbox "\\nPlease confirm the password for the FIND 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
FINDADMINPASS="$findPass1"
else
whiptail --title "findserver MQTT Setup" --msgbox "Password mismatched, blank, or less than 8 characters... Please try again!" 7 80
fi
done
if ! cond_redirect mosquitto_passwd -b $mqttpasswd "$FINDADMIN" "$FINDADMINPASS"; 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 FIND... "
if ! cond_redirect mkdir -p "$findDist"; then echo "FAILED (create directory)"; return 1; fi
if ! cond_redirect wget -qO "${temp}/find.zip" "$findRelease"; then echo "FAILED (fetch FIND)"; return 1; fi
if ! cond_redirect wget -qO "${temp}/client.zip" "$findClient"; then echo "FAILED (fetch client)"; return 1; fi
if ! cond_redirect unzip -qo "${temp}/find.zip" -d "$findDist"; then echo "FAILED (unzip FIND)"; return 1; fi
if ! cond_redirect unzip -qo "${temp}/client.zip" fingerprint -d "$findDist"; then echo "FAILED (unzip client)"; return 1; fi
if ! cond_redirect ln -sf "$findDist"/findserver /usr/sbin/findserver; then echo "FAILED (link findserver)"; return 1; fi
if ! cond_redirect ln -sf "$findDist"/fingerprint /usr/sbin/fingerprint; then echo "FAILED (link fingerprint)"; return 1; fi
if cond_redirect rm -rf "$temp"; then echo "OK"; else echo "FAILED"; return 1; fi

echo -n "$(timestamp) [openHABian] Setting up FIND service... "
if ! (sed -e 's|%MQTTSERVER|'"${MQTTSERVER}"'|g; s|%MQTTPORT|'"${MQTTPORT}"'|g; s|%FINDADMINPASS|'"${FINDADMINPASS}"'|g; s|%FINDADMIN|'"${FINDADMIN}"'|g; s|%FINDPORT|8003|g; s|%FINDSERVER|localhost|g' "${BASEDIR:-/opt/openhabian}"/includes/findserver.service > /etc/systemd/system/findserver.service); then echo "FAILED (service file creation)"; return 1; fi
if ! cond_redirect chmod 644 /etc/systemd/system/findserver.service; then echo "FAILED (permissions)"; return 1; fi
if ! (sed -e 's|%MQTTSERVER|'"${MQTTSERVER}"'|g; s|%MQTTPORT|'"${MQTTPORT}"'|g; s|%FINDADMINPASS|'"${FINDADMINPASS}"'|g; s|%FINDADMIN|'"${FINDADMIN}"'|g; s|%FINDPORT|8003|g; s|%FINDSERVER|localhost|g' "${BASEDIR:-/opt/openhabian}"/includes/findserver > /etc/default/findserver); then echo "FAILED (service configuration creation)"; return 1; fi
cond_redirect systemctl -q daemon-reload &> /dev/null
if ! cond_redirect systemctl enable findserver.service; then echo "FAILED (enable service)"; return 1; fi
if cond_redirect systemctl restart findserver.service; then echo "OK"; else echo "FAILED (restart service)"; return 1; fi

whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80

if [[ -z $BATS_TEST_NAME ]]; then
dashboard_add_tile find
fi
}

## Function for installing kndx as your EIB/KNX IP gateway and router to support your KNX bus system.
## This function can be invoked either INTERACTIVE with userinterface or UNATTENDED.
##
Expand Down
4 changes: 2 additions & 2 deletions includes/dashboard-imagedata.sh

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions includes/find3ai.service
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
6 changes: 6 additions & 0 deletions includes/find3server
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
13 changes: 13 additions & 0 deletions includes/find3server.service
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
9 changes: 0 additions & 9 deletions includes/findserver

This file was deleted.

13 changes: 0 additions & 13 deletions includes/findserver.service

This file was deleted.

0 comments on commit 41633b7

Please sign in to comment.