199 lines
6.4 KiB
Bash
Executable File
199 lines
6.4 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Installation script for Generator Current Ramp Controller
|
|
#
|
|
# Run this on the Venus OS device after copying files to /data/dbus-generator-ramp/
|
|
#
|
|
# Usage:
|
|
# chmod +x install.sh
|
|
# ./install.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/data/dbus-generator-ramp"
|
|
# 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
|
|
# Search for velib_python in existing Venus OS services (in order of preference)
|
|
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
|
|
# Last resort: find any vedbus.py
|
|
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
|
|
# Venus OS uses either /service or /opt/victronenergy/service depending on version
|
|
if [ -d "/service" ] && [ ! -L "/service" ]; then
|
|
# /service is a real directory (some Venus OS versions)
|
|
SERVICE_DIR="/service"
|
|
elif [ -d "/opt/victronenergy/service" ]; then
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
elif [ -L "/service" ]; then
|
|
# /service is a symlink, follow it
|
|
SERVICE_DIR=$(readlink -f /service)
|
|
else
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
fi
|
|
|
|
echo "=================================================="
|
|
echo "Generator Current Ramp Controller - 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 files exist
|
|
if [ ! -f "$INSTALL_DIR/dbus-generator-ramp.py" ]; then
|
|
echo "ERROR: Installation files not found in $INSTALL_DIR"
|
|
echo " Please copy all files to $INSTALL_DIR first."
|
|
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/dbus-generator-ramp.py"
|
|
|
|
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"
|
|
# Remove existing symlink if it points somewhere else
|
|
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. Creating main service symlink..."
|
|
if [ -L "$SERVICE_DIR/dbus-generator-ramp" ]; then
|
|
echo " Service link already exists, removing old link..."
|
|
rm "$SERVICE_DIR/dbus-generator-ramp"
|
|
fi
|
|
if [ -e "$SERVICE_DIR/dbus-generator-ramp" ]; then
|
|
echo " Removing existing service directory..."
|
|
rm -rf "$SERVICE_DIR/dbus-generator-ramp"
|
|
fi
|
|
ln -s "$INSTALL_DIR/service" "$SERVICE_DIR/dbus-generator-ramp"
|
|
|
|
# Verify symlink was created
|
|
if [ -L "$SERVICE_DIR/dbus-generator-ramp" ]; then
|
|
echo " Symlink created: $SERVICE_DIR/dbus-generator-ramp -> $INSTALL_DIR/service"
|
|
else
|
|
echo "ERROR: Failed to create service symlink"
|
|
exit 1
|
|
fi
|
|
|
|
echo "4. Creating log directory..."
|
|
mkdir -p /var/log/dbus-generator-ramp
|
|
|
|
echo "5. 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
|
|
|
|
# Check if already in rc.local
|
|
if ! grep -q "dbus-generator-ramp" "$RC_LOCAL"; then
|
|
echo "" >> "$RC_LOCAL"
|
|
echo "# Generator Current Ramp Controller" >> "$RC_LOCAL"
|
|
echo "if [ ! -L $SERVICE_DIR/dbus-generator-ramp ]; then" >> "$RC_LOCAL"
|
|
echo " ln -s /data/dbus-generator-ramp/service $SERVICE_DIR/dbus-generator-ramp" >> "$RC_LOCAL"
|
|
echo "fi" >> "$RC_LOCAL"
|
|
echo " Added to rc.local for persistence across firmware updates"
|
|
else
|
|
echo " Already in rc.local"
|
|
fi
|
|
|
|
echo "6. Activating service..."
|
|
# Give svscan a moment to detect the new service
|
|
sleep 2
|
|
# Check if service is being supervised
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
if svstat "$SERVICE_DIR/dbus-generator-ramp" 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 ""
|
|
|
|
# Show current status
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
echo "Current status:"
|
|
svstat "$SERVICE_DIR/dbus-generator-ramp" 2>/dev/null || echo " Service not yet detected by svscan"
|
|
echo ""
|
|
fi
|
|
|
|
echo "To check status:"
|
|
echo " svstat $SERVICE_DIR/dbus-generator-ramp"
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " tail -F /var/log/dbus-generator-ramp/current | tai64nlocal"
|
|
echo ""
|
|
echo "MQTT Paths:"
|
|
echo " N/<vrm-id>/generatorramp/0/State"
|
|
echo " N/<vrm-id>/generatorramp/0/CurrentLimit"
|
|
echo " N/<vrm-id>/generatorramp/0/Settings/..."
|
|
echo ""
|
|
echo "To stop the service:"
|
|
echo " svc -d $SERVICE_DIR/dbus-generator-ramp"
|
|
echo ""
|
|
echo "IMPORTANT: The VE.Bus service is set to: com.victronenergy.vebus.ttyS4"
|
|
echo " If this is incorrect, edit: $INSTALL_DIR/config.py"
|
|
echo ""
|
|
echo "Optional: Install native GUI integration:"
|
|
echo " ./install_gui.sh"
|
|
echo ""
|
|
echo "Troubleshooting:"
|
|
echo " ls -la $SERVICE_DIR/dbus-generator-ramp"
|
|
echo " cat /var/log/dbus-generator-ramp/current | tai64nlocal | tail -20"
|
|
echo ""
|