148 lines
3.8 KiB
Bash
Executable File
148 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Setup script for IPMI Fan Controller v2
|
|
|
|
set -e
|
|
|
|
echo "🌬️ IPMI Fan Controller v2 - Setup"
|
|
echo "=================================="
|
|
|
|
# Check if running as root for system-wide install
|
|
if [ "$EUID" -eq 0 ]; then
|
|
INSTALL_SYSTEM=true
|
|
INSTALL_DIR="/opt/ipmi-fan-controller"
|
|
CONFIG_DIR="/etc/ipmi-fan-controller"
|
|
else
|
|
INSTALL_SYSTEM=false
|
|
INSTALL_DIR="$HOME/.local/ipmi-fan-controller"
|
|
CONFIG_DIR="$HOME/.config/ipmi-fan-controller"
|
|
echo "⚠️ Running as user - installing to $INSTALL_DIR"
|
|
echo " (Run with sudo for system-wide install)"
|
|
echo ""
|
|
fi
|
|
|
|
# Check dependencies
|
|
echo "📦 Checking dependencies..."
|
|
|
|
if ! command -v python3 &> /dev/null; then
|
|
echo "❌ Python 3 is required but not installed"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v ipmitool &> /dev/null; then
|
|
echo "⚠️ ipmitool not found. Installing..."
|
|
if [ "$INSTALL_SYSTEM" = true ]; then
|
|
apt-get update && apt-get install -y ipmitool
|
|
else
|
|
echo "❌ Please install ipmitool: sudo apt-get install ipmitool"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "✓ Python 3: $(python3 --version)"
|
|
echo "✓ ipmitool: $(ipmitool -V)"
|
|
|
|
# Create directories
|
|
echo ""
|
|
echo "📁 Creating directories..."
|
|
mkdir -p "$INSTALL_DIR"
|
|
mkdir -p "$CONFIG_DIR"
|
|
mkdir -p "$INSTALL_DIR/logs"
|
|
|
|
# Copy files
|
|
echo ""
|
|
echo "📋 Installing files..."
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cp "$SCRIPT_DIR/fan_controller.py" "$INSTALL_DIR/"
|
|
cp "$SCRIPT_DIR/web_server.py" "$INSTALL_DIR/"
|
|
cp "$SCRIPT_DIR/requirements.txt" "$INSTALL_DIR/"
|
|
|
|
# Install Python dependencies
|
|
echo ""
|
|
echo "🐍 Installing Python dependencies..."
|
|
python3 -m pip install -q -r "$INSTALL_DIR/requirements.txt"
|
|
|
|
# Create default config if not exists
|
|
if [ ! -f "$CONFIG_DIR/config.json" ]; then
|
|
echo ""
|
|
echo "⚙️ Creating default configuration..."
|
|
cat > "$CONFIG_DIR/config.json" << 'EOF'
|
|
{
|
|
"host": "",
|
|
"username": "root",
|
|
"password": "",
|
|
"port": 623,
|
|
"enabled": false,
|
|
"interval": 10,
|
|
"min_speed": 10,
|
|
"max_speed": 100,
|
|
"fan_curve": [
|
|
{"temp": 30, "speed": 15},
|
|
{"temp": 40, "speed": 25},
|
|
{"temp": 50, "speed": 40},
|
|
{"temp": 60, "speed": 60},
|
|
{"temp": 70, "speed": 80},
|
|
{"temp": 80, "speed": 100}
|
|
],
|
|
"panic_temp": 85,
|
|
"panic_speed": 100
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
# Create systemd service (system-wide only)
|
|
if [ "$INSTALL_SYSTEM" = true ]; then
|
|
echo ""
|
|
echo "🔧 Creating systemd service..."
|
|
cat > /etc/systemd/system/ipmi-fan-controller.service << EOF
|
|
[Unit]
|
|
Description=IPMI Fan Controller v2
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
WorkingDirectory=$INSTALL_DIR
|
|
Environment="CONFIG_PATH=$CONFIG_DIR/config.json"
|
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/web_server.py
|
|
ExecStop=/usr/bin/python3 -c "import requests; requests.post('http://localhost:8000/api/shutdown')"
|
|
Restart=on-failure
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable ipmi-fan-controller.service
|
|
|
|
echo ""
|
|
echo "✅ Installation complete!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Edit config: sudo nano $CONFIG_DIR/config.json"
|
|
echo " 2. Start service: sudo systemctl start ipmi-fan-controller"
|
|
echo " 3. View status: sudo systemctl status ipmi-fan-controller"
|
|
echo " 4. Open web UI: http://$(hostname -I | awk '{print $1}'):8000"
|
|
echo ""
|
|
echo "Or test from CLI:"
|
|
echo " python3 $INSTALL_DIR/fan_controller.py <host> <user> <pass>"
|
|
|
|
else
|
|
|
|
echo ""
|
|
echo "✅ User installation complete!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Edit config: nano $CONFIG_DIR/config.json"
|
|
echo " 2. Start manually:"
|
|
echo " CONFIG_PATH=$CONFIG_DIR/config.json python3 $INSTALL_DIR/web_server.py"
|
|
echo " 3. Open web UI: http://localhost:8000"
|
|
echo ""
|
|
echo "Or test from CLI:"
|
|
echo " python3 $INSTALL_DIR/fan_controller.py <host> <user> <pass>"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
echo "📖 Configuration file: $CONFIG_DIR/config.json"
|