216 lines
5.6 KiB
Bash
Executable File
216 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# IPMI Controller - Install Script with Persistence
|
|
# This sets up auto-start and ensures settings persist
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="${1:-/opt/ipmi-controller}"
|
|
DATA_DIR="$INSTALL_DIR/data"
|
|
SERVICE_NAME="ipmi-controller"
|
|
USER="${SUDO_USER:-$USER}"
|
|
|
|
echo "🌡️ IPMI Controller Installation"
|
|
echo "================================"
|
|
echo "Install dir: $INSTALL_DIR"
|
|
echo "Data dir: $DATA_DIR"
|
|
echo "Service user: $USER"
|
|
echo ""
|
|
|
|
# Check if running as root for system-wide install
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "⚠️ Not running as root. Installing to $HOME/ipmi-controller instead."
|
|
INSTALL_DIR="$HOME/ipmi-controller"
|
|
DATA_DIR="$INSTALL_DIR/data"
|
|
SYSTEM_INSTALL=false
|
|
else
|
|
SYSTEM_INSTALL=true
|
|
fi
|
|
|
|
# Create directories
|
|
echo "📁 Creating directories..."
|
|
mkdir -p "$INSTALL_DIR"
|
|
mkdir -p "$DATA_DIR"
|
|
|
|
# Copy files
|
|
echo "📋 Copying files..."
|
|
cp -r . "$INSTALL_DIR/" 2>/dev/null || true
|
|
|
|
# Ensure data directory exists with proper files
|
|
if [ ! -f "$DATA_DIR/config.json" ]; then
|
|
echo "⚙️ Creating default config..."
|
|
cat > "$DATA_DIR/config.json" << 'EOF'
|
|
{
|
|
"ipmi_host": "",
|
|
"ipmi_username": "",
|
|
"ipmi_password": "",
|
|
"ipmi_port": 623,
|
|
"http_sensor_enabled": false,
|
|
"http_sensor_url": "",
|
|
"http_sensor_timeout": 10,
|
|
"enabled": false,
|
|
"poll_interval": 10,
|
|
"min_speed": 10,
|
|
"max_speed": 100,
|
|
"panic_temp": 85,
|
|
"panic_speed": 100,
|
|
"panic_on_no_data": true,
|
|
"no_data_timeout": 60,
|
|
"primary_sensor": "cpu",
|
|
"sensor_preference": "auto",
|
|
"fans": {},
|
|
"fan_groups": {},
|
|
"fan_curves": {
|
|
"Balanced": {
|
|
"points": [
|
|
{"temp": 30, "speed": 10},
|
|
{"temp": 35, "speed": 12},
|
|
{"temp": 40, "speed": 15},
|
|
{"temp": 45, "speed": 20},
|
|
{"temp": 50, "speed": 30},
|
|
{"temp": 55, "speed": 40},
|
|
{"temp": 60, "speed": 55},
|
|
{"temp": 65, "speed": 70},
|
|
{"temp": 70, "speed": 85},
|
|
{"temp": 75, "speed": 95},
|
|
{"temp": 80, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
},
|
|
"Silent": {
|
|
"points": [
|
|
{"temp": 30, "speed": 5},
|
|
{"temp": 40, "speed": 10},
|
|
{"temp": 50, "speed": 15},
|
|
{"temp": 55, "speed": 25},
|
|
{"temp": 60, "speed": 35},
|
|
{"temp": 65, "speed": 50},
|
|
{"temp": 70, "speed": 70},
|
|
{"temp": 75, "speed": 85},
|
|
{"temp": 80, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
},
|
|
"Performance": {
|
|
"points": [
|
|
{"temp": 30, "speed": 20},
|
|
{"temp": 35, "speed": 25},
|
|
{"temp": 40, "speed": 35},
|
|
{"temp": 45, "speed": 45},
|
|
{"temp": 50, "speed": 55},
|
|
{"temp": 55, "speed": 70},
|
|
{"temp": 60, "speed": 85},
|
|
{"temp": 65, "speed": 95},
|
|
{"temp": 70, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
}
|
|
},
|
|
"active_curve": "Balanced",
|
|
"theme": "dark"
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
if [ ! -f "$DATA_DIR/users.json" ]; then
|
|
echo "👤 Creating users file..."
|
|
echo '{"users": {}}' > "$DATA_DIR/users.json"
|
|
fi
|
|
|
|
# Install Python dependencies
|
|
echo "🐍 Installing dependencies..."
|
|
if [ "$SYSTEM_INSTALL" = true ]; then
|
|
pip3 install -q -r "$INSTALL_DIR/requirements.txt" || pip install -q -r "$INSTALL_DIR/requirements.txt"
|
|
else
|
|
pip3 install --user -q -r "$INSTALL_DIR/requirements.txt" 2>/dev/null || true
|
|
fi
|
|
|
|
# Install ipmitool if not present
|
|
if ! command -v ipmitool &> /dev/null; then
|
|
echo "📦 Installing ipmitool..."
|
|
if [ "$SYSTEM_INSTALL" = true ]; then
|
|
apt-get update -qq && apt-get install -y -qq ipmitool
|
|
else
|
|
echo "⚠️ Please install ipmitool manually: sudo apt-get install ipmitool"
|
|
fi
|
|
else
|
|
echo "✓ ipmitool already installed"
|
|
fi
|
|
|
|
# Create systemd service (system-wide only)
|
|
if [ "$SYSTEM_INSTALL" = true ]; then
|
|
echo "🔧 Creating systemd service..."
|
|
cat > "/etc/systemd/system/$SERVICE_NAME.service" << EOF
|
|
[Unit]
|
|
Description=IPMI Controller
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$USER
|
|
WorkingDirectory=$INSTALL_DIR
|
|
Environment="PYTHONUNBUFFERED=1"
|
|
Environment="DATA_DIR=$DATA_DIR"
|
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/web_server.py
|
|
ExecStop=/bin/kill -TERM \$MAINPID
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable "$SERVICE_NAME"
|
|
|
|
# Set proper ownership
|
|
chown -R "$USER:$USER" "$INSTALL_DIR"
|
|
|
|
echo ""
|
|
echo "✅ Installation complete!"
|
|
echo ""
|
|
echo "Start the service:"
|
|
echo " sudo systemctl start $SERVICE_NAME"
|
|
echo ""
|
|
echo "Check status:"
|
|
echo " sudo systemctl status $SERVICE_NAME"
|
|
echo ""
|
|
echo "View logs:"
|
|
echo " sudo journalctl -u $SERVICE_NAME -f"
|
|
echo ""
|
|
echo "Access: http://$(hostname -I | awk '{print $1}'):8000"
|
|
|
|
else
|
|
# User install - create a simple start script
|
|
cat > "$INSTALL_DIR/start.sh" << 'EOF'
|
|
#!/bin/bash
|
|
cd "$(dirname "$0")"
|
|
export DATA_DIR="./data"
|
|
export PYTHONUNBUFFERED=1
|
|
echo "Starting IPMI Controller..."
|
|
echo "Data directory: $DATA_DIR"
|
|
python3 web_server.py
|
|
EOF
|
|
chmod +x "$INSTALL_DIR/start.sh"
|
|
|
|
echo ""
|
|
echo "✅ User installation complete!"
|
|
echo ""
|
|
echo "Start manually:"
|
|
echo " cd $INSTALL_DIR && ./start.sh"
|
|
echo ""
|
|
echo "Or create a systemd service manually:"
|
|
echo " nano ~/.config/systemd/user/ipmi-controller.service"
|
|
echo ""
|
|
echo "Access: http://localhost:8000"
|
|
fi
|
|
|
|
echo ""
|
|
echo "📁 Your settings are stored in: $DATA_DIR"
|
|
echo " - config.json: All configuration"
|
|
echo " - users.json: User accounts"
|
|
echo ""
|
|
echo "💾 These files persist across restarts and updates!"
|