-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·230 lines (197 loc) · 7.56 KB
/
install.sh
File metadata and controls
executable file
·230 lines (197 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
#
# Remote installer for victron-seelevel-python on Venus OS
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/TechBlueprints/victron-seelevel-python/main/install.sh | bash
#
set -e
REPO_URL="https://github.com/TechBlueprints/victron-seelevel-python.git"
INSTALL_DIR="/data/apps/victron-seelevel-python"
OLD_INSTALL_DIR="/data/apps/dbus-seelevel"
SERVICE_NAME="dbus-seelevel"
BLE_ROUTER_INSTALLER="https://raw.githubusercontent.com/TechBlueprints/dbus-ble-advertisements/main/install.sh"
echo "========================================"
echo "SeeLevel 709-BT Service Installer"
echo "========================================"
echo ""
# Check if running on Venus OS
if [ ! -d "/data/apps" ]; then
echo "Error: /data/apps not found. This script must run on Venus OS."
exit 1
fi
# Step 0: Install dbus-ble-advertisements (required dependency)
echo "Step 0: Installing required dependency (dbus-ble-advertisements)..."
echo ""
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$BLE_ROUTER_INSTALLER" | bash
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$BLE_ROUTER_INSTALLER" | bash
else
echo "Error: Neither curl nor wget found."
exit 1
fi
echo ""
echo "✓ Dependency installation complete"
echo ""
# Step 1: Ensure git is installed
echo "Step 1: Checking for git..."
if ! command -v git >/dev/null 2>&1; then
echo "Git not found. Installing git..."
if ! opkg install git; then
echo "Error: Failed to install git."
exit 1
fi
echo "✓ Git installed successfully"
else
echo "✓ Git already installed"
fi
echo ""
# Step 2: Clone or update repository
echo "Step 2: Setting up repository..."
cd /data/apps
NEEDS_RESTART=false
# Migrate from old install location if it exists
if [ -d "$OLD_INSTALL_DIR" ] && [ ! -d "$INSTALL_DIR" ]; then
echo "Migrating from old install location..."
# Stop old service if running
svc -d /service/$SERVICE_NAME 2>/dev/null || true
rm -f /service/$SERVICE_NAME 2>/dev/null || true
# Move to new location
mv "$OLD_INSTALL_DIR" "$INSTALL_DIR"
echo "✓ Migrated to $INSTALL_DIR"
NEEDS_RESTART=true
elif [ -d "$OLD_INSTALL_DIR" ] && [ -d "$INSTALL_DIR" ]; then
echo "Removing old install location (new location exists)..."
svc -d /service/$SERVICE_NAME 2>/dev/null || true
rm -rf "$OLD_INSTALL_DIR"
echo "✓ Removed old install at $OLD_INSTALL_DIR"
fi
if [ -d "$INSTALL_DIR" ]; then
echo "Directory exists: $INSTALL_DIR"
cd "$INSTALL_DIR"
# Add to safe directories (ownership consideration)
git config --global --add safe.directory "$INSTALL_DIR" 2>/dev/null || true
# Check if it's already a git repository with correct remote
if [ -d .git ]; then
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
if [ "$CURRENT_REMOTE" != "$REPO_URL" ]; then
echo "Updating remote URL to $REPO_URL..."
git remote set-url origin "$REPO_URL" 2>/dev/null || git remote add origin "$REPO_URL"
fi
echo "Fetching latest changes..."
git fetch origin
# Check current commit vs remote
LOCAL=$(git rev-parse HEAD 2>/dev/null || echo "none")
REMOTE=$(git rev-parse origin/main 2>/dev/null || echo "none")
if [ "$LOCAL" != "$REMOTE" ]; then
echo "Updates available. Resetting to latest..."
# Discard any local changes and reset to origin/main
git checkout main 2>/dev/null || git checkout -b main origin/main
git reset --hard origin/main
NEEDS_RESTART=true
echo "✓ Repository updated to latest"
else
echo "✓ Already up to date"
fi
else
echo "Not a git repository. Converting..."
# Back up any existing files
if [ -f "data/dbus-seelevel-service.py" ]; then
echo "Backing up existing installation..."
mkdir -p /tmp/seelevel-backup
cp -r data /tmp/seelevel-backup/ 2>/dev/null || true
fi
# Initialize as git repo
git init
git remote add origin "$REPO_URL"
# Fetch and reset to main
git fetch origin
git checkout -b main origin/main 2>/dev/null || git checkout main
git reset --hard origin/main
git branch --set-upstream-to=origin/main main 2>/dev/null || true
NEEDS_RESTART=true
echo "✓ Converted to git repository and updated to latest"
fi
else
echo "Directory does not exist. Cloning repository..."
git clone "$REPO_URL" "$INSTALL_DIR"
cd "$INSTALL_DIR"
# Add to safe directories
git config --global --add safe.directory "$INSTALL_DIR" 2>/dev/null || true
NEEDS_RESTART=false # New install, not a restart
echo "✓ Repository cloned"
fi
echo ""
# Step 3: Install or restart service
echo "Step 3: Installing/updating service..."
# Check if service is already running
if [ -L "/service/$SERVICE_NAME" ] && svstat "/service/$SERVICE_NAME" 2>/dev/null | grep -q "up"; then
if [ "$NEEDS_RESTART" = true ]; then
echo "Service is already installed and running."
echo "Updates detected. Restarting service..."
svc -t "/service/$SERVICE_NAME"
sleep 2
# Verify it restarted
if svstat "/service/$SERVICE_NAME" 2>/dev/null | grep -q "up"; then
echo "✓ Service restarted successfully"
else
echo "Warning: Service may not have restarted properly. Check logs:"
echo " tail -f /var/log/$SERVICE_NAME/current"
fi
else
echo "Service is already installed and running."
echo "✓ No updates needed"
fi
else
echo "Service not installed or not running. Running installation..."
bash "$INSTALL_DIR/install-service.sh"
FRESH_INSTALL=true
fi
echo ""
echo "========================================"
echo "Installation Complete!"
echo "========================================"
echo ""
# Check if discoveries are enabled (skip for fresh installs as discovery is enabled by default)
if [ "$FRESH_INSTALL" != true ]; then
# Wait a moment for D-Bus to be ready after restart
sleep 2
BLE_DISCOVERY=$(dbus -y com.victronenergy.switch.ble_advertisements /SwitchableOutput/relay_discovery/State GetValue 2>/dev/null || echo "")
SEELEVEL_DISCOVERY=$(dbus -y com.victronenergy.switch.seelevel /SwitchableOutput/relay_discovery/State GetValue 2>/dev/null || echo "")
WARNINGS=false
if [ "$BLE_DISCOVERY" = "0" ]; then
echo "⚠️ WARNING: BLE Router discovery is currently DISABLED"
WARNINGS=true
fi
if [ "$SEELEVEL_DISCOVERY" = "0" ]; then
echo "⚠️ WARNING: SeeLevel Tank discovery is currently DISABLED"
WARNINGS=true
fi
if [ "$WARNINGS" = true ]; then
echo ""
echo "For sensors to appear, BOTH discoveries must be enabled:"
echo " 1. BLE Router New Device Discovery"
echo " 2. SeeLevel Tank Discovery"
echo ""
echo "See: https://github.com/TechBlueprints/victron-seelevel-python#switches-not-visible"
echo ""
else
echo "✓ Both discoveries are enabled"
echo ""
fi
fi
echo "Run diagnostic to verify setup:"
echo " bash $INSTALL_DIR/diagnose.sh"
echo ""
echo "Service status:"
svstat "/service/$SERVICE_NAME"
echo ""
echo "View logs:"
echo " tail -f /var/log/$SERVICE_NAME/current"
echo ""
echo "Service management:"
echo " svc -u /service/$SERVICE_NAME # Start"
echo " svc -d /service/$SERVICE_NAME # Stop"
echo " svc -t /service/$SERVICE_NAME # Restart"
echo ""