Created
December 20, 2024 17:51
-
-
Save adde88/52714c98e66f00fc26c5ee1431538de5 to your computer and use it in GitHub Desktop.
Corsair AIO Manager - Bash Script | Requires: liquidctl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Systemd service file. | |
# Save to: /etc/systemd/system/ | |
# Then: 'sudo systemctl enable corsair-quiet.service' | |
# Delete these four commented lines before saving this file | |
[Unit] | |
Description=Corsair AIO Manager | |
After=multi-user.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/corsair-quiet.sh --static | |
RemainAfterExit=yes | |
# Explicitly run as root | |
User=root | |
Group=root | |
# Add security hardening options | |
ProtectSystem=strict | |
ProtectHome=true | |
PrivateTmp=true | |
NoNewPrivileges=true | |
# Restrict hardware access to only what's needed | |
PrivateDevices=true | |
DeviceAllow=/dev/hidraw* | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Made by: Andreas Nilsen <adde88@gmail> @adde88 © Friday 20. December 2024 | |
# Script to set Corsair H100i Platinum fan speed to dynamic or static mode | |
# Can be run as root or with sudo privileges only | |
# | |
# Dependencies: liquidctl has to be workingly installed and/or exist in the PATH directories | |
# Recommended to be used in conjunction with a systemd service file, to automatically set fan speed on boot | |
# Check whether the Corsair AIO is connected, and which model it is | |
get_corsair_aios() { | |
# Define an array of known Corsair AIO models | |
declare -A corsair_models=( | |
["0c18"]="Corsair H100i Platinum" | |
["0c17"]="Corsair H115i Pro" | |
# Add more models as needed | |
) | |
# Get the product ID from lsusb | |
local device_info | |
device_info=$(lsusb | grep -i "1b1c:" | head -n1) | |
local product_id | |
product_id=$(echo "$device_info" | grep -o "1b1c:\([0-9a-f]\{4\}\)" | cut -d: -f2) | |
if [ -n "$product_id" ] && [ -n "${corsair_models[$product_id]}" ]; then | |
echo "${corsair_models[$product_id]}" | |
else | |
echo "No compatible Corsair AIO's detected" | |
fi | |
} | |
# Function to extract numbers from string | |
get_number() { | |
echo -e "$1" | grep -o '[0-9]\+\([.][0-9]\+\)*' | |
} | |
# Function to display help menu | |
display_help() { | |
echo -e "Corsair AIO Manager:" | |
echo -e "This script helps the user set the fan and pump speeds of some of Corsair's AIO water coolers, to either dynamic (default), or static mode (20% fan speed + 70% pump speed.)" | |
echo -e "It HAS to be run as either root OR with sudo privileges." | |
echo -e "" | |
echo -e "Usage: corsair-quiet.sh [OPTION] [INTEGER]\n" | |
echo -e "Options:" | |
echo -e " --dynamic, -d Sets both fan and pump to dynamic mode. (Default)" | |
echo -e " --static, -s Sets fan speed to static mode. (20% fan speed + 70% pump speed.)" | |
echo -e " --help, -h Displays this help menu" | |
return 1 | |
} | |
# Check if the script is run as root | |
if [[ $EUID -ne 0 ]]; then | |
echo -e "This script must be run as root or with sudo privileges." | |
logger "[Corsair AIO Manager]: Script execution failed: Not running as root" | |
exit 2 | |
fi | |
# Default to --dynamic if no arguments are provided | |
if [[ -z "$1" ]]; then | |
set -- "--dynamic" | |
fi | |
# Display help menu if -h or --help is provided | |
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | |
display_help | |
exit 1 | |
fi | |
# Get AIO model for logging | |
AIO_MODEL=$(get_corsair_aios) | |
# Initialize liquidctl | |
echo -e "Initializing 'liquidctl' for: '$AIO_MODEL'" | |
logger "[Corsair AIO Manager]: Initializing 'liquidctl' for: '$AIO_MODEL'" | |
/usr/local/bin/liquidctl --device 1 initialize > /dev/null 2>&1 | |
# Handle arguments | |
case "$1" in | |
--dynamic|-d) | |
echo -e "Setting fan and pump speeds to dynamic mode, with optimized curves..." | |
# Set fan curve (optimized for silence and performance) | |
/usr/local/bin/liquidctl --device 1 set fan speed 20 20 30 40 35 60 40 75 45 90 50 100 > /dev/null 2>&1 | |
# Set pump curve (optimized for flow and acoustics) | |
/usr/local/bin/liquidctl --device 1 set pump speed 20 60 30 70 35 80 40 90 45 100 > /dev/null 2>&1 | |
# Log the action | |
logger "[Corsair AIO Manager]: Fan and pump speeds set to dynamic mode, with optimized curves" | |
;; | |
--static|-s) | |
echo -e "Setting fan and pump to static mode (20% fan speed + 70% pump speed)..." | |
# Set fans to a quiet 20% speed | |
/usr/local/bin/liquidctl --device 1 set fan speed 20 > /dev/null 2>&1 | |
# Set pump to constant 70% for adequate flow without hot-spots | |
/usr/local/bin/liquidctl --device 1 set pump speed 70 > /dev/null 2>&1 | |
# Log the action | |
logger "[Corsair AIO Manager]: Fan set to static 20% speed, pump set to static 70% speed" | |
;; | |
*) | |
echo -e "Invalid option: $1" | |
logger "[Corsair AIO Manager]: Invalid option: $1" | |
# Display help menu | |
display_help | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment