linutil/core/tabs/utils/power-profile.sh

102 lines
3.2 KiB
Bash
Raw Normal View History

2024-09-18 15:15:29 +01:00
#!/bin/sh -e
. ../common-script.sh
installAutoCpufreq() {
clear
printf "%b\n" "${YELLOW}Checking if auto-cpufreq is already installed...${RC}"
# Check if auto-cpufreq is already installed
if command_exists auto-cpufreq; then
printf "%b\n" "${GREEN}auto-cpufreq is already installed.${RC}"
else
printf "%b\n" "${YELLOW}Installing auto-cpufreq...${RC}"
# Install git if not already installed
if ! command_exists git; then
printf "%b\n" "${YELLOW}git not found. Installing git...${RC}"
2024-09-19 19:05:36 +01:00
case "$PACKAGER" in
2024-09-18 15:15:29 +01:00
pacman)
2024-09-19 19:05:36 +01:00
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm git
2024-09-18 15:15:29 +01:00
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add git
;;
2024-09-18 15:15:29 +01:00
*)
2024-09-19 19:05:36 +01:00
"$ESCALATION_TOOL" "$PACKAGER" install -y git
2024-09-18 15:15:29 +01:00
;;
esac
fi
# Clone the auto-cpufreq repository and run the installer
if [ ! -d "auto-cpufreq" ]; then
printf "%b\n" "${YELLOW}Cloning auto-cpufreq repository...${RC}"
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
fi
cd auto-cpufreq
printf "%b\n" "${YELLOW}Running auto-cpufreq installer...${RC}"
"$ESCALATION_TOOL" ./auto-cpufreq-installer
2024-09-28 20:11:29 +01:00
"$ESCALATION_TOOL" auto-cpufreq --install
2024-09-18 15:15:29 +01:00
cd ..
fi
}
configureAutoCpufreq() {
printf "%b\n" "${YELLOW}Configuring auto-cpufreq...${RC}"
if command_exists auto-cpufreq; then
# Check if the system has a battery to determine if it's a laptop
if [ -d /sys/class/power_supply/BAT0 ]; then
printf "%b\n" "${GREEN}System detected as laptop. Updating auto-cpufreq for laptop...${RC}"
2024-09-19 19:05:36 +01:00
"$ESCALATION_TOOL" auto-cpufreq --force powersave
2024-09-18 15:15:29 +01:00
else
printf "%b\n" "${GREEN}System detected as desktop. Updating auto-cpufreq for desktop...${RC}"
2024-09-19 19:05:36 +01:00
"$ESCALATION_TOOL" auto-cpufreq --force performance
2024-09-18 15:15:29 +01:00
fi
else
printf "%b\n" "${RED}auto-cpufreq is not installed, skipping configuration.${RC}"
fi
}
removeAutoCpufreqTweak() {
printf "%b\n" "${YELLOW}Removing auto-cpufreq tweak...${RC}"
if command_exists auto-cpufreq; then
printf "%b\n" "${YELLOW}Resetting auto-cpufreq configuration...${RC}"
2024-09-19 19:05:36 +01:00
"$ESCALATION_TOOL" auto-cpufreq --force reset
2024-09-18 15:15:29 +01:00
else
printf "%b\n" "${RED}auto-cpufreq is not installed, skipping removal.${RC}"
fi
}
apply_or_remove_auto_cpufreq() {
# Prompt user for action
printf "%b\n" "${YELLOW}Do you want to apply the auto-cpufreq tweak or remove it?${RC}"
printf "%b\n" "${YELLOW}1) Apply tweak${RC}"
printf "%b\n" "${YELLOW}2) Remove tweak${RC}"
2024-09-18 18:53:47 +01:00
printf "%b" "Enter your choice [1/2]: "
read -r choice
2024-09-18 15:15:29 +01:00
case $choice in
1)
configureAutoCpufreq
;;
2)
removeAutoCpufreqTweak
;;
*)
printf "%b\n" "${RED}Invalid choice. Exiting.${RC}"
exit 1
;;
esac
printf "%b\n" "${GREEN}auto-cpufreq setup complete.${RC}"
}
checkEnv
checkEscalationTool
installAutoCpufreq
2024-09-28 20:11:29 +01:00
apply_or_remove_auto_cpufreq