-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·76 lines (63 loc) · 2.37 KB
/
install.sh
File metadata and controls
executable file
·76 lines (63 loc) · 2.37 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
#!/bin/bash
#
# IPMI Fan Control Service Installer
# ----------------------------------
# This script installs the fan control script and systemd service.
# It is designed to be run from a cloned Git repository.
set -e
# --- Configuration ---
SCRIPT_NAME="fan_control.py"
SERVICE_NAME="ipmi-fan-control.service"
CONFIG_TEMPLATE="config.ini.example"
# Destination Paths
INSTALL_DIR="/usr/local/sbin"
SERVICE_DIR="/etc/systemd/system"
CONFIG_DIR="/etc/ipmi-fan-control"
# Full paths for destination files
SCRIPT_DEST="${INSTALL_DIR}/${SCRIPT_NAME}"
SERVICE_DEST="${SERVICE_DIR}/${SERVICE_NAME}"
CONFIG_DEST="${CONFIG_DIR}/config.ini"
# --- Sanity Checks ---
if [ "$EUID" -ne 0 ]; then
echo "ERROR: Please run this script as root or with sudo."
exit 1
fi
if [ ! -f "$SCRIPT_NAME" ] || [ ! -f "$SERVICE_NAME" ] || [ ! -f "$CONFIG_TEMPLATE" ]; then
echo "ERROR: Missing required files. Please run this script from the root of the Git repository."
exit 1
fi
echo "--- Installing/Updating IPMI Fan Control Service ---"
# --- Install Script and Service ---
echo "Copying script to $SCRIPT_DEST..."
cp "$SCRIPT_NAME" "$SCRIPT_DEST"
chmod 755 "$SCRIPT_DEST"
echo "Copying systemd service file to $SERVICE_DEST..."
cp "$SERVICE_NAME" "$SERVICE_DEST"
# --- Handle Configuration File ---
# Create the configuration directory if it doesn't exist.
if [ ! -d "$CONFIG_DIR" ]; then
echo "Creating configuration directory: $CONFIG_DIR"
mkdir -p "$CONFIG_DIR"
fi
# Only create the config file from the template if it doesn't already exist.
# This preserves user settings during updates.
if [ ! -f "$CONFIG_DEST" ]; then
echo "No existing configuration found. Creating new config from template..."
cp "$CONFIG_TEMPLATE" "$CONFIG_DEST"
echo "IMPORTANT: Please edit your new configuration file at $CONFIG_DEST"
else
echo "Existing configuration at $CONFIG_DEST found. Skipping creation."
fi
# --- Finalize ---
echo "Reloading systemd daemon to recognize changes..."
systemctl daemon-reload
echo ""
echo "--- Installation/Update Complete ---"
echo ""
echo "To finish setup (if this is a first-time install):"
echo "1. Edit the configuration: sudo nano $CONFIG_DEST"
echo "2. Enable the service to start on boot: sudo systemctl enable $SERVICE_NAME"
echo "3. Start the service now: sudo systemctl start $SERVICE_NAME"
echo ""
echo "To check status, run: sudo systemctl status $SERVICE_NAME"
echo ""