#!/system/bin/sh
#
#	Manually set the cpu governor for the current session
#
#	This file is part of the OrangeFox Recovery Project
# 	Copyright (C) 2026 The OrangeFox Recovery Project
#
#	OrangeFox is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	any later version.
#
#	OrangeFox is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
# 	This software is released under GPL version 3 or any later version.
#	See <http://www.gnu.org/licenses/>.
#
# 	Please maintain this if you use this script or any part of it
#

gov="$1";
governors=$(cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors");

syntax() {
	echo "Syntax = $0 <governor>";
	echo "Available governors: $governors";
	exit 1;
}

if [ -z "$gov" ]; then
	syntax;
fi

if echo "$governors" | grep -qw "$gov"; then
	echo "Setting cpu governor to $gov";
else
	syntax;
fi

for i in 0 1 2 3 4 5 6 7; do
	F="/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor";
	if [ -e $F ]; then
		echo $gov > $F;
	fi
done
#
