36 lines
1.2 KiB
Bash
Executable File
36 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
check_usb_port() {
|
|
usb_path=$(udevadm info --query=path --name="$device")
|
|
# Check the bus this USB device is on
|
|
bus_num=$(echo "$usb_path" | grep -o 'usb[0-9]*' | grep -o '[0-9]*' | head -n1)
|
|
# Read the speed from sysfs
|
|
speed_file="/sys/bus/usb/devices/usb${bus_num}/speed"
|
|
if [[ -f "$speed_file" ]]; then
|
|
speed=$(cat "$speed_file")
|
|
if [[ $speed -lt 1000 ]]; then
|
|
spd-say -Cw "Warning. USB 2.0 detected. Please power off the system and move the USB drive to a USB 3 port for better performance."
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
# set performance (if scaling governor exists)
|
|
if [[ -d /sys/devices/system/cpu/cpu0/cpufreq ]]; then
|
|
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 2>/dev/null || true
|
|
fi
|
|
|
|
# Find the USB bus speed for the boot drive
|
|
device=$(findmnt / -o SOURCE -n | sed 's/[0-9]*$//')
|
|
if [[ "$device" == /dev/sd* ]]; then
|
|
check_usb_port
|
|
fi
|
|
|
|
# File system trim
|
|
rootPartition=$(findmnt / -o SOURCE -n)
|
|
if [[ $(lsblk -b --discard $rootPartition | awk 'NR==2 { print $NF }') -gt 0 ]]; then
|
|
if ! systemctl is-enabled fstrim.timer ; then
|
|
sudo systemctl enable fstrim.timer
|
|
fi
|
|
fi
|