-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·102 lines (88 loc) · 3.11 KB
/
bootstrap
File metadata and controls
executable file
·102 lines (88 loc) · 3.11 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
#!/usr/bin/env bash
# CyberPower PDU Bridge
# Created by Matthew Valancy, Valpatel Software LLC
# Copyright 2026 GPL-3.0 License
# https://github.com/mvalancy/CyberPower-PDU
set -euo pipefail
cd "$(dirname "$0")"
source lib/common.sh
check_help "${1:-}" "./bootstrap" "Install system dependencies for development and testing" \
"Usage: ./bootstrap
Installs Docker, mosquitto-clients, SNMP tools, Python test
dependencies, and serial port access. Requires sudo. Run once
on a fresh machine.
What it installs:
- Docker and docker compose plugin
- mosquitto-clients (MQTT testing)
- snmp tools (SNMP testing)
- Python packages (pytest, pysnmp, paho-mqtt, pyserial, etc.)
- dialout group membership (serial port access)"
setup_log "bootstrap"
banner
step "Installing system dependencies"
# Docker
if ! command -v docker &>/dev/null; then
info "Installing Docker..."
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker "$USER"
success "Docker installed. Group membership takes effect on next login."
else
success "Docker already installed"
fi
# Start Docker if not running
if ! sudo systemctl is-active --quiet docker; then
sudo systemctl start docker
sudo systemctl enable docker
success "Docker service started"
fi
# Serial port access (dialout group)
step "Configuring serial port access"
if groups | grep -q dialout; then
success "Already in dialout group"
else
info "Adding $USER to dialout group for serial port access..."
sudo usermod -aG dialout "$USER"
success "Added to dialout group. Takes effect on next login."
fi
# Detect connected serial devices
serial_count=$(ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | wc -l)
if [ "$serial_count" -gt 0 ]; then
success "Found $serial_count serial port(s):"
ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | while read -r dev; do
echo " $dev"
done
# Show serial-by-id for stable naming
if [ -d /dev/serial/by-id ]; then
info "Serial devices by ID:"
ls -la /dev/serial/by-id/ 2>/dev/null | grep -v total | while read -r line; do
echo " $line"
done
fi
else
info "No serial ports detected (ttyUSB/ttyACM)"
fi
# APT packages
step "Installing mosquitto-clients, snmp tools, python3-pip"
sudo apt-get update -qq
sudo apt-get install -y -qq mosquitto-clients snmp python3-pip python3-venv
# Python test dependencies (includes pyserial for serial port PDU control)
step "Installing Python packages"
pip install --user --break-system-packages pytest pytest-asyncio pysnmp-lextudio paho-mqtt aiohttp pyserial 2>/dev/null \
|| pip install --user pytest pytest-asyncio pysnmp-lextudio paho-mqtt aiohttp pyserial
echo ""
success "All dependencies installed"
success "Log saved to $LOG_FILE"
# Check if we need a new shell for group changes
_needs_relogin=false
if ! groups | grep -q docker; then
_needs_relogin=true
fi
if ! groups | grep -q dialout; then
_needs_relogin=true
fi
if [ "$_needs_relogin" = true ]; then
echo ""
warn "Log out and back in (or run 'newgrp docker && newgrp dialout') for Docker and serial port access."
fi
echo ""
info "Next step: ./setup"