Skip to content

Instantly share code, notes, and snippets.

@salaros
Last active January 19, 2020 19:40
Show Gist options
  • Save salaros/72fa25ef7e1695bfc3a91829a3c4a811 to your computer and use it in GitHub Desktop.
Save salaros/72fa25ef7e1695bfc3a91829a3c4a811 to your computer and use it in GitHub Desktop.
My tweaks for Ubuntu + Dell Inspiron 5567
#!/usr/bin/env bash
# Require root to run
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 0
fi
# [PlayOnLinux] - disables protection against the usage of Ptrace
# https://www.playonlinux.com/en/topic-10534-Regarding_ptrace_scope_fatal_error.html
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
sudo sed -e 's/kernel.yama.ptrace_scope = .*/kernel.yama.ptrace_scope = 0/g' \
-i /etc/sysctl.d/10-ptrace.conf
# Tunes Intel Skylake, Kabylake and beyond Integrated Graphics for performance and reliability
# https://gist.github.com/Brainiarc7/aa43570f512906e882ad6cdd835efe57
# -------------------------------------------------------------------
# modeset: Use kernel modesetting [KMS] (0=disable, 1=on, -1=force vga console preference [default]) (int)
# enable_dc: Enable power-saving display C-states. (-1=auto [default]; 0=disable; 1=up to DC5; 2=up to DC6) (int)
# enable_fbc: Enable frame buffer compression for power savings (default: -1 (use per-chip default)) (int)
# enable_psr: Enable PSR (0=disabled, 1=enabled - link mode chosen per-platform, 2=force link-standby mode, 3=force link-off mode) Default: -1 (use per-chip default) (int)
# enable_guc: Enable GuC load for GuC submission and/or HuC load. Required functionality can be selected using bitmask values. (-1=auto, 0=disable [default], 1=GuC submission, 2=HuC load) (int)
# disable_power_well: Disable display power wells when possible (-1=auto [default], 0=power wells always on, 1=power wells disabled when possible) (int)
# -------------------------------------------------------------------
echo "options i915 modeset=1 enable_dc=1 enable_fbc=0 enable_psr=1 enable_guc=3 disable_power_well=0 alpha_support=1" | \
sudo tee /etc/modprobe.d/i915.conf
# Fix font and screen corruption in GTK+ applications (missing glyphs after suspend/resume)
[[ -z $(grep COGL_ATLAS_DEFAULT_BLIT_MODE /etc/environment) ]] && \
echo -e "\nCOGL_ATLAS_DEFAULT_BLIT_MODE=framebuffer" | sudo tee -a /etc/environment
# Inject some kernel options via grub config
# intel_pstate: Enable Intel's Hardware P-States, known commonly by the marketing moniker "SpeedShift"
# pci=noaer: Disable the use of PCIE advanced error reporting
# pci=nomsi: Disable the use of MSI interrupts system-wide
sudo sed 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=nomsi,noaer intel_pstate=skylake_hwp"/g' \
-i /etc/default/grub
# Blacklist Red Dragon keyboard, conflicting with my Defender keyboard
echo "blacklist hid_redragon" | \
sudo tee /etc/modprobe.d/blacklist-hid_redragon.conf
# Enable weekly SSD trimming for drives that support it
[[ ! -f /etc/cron.weekly/fstrim ]]
echo -e "#!/bin/sh \n# trim all mounted file systems which support it \n/sbin/fstrim --all || true" | \
sudo tee /etc/cron.weekly/fstrim && \
sudo chmod +x /etc/cron.weekly/fstrim
# Add `noatime` to SSD root partition
sudo sed "$(grep -n -e "^UUID.*\s/\s" /etc/fstab | cut -f1 -d:)s| errors| noatime,errors|g" -i /etc/fstab
# Disable swap file on SSD
sudo sed -e 's/^\/swapfile/#\/swapfile/g' -i /etc/fstab
# Make Grub remember last used item
sudo sed s/GRUB_DEFAULT=.*$/GRUB_DEFAULT=saved/g -i /etc/default/grub
[[ -z $(grep GRUB_SAVEDEFAULT /etc/default/grub) ]] && \
sudo sed -e "s/GRUB_DEFAULT/GRUB_SAVEDEFAULT=true\nGRUB_DEFAULT/g" -i /etc/default/grub
# Reduce Grub's timeout to 5s
sudo sed s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=5/g -i /etc/default/grub
# Tweak Intel HD 620 and AMD Radeon R7 M445 (Xorg)
[[ ! -f /usr/share/X11/xorg.conf.d/20-intel.conf ]] && echo "
Section \"Module\"
Load \"dri2\"
Load \"glamoregl\"
EndSection
Section \"OutputClass\"
Identifier \"Intel Graphics\"
# MatchDriver \"intel\"
# Driver \"intel\"
MatchDriver \"modesetting\"
Driver \"modesetting\"
EndSection
Section \"Device\"
Identifier \"Intel Graphics\"
# Driver \"intel\"
Driver \"modesetting\"
BusID \"PCI:0:2:0\"
VendorName \"Intel\"
BoardName \"HD Graphics 620\"
Option \"AccelMethod\" \"glamor\"
Option \"SwapbuffersWait\" \"false\"
Option \"TearFree\" \"true\"
Option \"TripleBuffer\" \"1\"
Option \"Backlight\" \"intel_backlight\"
Option \"DRI\" \"3\"
EndSection
" | sudo tee /usr/share/X11/xorg.conf.d/20-intel.conf
[[ ! -f /usr/share/X11/xorg.conf.d/21-amdgpu.conf ]] && echo "
Section \"Device\"
Identifier \"Radeon R7 M445\"
Driver \"amdgpu\"
BusID \"PCI:1:0:0\"
VendorName \"AMD\"
BoardName \"Radeon R7 M445\"
Option \"AccelMethod\" \"glamor\"
Option \"TearFree\" \"true\"
Option \"DRI\" \"3\"
EndSection
" | sudo tee /usr/share/X11/xorg.conf.d/21-amdgpu.conf
# Disable .NET Core CLI telemetry
[[ -z $(grep DOTNET_CLI_TELEMETRY_OPTOUT /etc/environment) ]] && \
echo -e "\nDOTNET_CLI_TELEMETRY_OPTOUT=1" | sudo tee -a /etc/environment
# Enable Advanced Power Management (TLP) if not enabled
sudo sed -e s/TLP_ENABLE=.*$/TLP_ENABLE=1/g -i /etc/default/tlp
# Enable `performance` CPU scaling mode on AC and `powersave` on battery
sudo sed -e s/\#CPU_SCALING_GOVERNOR_ON_AC=.*$/CPU_SCALING_GOVERNOR_ON_AC=performance/g -i /etc/default/tlp
sudo sed -e s/\#CPU_SCALING_GOVERNOR_ON_BAT=.*$/CPU_SCALING_GOVERNOR_ON_BAT=powersave/g -i /etc/default/tlp
# Enable Intel Turbo Boost on AC and disable on battery power
sudo sed -e s/\#CPU_BOOST_ON_AC=.*$/CPU_BOOST_ON_AC=1/g -i /etc/default/tlp
sudo sed -e s/\#CPU_BOOST_ON_BAT=.*$/CPU_BOOST_ON_BAT=0/g -i /etc/default/tlp
# Turn off bluetooth and turn on Wi-Fi on startup
sudo sed -e s/\#DEVICES_TO_DISABLE_ON_STARTUP=.*$/DEVICES_TO_DISABLE_ON_STARTUP=\"bluetooth\"/g -i /etc/default/tlp
sudo sed -e s/\#DEVICES_TO_ENABLE_ON_STARTUP=.*$/DEVICES_TO_ENABLE_ON_STARTUP=\"wifi\"/g -i /etc/default/tlp
# Exclude listed devices from USB autosuspend
# -------------------------------------------------------------------
# 1a40:0101 Terminus Technology Inc. 4-Port HUB
# 046d:c526 Logitech, Inc. Nano Receiver
# 046d:c077 Logitech USB Optical Mouse
# 0c45:760b Defender Keyboard
# -------------------------------------------------------------------
sudo sed -e 's/\#USB_BLACKLIST=.*$/USB_BLACKLIST=\"1a40:0101 046d:c526 046d:c077 0c45:760b\"/g' -i /etc/default/tlp
# ----------------- #
# /etc/rc.local #
# ----------------- #
# Create /etc/rc.local script if needed
[[ ! -f /etc/rc.local ]] && echo -e '#!/bin/sh -e\n' | sudo tee /etc/rc.local && sudo chmod +x -v /etc/rc.local
sudo sed -e "s/exit 0$//g" -i /etc/rc.local
# Apply PowerTop turing upon system startup
[[ -z $(grep "powertop --auto-tune" /etc/rc.local) ]] && \
echo -e "# Apply PowerTop tuning \npowertop --auto-tune \necho '1500' | sudo tee '/proc/sys/vm/dirty_writeback_centisecs'" | \
sudo tee -a /etc/rc.local
# Re-apply USB rules overridden by PowerTop above
[[ -z $(grep "tlp usb" /etc/rc.local) ]] && \
echo -e "# Re-apply USB rules overridden by PowerTop above\ntlp usb" | \
sudo tee -a /etc/rc.local
# Re-append `exit 0` line at the end of the script
[[ -z $(grep "exit 0" /etc/rc.local) ]] && echo -e "\nexit 0" | sudo tee -a /etc/rc.local
# Restart TLP and apply rc.local
sudo /etc/init.d/tlp restart
sudo /etc/rc.local
# Clicks on Gnome Dash will minimize / maximize the window
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'
# Enforce en_US.UTF8 culture
[[ -z $(grep LANGUAGE /etc/environment) ]] && echo -e "\nLANGUAGE=\"en_US:en\"" | sudo tee -a /etc/environment
[[ -z $(grep LC_ALL /etc/environment) ]] && echo "LC_ALL=\"en_DK.UTF-8\"" | sudo tee -a /etc/environment
echo "en_DK.UTF-8 UTF-8
en_US.UTF-8 UTF-8
en_GB.UTF-8 UTF-8" | sudo tee /var/lib/locales/supported.d/en
sudo locale-gen --purge ru_RU.UTF-8 be_BY.UTF-8 en_US.UTF-8 en_DK.UTF-8
sudo update-locale --no-checks
sudo update-desktop-database -q
sudo update-initramfs -cu
sudo update-grub
# Install WakaTime for Bash, some dotfiles and Bash tweaks
[[ ! -d $HOME/.bash-wakatime ]] && git clone https://github.com/gjsheep/bash-wakatime.git $HOME/.bash-wakatime
[[ ! -x "$(command -v wakatime)" ]] && pip3 install wakatime
[[ ! -d $HOME/.dotfiles ]] && git clone https://github.com/salaros/dotfiles.git $HOME/.dotfiles && cd $HOME/.dotfiles && bash ./install.sh
cd $HOME
sudo usermod -a -G sudo,disk,video,scanner,saned,docker $([[ ! -z $SUDO_USER ]] && echo $SUDO_USER || echo $USER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment