- Added lib/signal_reader.py with SignalGpsReader, SignalMeteoReader, and SignalDepthReader that use PropertiesChanged signal subscriptions instead of polling via GetValue(), reducing D-Bus overhead at steady state. - Each reader discovers its service dynamically, seeds its cache with a one-shot GetValue, then relies on signals for all subsequent updates. - Refactored dbus-tides, dbus-windy-station, dbus-no-foreign-land, dbus-lightning, and dbus-meteoblue-forecast to import from the shared library, removing ~600 lines of duplicated _unwrap() helpers and per-service GPS/meteo/depth reader classes. - Updated install.sh for all five services to deploy signal_reader.py to /data/lib/ on the target device. - Updated build-package.sh for all five services to bundle signal_reader.py into the .tar.gz package. - Updated README.md with the new lib/ entry in the project table and documented the shared D-Bus readers pattern. - Bumped version numbers in affected services (e.g. nfl_tracking 2.0.1). Made-with: Cursor
218 lines
7.0 KiB
Bash
218 lines
7.0 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Installation script for NFL (No Foreign Land) Tracking
|
|
#
|
|
# Run this on the Venus OS device after copying files to /data/dbus-no-foreign-land/
|
|
#
|
|
# Usage:
|
|
# chmod +x install.sh
|
|
# ./install.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/data/dbus-no-foreign-land"
|
|
|
|
# Find velib_python - check standard location first, then search existing services
|
|
VELIB_DIR=""
|
|
if [ -d "/opt/victronenergy/velib_python" ]; then
|
|
VELIB_DIR="/opt/victronenergy/velib_python"
|
|
else
|
|
for candidate in \
|
|
"/opt/victronenergy/dbus-systemcalc-py/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-generator/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-mqtt/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-digitalinputs/ext/velib_python" \
|
|
"/opt/victronenergy/vrmlogger/ext/velib_python"
|
|
do
|
|
if [ -d "$candidate" ] && [ -f "$candidate/vedbus.py" ]; then
|
|
VELIB_DIR="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -z "$VELIB_DIR" ]; then
|
|
VEDBUS_PATH=$(find /opt/victronenergy -name "vedbus.py" -path "*/velib_python/*" 2>/dev/null | head -1)
|
|
if [ -n "$VEDBUS_PATH" ]; then
|
|
VELIB_DIR=$(dirname "$VEDBUS_PATH")
|
|
fi
|
|
fi
|
|
|
|
# Determine the correct service directory
|
|
if [ -d "/service" ] && [ ! -L "/service" ]; then
|
|
SERVICE_DIR="/service"
|
|
elif [ -d "/opt/victronenergy/service" ]; then
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
elif [ -L "/service" ]; then
|
|
SERVICE_DIR=$(readlink -f /service)
|
|
else
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
fi
|
|
|
|
echo "=================================================="
|
|
echo "NFL (No Foreign Land) Tracking - Installation"
|
|
echo "=================================================="
|
|
|
|
# Check if running on Venus OS
|
|
if [ ! -d "$SERVICE_DIR" ]; then
|
|
echo "ERROR: This doesn't appear to be a Venus OS device."
|
|
echo " Service directory not found."
|
|
echo " Checked: /service, /opt/victronenergy/service"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Detected service directory: $SERVICE_DIR"
|
|
|
|
# Check if required files exist
|
|
if [ ! -f "$INSTALL_DIR/nfl_tracking.py" ]; then
|
|
echo "ERROR: Installation files not found in $INSTALL_DIR"
|
|
echo " Please copy all files to $INSTALL_DIR first."
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$INSTALL_DIR/service/run" ]; then
|
|
echo "ERROR: service/run not found. The package is incomplete."
|
|
echo " Rebuild with build-package.sh or ensure service/ is included."
|
|
echo " Expected: $INSTALL_DIR/service/run"
|
|
exit 1
|
|
fi
|
|
|
|
echo "1. Making scripts executable..."
|
|
chmod +x "$INSTALL_DIR/service/run"
|
|
chmod +x "$INSTALL_DIR/service/log/run"
|
|
chmod +x "$INSTALL_DIR/nfl_tracking.py"
|
|
if [ -f "$INSTALL_DIR/install_gui.sh" ]; then
|
|
chmod +x "$INSTALL_DIR/install_gui.sh"
|
|
fi
|
|
|
|
echo "2. Creating velib_python symlink..."
|
|
if [ -z "$VELIB_DIR" ]; then
|
|
echo "ERROR: Could not find velib_python on this system."
|
|
echo " Searched /opt/victronenergy for vedbus.py"
|
|
exit 1
|
|
fi
|
|
echo " Found velib_python at: $VELIB_DIR"
|
|
mkdir -p "$INSTALL_DIR/ext"
|
|
if [ -L "$INSTALL_DIR/ext/velib_python" ]; then
|
|
CURRENT_TARGET=$(readlink "$INSTALL_DIR/ext/velib_python")
|
|
if [ "$CURRENT_TARGET" != "$VELIB_DIR" ]; then
|
|
echo " Updating symlink (was: $CURRENT_TARGET)"
|
|
rm "$INSTALL_DIR/ext/velib_python"
|
|
fi
|
|
fi
|
|
if [ ! -L "$INSTALL_DIR/ext/velib_python" ]; then
|
|
ln -s "$VELIB_DIR" "$INSTALL_DIR/ext/velib_python"
|
|
echo " Symlink created: $INSTALL_DIR/ext/velib_python -> $VELIB_DIR"
|
|
else
|
|
echo " Symlink already exists"
|
|
fi
|
|
|
|
echo "3. Installing shared library..."
|
|
SHARED_LIB_DIR="/data/lib"
|
|
mkdir -p "$SHARED_LIB_DIR"
|
|
SIGNAL_READER=""
|
|
if [ -f "$INSTALL_DIR/signal_reader.py" ]; then
|
|
SIGNAL_READER="$INSTALL_DIR/signal_reader.py"
|
|
elif [ -f "$(dirname "$INSTALL_DIR")/lib/signal_reader.py" ]; then
|
|
SIGNAL_READER="$(dirname "$INSTALL_DIR")/lib/signal_reader.py"
|
|
fi
|
|
if [ -n "$SIGNAL_READER" ]; then
|
|
cp "$SIGNAL_READER" "$SHARED_LIB_DIR/"
|
|
echo " Installed signal_reader.py to $SHARED_LIB_DIR"
|
|
elif [ -f "$SHARED_LIB_DIR/signal_reader.py" ]; then
|
|
echo " signal_reader.py already installed"
|
|
else
|
|
echo "WARNING: signal_reader.py not found."
|
|
echo " Copy lib/signal_reader.py to $SHARED_LIB_DIR/ manually."
|
|
fi
|
|
|
|
echo "4. Creating main service symlink..."
|
|
if [ -L "$SERVICE_DIR/dbus-no-foreign-land" ]; then
|
|
echo " Service link already exists, removing old link..."
|
|
rm "$SERVICE_DIR/dbus-no-foreign-land"
|
|
fi
|
|
if [ -e "$SERVICE_DIR/dbus-no-foreign-land" ]; then
|
|
echo " Removing existing service directory..."
|
|
rm -rf "$SERVICE_DIR/dbus-no-foreign-land"
|
|
fi
|
|
ln -s "$INSTALL_DIR/service" "$SERVICE_DIR/dbus-no-foreign-land"
|
|
|
|
# Verify symlink was created
|
|
if [ -L "$SERVICE_DIR/dbus-no-foreign-land" ]; then
|
|
echo " Symlink created: $SERVICE_DIR/dbus-no-foreign-land -> $INSTALL_DIR/service"
|
|
else
|
|
echo "ERROR: Failed to create service symlink"
|
|
exit 1
|
|
fi
|
|
|
|
echo "5. Creating data and log directories..."
|
|
mkdir -p "$INSTALL_DIR"
|
|
mkdir -p /var/log/dbus-no-foreign-land
|
|
|
|
echo "6. Setting up rc.local for persistence..."
|
|
RC_LOCAL="/data/rc.local"
|
|
if [ ! -f "$RC_LOCAL" ]; then
|
|
echo "#!/bin/bash" > "$RC_LOCAL"
|
|
chmod +x "$RC_LOCAL"
|
|
fi
|
|
|
|
if ! grep -q "dbus-no-foreign-land" "$RC_LOCAL"; then
|
|
echo "" >> "$RC_LOCAL"
|
|
echo "# NFL (No Foreign Land) Tracking" >> "$RC_LOCAL"
|
|
echo "if [ ! -L $SERVICE_DIR/dbus-no-foreign-land ]; then" >> "$RC_LOCAL"
|
|
echo " ln -s /data/dbus-no-foreign-land/service $SERVICE_DIR/dbus-no-foreign-land" >> "$RC_LOCAL"
|
|
echo "fi" >> "$RC_LOCAL"
|
|
echo " Added to rc.local for persistence across firmware updates"
|
|
else
|
|
echo " Already in rc.local"
|
|
fi
|
|
|
|
echo "7. Activating service..."
|
|
sleep 2
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
if svstat "$SERVICE_DIR/dbus-no-foreign-land" 2>/dev/null | grep -q "up"; then
|
|
echo " Service is running"
|
|
else
|
|
echo " Waiting for service to start..."
|
|
sleep 3
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "=================================================="
|
|
echo "Installation complete!"
|
|
echo "=================================================="
|
|
echo ""
|
|
echo "Service directory: $SERVICE_DIR"
|
|
echo ""
|
|
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
echo "Current status:"
|
|
svstat "$SERVICE_DIR/dbus-no-foreign-land" 2>/dev/null || echo " Service not yet detected by svscan"
|
|
echo ""
|
|
fi
|
|
|
|
echo "IMPORTANT: Configure via Settings menu:"
|
|
echo " 1. Run: ./install_gui.sh (adds NFL Tracking to Settings > GPS)"
|
|
echo " 2. Open Settings > GPS > NFL Tracking and enter your Boat API Key"
|
|
echo " 3. Or use MQTT: N/<vrm-id>/nfltracking/0/Settings/BoatApiKey"
|
|
echo ""
|
|
echo "To check status:"
|
|
echo " svstat $SERVICE_DIR/dbus-no-foreign-land"
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " tail -F /var/log/dbus-no-foreign-land/current | tai64nlocal"
|
|
echo ""
|
|
echo "MQTT Paths:"
|
|
echo " N/<vrm-id>/nfltracking/0/Status"
|
|
echo " N/<vrm-id>/nfltracking/0/TrackPoints"
|
|
echo " N/<vrm-id>/nfltracking/0/Settings/BoatApiKey"
|
|
echo ""
|
|
echo "Install GUI integration (required for configuration):"
|
|
echo " ./install_gui.sh"
|
|
echo ""
|
|
echo "Troubleshooting:"
|
|
echo " ls -la $SERVICE_DIR/dbus-no-foreign-land"
|
|
echo " cat /var/log/dbus-no-foreign-land/current | tai64nlocal | tail -20"
|
|
echo ""
|