-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·167 lines (141 loc) · 5.38 KB
/
install.sh
File metadata and controls
executable file
·167 lines (141 loc) · 5.38 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
#!/bin/bash
#
# Remote installer for dbus-ble-advertisements on Venus OS
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/TechBlueprints/dbus-ble-advertisements/main/install.sh | bash
#
set -e
REPO_URL="https://github.com/TechBlueprints/dbus-ble-advertisements.git"
INSTALL_DIR="/data/apps/dbus-ble-advertisements"
SERVICE_NAME="dbus-ble-advertisements"
echo "========================================"
echo "BLE Advertisements Router 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 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
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..."
# 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 discovery is 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
DISCOVERY_STATE=$(dbus -y com.victronenergy.switch.ble_advertisements /SwitchableOutput/relay_discovery/State GetValue 2>/dev/null || echo "")
if [ "$DISCOVERY_STATE" = "0" ]; then
echo "⚠️ WARNING: BLE Advertisements discovery is currently DISABLED"
echo ""
echo "To discover new BLE devices, you need to enable discovery."
echo "See: https://github.com/TechBlueprints/dbus-ble-advertisements#switches-not-visible"
echo ""
fi
fi
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 ""