Created
March 22, 2019 08:02
-
-
Save oddbjornkvalsund/67e8e9b7a4dbcecd2cbe15e0cdd16ffb to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -x | |
set -e | |
# Function to add line to file if not already present | |
function add_line() { | |
local line=$1 | |
local file=$2 | |
touch $file | |
grep -q "$line" "$file" || echo -e "$line" >> "$file" | |
} | |
# Install minimal set of tools | |
apt -y install \ | |
i7z \ | |
powertop \ | |
i8kutils \ | |
htop \ | |
iotop \ | |
lm-sensors \ | |
cpufrequtils \ | |
git \ | |
vim \ | |
pcregrep \ | |
curl \ | |
postgresql \ | |
gnome-tweaks | |
# Enable sensor modules | |
add_line "coretemp" /etc/modules | |
add_line "dell-smm-hwmon" /etc/modules | |
echo options dell-smm-hwmon restricted=0 force=1 ignore_dmi=1 > /etc/modprobe.d/dell-smm-hwmon.conf | |
# Enable undervolting | |
test -d /root/undervolt || git clone https://github.com/georgewhewell/undervolt.git /root/undervolt | |
add_line "* * * * * /root/undervolt/undervolt.py --core -100 --cache -100" /var/spool/cron/crontabs/root | |
# Enable performance scheduling governor | |
add_line "* * * * * cpufreq-set -g powersave" /var/spool/cron/crontabs/root | |
# Try to avoid audio skipping/crackling | |
add_line "options snd-hda-intel position_fix=1" /etc/modprobe.d/alsa-base.conf | |
# Create powerkeepalive script | |
cat > /usr/local/bin/powerkeepalive << EOF | |
#!/bin/bash | |
for usbdevice in \$(find /sys/bus/usb/devices/); do test -w \${usbdevice}/power/control && echo on > \${usbdevice}/power/control; true; done | |
echo 0 > /sys/module/snd_hda_intel/parameters/power_save | |
EOF | |
chmod +x /usr/local/bin/powerkeepalive | |
# Powertop auto-tune | |
test -f /etc/systemd/system/powertop-autotune.service || cat >> /etc/systemd/system/powertop-autotune.service << EOF | |
[Unit] | |
Description=Auto-tune power savings (oneshot) | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/sbin/powertop --auto-tune | |
ExecStartPost=/usr/local/bin/powerkeepalive | |
RemainAfterExit=true | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
# Enable and run the powertop script | |
systemctl enable powertop-autotune | |
systemctl start powertop-autotune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment