- 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
185 lines
5.5 KiB
Bash
Executable File
185 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Installation script for Lightning Monitor on Venus OS
|
|
#
|
|
# Usage:
|
|
# chmod +x install.sh
|
|
# ./install.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/data/dbus-lightning"
|
|
|
|
# Find velib_python
|
|
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 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 "Lightning Monitor - Installation"
|
|
echo "=================================================="
|
|
|
|
if [ ! -d "$SERVICE_DIR" ]; then
|
|
echo "ERROR: This doesn't appear to be a Venus OS device."
|
|
echo " Service directory not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Detected service directory: $SERVICE_DIR"
|
|
|
|
if [ ! -f "$INSTALL_DIR/lightning.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."
|
|
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/lightning.py"
|
|
|
|
echo "2. Creating velib_python symlink..."
|
|
if [ -z "$VELIB_DIR" ]; then
|
|
echo "ERROR: Could not find velib_python on this system."
|
|
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 service symlink..."
|
|
if [ -L "$SERVICE_DIR/dbus-lightning" ]; then
|
|
echo " Service link already exists, removing old link..."
|
|
rm "$SERVICE_DIR/dbus-lightning"
|
|
fi
|
|
if [ -e "$SERVICE_DIR/dbus-lightning" ]; then
|
|
rm -rf "$SERVICE_DIR/dbus-lightning"
|
|
fi
|
|
ln -s "$INSTALL_DIR/service" "$SERVICE_DIR/dbus-lightning"
|
|
|
|
if [ -L "$SERVICE_DIR/dbus-lightning" ]; then
|
|
echo " Symlink created: $SERVICE_DIR/dbus-lightning -> $INSTALL_DIR/service"
|
|
else
|
|
echo "ERROR: Failed to create service symlink"
|
|
exit 1
|
|
fi
|
|
|
|
echo "5. Creating log directory..."
|
|
mkdir -p /var/log/dbus-lightning
|
|
|
|
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-lightning" "$RC_LOCAL"; then
|
|
echo "" >> "$RC_LOCAL"
|
|
echo "# Lightning Monitor" >> "$RC_LOCAL"
|
|
echo "if [ ! -L $SERVICE_DIR/dbus-lightning ]; then" >> "$RC_LOCAL"
|
|
echo " ln -s /data/dbus-lightning/service $SERVICE_DIR/dbus-lightning" >> "$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-lightning" 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 ""
|
|
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
echo "Current status:"
|
|
svstat "$SERVICE_DIR/dbus-lightning" 2>/dev/null || echo " Service not yet detected by svscan"
|
|
echo ""
|
|
fi
|
|
|
|
echo "To check status:"
|
|
echo " svstat $SERVICE_DIR/dbus-lightning"
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " tail -F /var/log/dbus-lightning/current | tai64nlocal"
|
|
echo ""
|