-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
372 lines (318 loc) · 13.4 KB
/
Copy pathinstall.sh
File metadata and controls
372 lines (318 loc) · 13.4 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════
# OLED Dashboard - One-Command Installer
# Usage: curl -sSL https://raw.githubusercontent.com/Cr4zySh4rk/oled-dashboard/main/install.sh | sudo bash
# ═══════════════════════════════════════════════════════════════
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
INSTALL_DIR="/opt/oled-dashboard"
CONFIG_DIR="/root/.config/oled-dashboard"
SERVICE_NAME="oled-dashboard"
REPO_URL="https://github.com/Cr4zySh4rk/oled-dashboard.git"
BRANCH="main"
# ── Functions ──────────────────────────────────────────────────
print_banner() {
echo -e "${CYAN}"
echo " ╔═══════════════════════════════════════════╗"
echo " ║ OLED Dashboard Installer ║"
echo " ║ Web-configurable OLED display manager ║"
echo " ╚═══════════════════════════════════════════╝"
echo -e "${NC}"
}
log_info() {
echo -e "${GREEN}[✓]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[!]${NC} $1"
}
log_error() {
echo -e "${RED}[✗]${NC} $1"
}
log_step() {
echo -e "\n${BOLD}${CYAN}──── $1 ────${NC}\n"
}
check_root() {
if [ "$(id -u)" -ne 0 ]; then
log_error "This installer must be run as root (use sudo)"
exit 1
fi
}
check_platform() {
if [ ! -f /proc/device-tree/model ] 2>/dev/null; then
log_warn "This doesn't appear to be a Raspberry Pi"
log_warn "The OLED display drivers may not work, but the web UI will run in simulation mode"
read -p "Continue anyway? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
else
PI_MODEL=$(cat /proc/device-tree/model 2>/dev/null || echo "Unknown")
log_info "Detected: ${PI_MODEL}"
fi
}
enable_i2c() {
log_step "Enabling I2C Interface"
# Enable I2C via raspi-config noninteractive
if command -v raspi-config &>/dev/null; then
raspi-config nonint do_i2c 0 2>/dev/null || true
log_info "I2C enabled via raspi-config"
fi
# Also enable via config.txt as fallback
if [ -f /boot/config.txt ]; then
if ! grep -q "^dtparam=i2c_arm=on" /boot/config.txt; then
echo "dtparam=i2c_arm=on" >> /boot/config.txt
log_info "Added I2C to /boot/config.txt"
fi
elif [ -f /boot/firmware/config.txt ]; then
if ! grep -q "^dtparam=i2c_arm=on" /boot/firmware/config.txt; then
echo "dtparam=i2c_arm=on" >> /boot/firmware/config.txt
log_info "Added I2C to /boot/firmware/config.txt"
fi
fi
# Load I2C kernel module
modprobe i2c-dev 2>/dev/null || true
if ! grep -q "i2c-dev" /etc/modules 2>/dev/null; then
echo "i2c-dev" >> /etc/modules
fi
log_info "I2C interface configured"
}
enable_spi() {
log_step "Enabling SPI Interface"
if command -v raspi-config &>/dev/null; then
raspi-config nonint do_spi 0 2>/dev/null || true
log_info "SPI enabled via raspi-config"
fi
if [ -f /boot/config.txt ]; then
if ! grep -q "^dtparam=spi=on" /boot/config.txt; then
echo "dtparam=spi=on" >> /boot/config.txt
fi
elif [ -f /boot/firmware/config.txt ]; then
if ! grep -q "^dtparam=spi=on" /boot/firmware/config.txt; then
echo "dtparam=spi=on" >> /boot/firmware/config.txt
fi
fi
log_info "SPI interface configured"
}
install_system_deps() {
log_step "Installing System Dependencies"
apt-get update -qq
# Core packages — always needed
apt-get install -y -qq \
python3 \
python3-pip \
python3-venv \
python3-dev \
python3-pil \
python3-smbus \
i2c-tools \
libfreetype6-dev \
libjpeg-dev \
libopenjp2-7 \
libssl-dev \
git \
fonts-dejavu-core \
2>/dev/null
# GPIO / hardware packages — install from apt (pre-compiled, no build tools needed).
# These are the packages that fail when pip tries to compile them from source on
# DietPi / Pi Zero because the kernel headers / build chain may be absent.
log_info "Installing GPIO/hardware packages from apt (pre-compiled)..."
apt-get install -y -qq \
python3-rpi.gpio \
2>/dev/null && log_info "python3-rpi.gpio installed via apt" \
|| log_warn "python3-rpi.gpio not available in apt — will try pip fallback"
# smbus2 / python3-smbus for I2C
apt-get install -y -qq python3-smbus2 2>/dev/null \
|| apt-get install -y -qq python3-smbus 2>/dev/null \
|| true
log_info "System dependencies installed"
}
clone_or_update_repo() {
log_step "Installing OLED Dashboard"
if [ -d "$INSTALL_DIR/.git" ]; then
log_info "Existing installation found, updating..."
cd "$INSTALL_DIR"
git fetch origin
git reset --hard "origin/$BRANCH"
else
rm -rf "$INSTALL_DIR"
git clone --depth 1 -b "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
log_info "Repository cloned to $INSTALL_DIR"
fi
cd "$INSTALL_DIR"
}
setup_python_env() {
log_step "Setting Up Python Environment"
cd "$INSTALL_DIR"
# Create venv with --system-site-packages so apt-installed packages
# (python3-pil, python3-rpi.gpio, python3-smbus) are visible inside the venv
# without needing to recompile anything from source.
python3 -m venv --system-site-packages venv
source venv/bin/activate
# Upgrade pip/setuptools — but do NOT let this step fail the whole install
pip install --upgrade pip setuptools wheel 2>/dev/null || true
# ── Core Python dependencies (pure-Python, always safe) ──────────────────
log_info "Installing core Python dependencies..."
pip install "flask>=2.0" "Pillow>=9.0" "psutil>=5.9" "requests>=2.28" \
|| { log_error "Core pip installs failed — aborting"; exit 1; }
# ── smbus2 (I2C helper — pure Python, installs fine everywhere) ──────────
pip install smbus2 2>/dev/null \
&& log_info "smbus2 installed" \
|| log_warn "smbus2 pip install failed (apt version will be used)"
# ── Adafruit / CircuitPython OLED stack ───────────────────────────────────
# adafruit-blinka pulls in RPi.GPIO and rpi_ws281x as C-extension deps.
# On DietPi / Pi Zero the kernel headers may be absent so a source build
# fails. We install with --no-build-isolation and set the env var that
# tells the RPi.GPIO build to skip the hardware check, then fall back
# gracefully if it still fails.
log_info "Installing adafruit-blinka (CircuitPython Pi bridge)..."
READTHEDOCS=True pip install --upgrade adafruit-blinka 2>/dev/null \
&& log_info "adafruit-blinka installed" \
|| {
log_warn "adafruit-blinka pip install failed"
log_warn "Attempting RPi.GPIO from apt + blinka install without GPIO dep..."
# Try installing RPi.GPIO wheel from piwheels (pre-built for Pi)
pip install --extra-index-url https://www.piwheels.org/simple \
RPi.GPIO 2>/dev/null \
&& log_info "RPi.GPIO installed from piwheels" \
|| log_warn "RPi.GPIO install failed — luma.oled fallback will be used"
READTHEDOCS=True pip install adafruit-blinka 2>/dev/null \
&& log_info "adafruit-blinka installed (second attempt)" \
|| log_warn "adafruit-blinka unavailable — falling back to luma.oled"
}
log_info "Installing adafruit-circuitpython-ssd1306..."
pip install adafruit-circuitpython-ssd1306 2>/dev/null \
&& log_info "adafruit-circuitpython-ssd1306 installed" \
|| log_warn "adafruit-circuitpython-ssd1306 install failed (luma fallback will be used)"
# ── luma.oled fallback stack ──────────────────────────────────────────────
# Used automatically by the dashboard drivers when adafruit-blinka is absent.
log_info "Installing luma.oled fallback stack..."
pip install --extra-index-url https://www.piwheels.org/simple \
luma.oled luma.core 2>/dev/null \
&& log_info "luma.oled installed" \
|| log_warn "luma.oled install failed — display will run in simulation mode"
# ── Install the dashboard package itself (no hardware deps in install_requires) ──
log_info "Installing oled-dashboard package..."
pip install -e . \
&& log_info "oled-dashboard package installed" \
|| { log_error "oled-dashboard install failed"; exit 1; }
deactivate
log_info "Python environment configured"
}
create_config() {
log_step "Creating Default Configuration"
mkdir -p "$CONFIG_DIR"
if [ ! -f "$CONFIG_DIR/config.json" ]; then
cat > "$CONFIG_DIR/config.json" << 'CONFIGEOF'
{
"display": {
"chip": "SSD1306",
"width": 128,
"height": 64,
"interface": "i2c",
"i2c_address": "0x3C",
"i2c_bus": 1,
"rotation": 0,
"brightness": 255
},
"layout": {
"name": "Default",
"widgets": [
{"widget_id": "ip_address", "x": 0, "y": 0, "width": 128, "height": 14, "font_size": 12, "config": {"show_label": true}},
{"widget_id": "cpu_usage", "x": 0, "y": 16, "width": 60, "height": 14, "font_size": 11, "config": {"show_bar": false}},
{"widget_id": "temperature", "x": 68, "y": 16, "width": 60, "height": 14, "font_size": 11, "config": {"unit": "C"}},
{"widget_id": "ram_usage", "x": 0, "y": 32, "width": 128, "height": 14, "font_size": 11, "config": {"format": "compact"}},
{"widget_id": "disk_space", "x": 0, "y": 48, "width": 128, "height": 14, "font_size": 11, "config": {"mount_point": "/", "show_bar": false}}
]
},
"server": {
"host": "0.0.0.0",
"port": 8686,
"debug": false
},
"refresh_rate": 1.0
}
CONFIGEOF
log_info "Default configuration created"
else
log_info "Existing configuration preserved"
fi
}
install_service() {
log_step "Installing Systemd Service"
cp "$INSTALL_DIR/systemd/oled-dashboard.service" /etc/systemd/system/
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl start "$SERVICE_NAME"
log_info "Service installed and started"
}
detect_displays() {
log_step "Detecting I2C Displays"
if command -v i2cdetect &>/dev/null; then
echo "Scanning I2C bus 1..."
i2cdetect -y 1 2>/dev/null || log_warn "No I2C bus found (this is normal if I2C was just enabled)"
else
log_warn "i2cdetect not available, skipping detection"
fi
}
print_summary() {
# Get the Pi's IP address
LOCAL_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ -z "$LOCAL_IP" ]; then
LOCAL_IP="<your-pi-ip>"
fi
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════${NC}"
echo -e "${GREEN} OLED Dashboard installed successfully!${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════${NC}"
echo ""
echo -e " ${BOLD}Web UI:${NC} http://${LOCAL_IP}:8686"
echo ""
echo -e " ${BOLD}Commands:${NC}"
echo -e " Start: ${CYAN}sudo systemctl start oled-dashboard${NC}"
echo -e " Stop: ${CYAN}sudo systemctl stop oled-dashboard${NC}"
echo -e " Restart: ${CYAN}sudo systemctl restart oled-dashboard${NC}"
echo -e " Status: ${CYAN}sudo systemctl status oled-dashboard${NC}"
echo -e " Logs: ${CYAN}sudo journalctl -u oled-dashboard -f${NC}"
echo ""
echo -e " ${BOLD}Config:${NC} $CONFIG_DIR/config.json"
echo -e " ${BOLD}Install:${NC} $INSTALL_DIR"
echo ""
echo -e " ${YELLOW}Note:${NC} If I2C/SPI was just enabled, a reboot may be required."
echo -e " Run: ${CYAN}sudo reboot${NC}"
echo ""
}
# ── Main ───────────────────────────────────────────────────────
main() {
print_banner
check_root
check_platform
install_system_deps
enable_i2c
enable_spi
clone_or_update_repo
setup_python_env
create_config
install_service
detect_displays
print_summary
}
# Handle uninstall flag
if [ "${1:-}" = "--uninstall" ]; then
echo -e "${YELLOW}Uninstalling OLED Dashboard...${NC}"
systemctl stop "$SERVICE_NAME" 2>/dev/null || true
systemctl disable "$SERVICE_NAME" 2>/dev/null || true
rm -f /etc/systemd/system/oled-dashboard.service
systemctl daemon-reload
rm -rf "$INSTALL_DIR"
echo -e "${GREEN}OLED Dashboard uninstalled.${NC}"
echo -e "Config preserved at: $CONFIG_DIR"
exit 0
fi
main "$@"