Created
February 10, 2022 06:25
-
-
Save RenatoExpert/a6c0e37c5f290e7ff323b2a7f9bca7f4 to your computer and use it in GitHub Desktop.
An utilitary for setting up ACPI Mutex
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 | |
# autor: renatoexpert | |
# renatorraraujo@gmail.com | |
# to: ja koolit | |
# Logging stuff | |
LOGFILE='bash.log' | |
tee $LOGFILE < $PIPEFILE & | |
TEEPID=$! | |
exec > $PIPEFILE 2>&1 | |
echo 'Welcome Ja Koolit' | |
# ------------------------------------------- | |
# step 1 : getting board vendor and name info | |
# ------------------------------------------- | |
binfo_dir='/sys/class/dmi/id/' # where to get info we need | |
vendorstr=$binfo_dir'board_vendor' | |
namestr=$binfo_dir'board_name' | |
source_file='asus-ec-sensors.c' | |
echo 'Looking for board vendor at '$vendorstr | |
vendor_res=$(cat vendorstr) | |
echo 'Result: '$vendor_res | |
echo 'Looking for board name at '$namestr | |
name_res=$(cat $namestr) | |
echo 'Result: '$name_res | |
if [ $1='test' ]; then | |
echo "Runing as test..." | |
vendor_res="test-vendor" | |
name_res="test-name" | |
fi | |
# ------------------------------------------- | |
# step 2 : defining sensors | |
# ------------------------------------------- | |
possible_sensors=("SENSOR_SET_TEMP_CHIPSET_CPU_MB" "SENSOR_TEMP_VRM" "SENSOR_TEMP_T_SENSOR" "SENSOR_FAN_CHIPSET" "SENSOR_CURR_CPU" "SENSOR_IN_CPU_CORE" "SENSOR_SET_TEMP_WATER" "SENSOR_FAN_CPU_OPT" "SENSOR_FAN_WATER_FLOW") | |
desired_sensors=() | |
add_sensor() { | |
echo -e "Adding "$1" on config\n"; | |
desired_sensors+=($1); | |
} | |
ask_sensor () { | |
while true; do | |
read -p "Does it have "$1"?(y/n)[n]" yn | |
case $yn in | |
[Yy]* ) | |
add_sensor $1 | |
break | |
;; | |
"" | [Nn]* ) | |
echo -e "Skipping\n" | |
break | |
;; | |
* ) | |
echo "Please answer only with y/n" | |
;; | |
esac | |
done | |
} | |
setup_sensors () { | |
for i in ${!possible_sensors[@]}; do | |
ask_sensor ${possible_sensors[$i]} | |
echo "Choosed sensors: "${desired_sensors[@]} | |
done | |
} | |
echo 'Sensors configuration' | |
setup_sensors | |
# ------------------------------------------- | |
# step 3 : backing up | |
# ------------------------------------------- | |
echo -n "Backing up original source... " | |
source_name="asus-ec-sensors.c" | |
backup_name=$source_name".bkp" | |
cp $source_name $backup_name | |
echo "Done!" | |
# ------------------------------------------- | |
# step 4 : confirmation | |
# ------------------------------------------- | |
printf "\n\tCheck current configuration\n" | |
echo "Target file: "$source_name | |
echo "Vendor: "$vendor_res | |
echo "Model: "$name_res | |
echo "Sensors: " | |
for i in ${!desired_sensors[@]}; do | |
echo -e "\t${desired_sensors[$i]}" | |
done | |
read -p "Write on source code? Say 'yes' or operation will be aborted: " confirm | |
if [ $confirm != "yes" ] | |
then | |
exit | |
fi | |
# ------------------------------------------- | |
# step 5 : change into source | |
# ------------------------------------------- | |
# reference example i got from source code | |
# DMI_EXACT_MATCH_BOARD(VENDOR_ASUS_UPPER_CASE, "ROG STRIX X570-E GAMING", SENSOR_SET_TEMP_CHIPSET_CPU_MB | SENSOR_TEMP_T_SENSOR | SENSOR_TEMP_VRM | SENSOR_FAN_CHIPSET | SENSOR_CURR_CPU | SENSOR_IN_CPU_CORE), | |
echo "Generating code..." | |
sensors_definitive=$(echo -n ${desired_sensors[@]} | sed 's/ / | /g') | |
complete_name=$(echo -n "$vendor_res $name_res") | |
trix_code=$(printf "DMI_EXACT_MATCH_BOARD(VENDOR_ASUS_UPPER_CASE, \"$complete_name\", $sensors_definitive),") | |
echo $trix_code | |
echo "Writing on source..." | |
tracker='DMI_EXACT_MATCH_BOARD(VENDOR' | |
sum=$(echo -n $trix_code $tracker) | |
sed -i "0,/$tracker/{s/$tracker/$sum/}" $source_file | |
echo "Wrote!" | |
# ------------------------------------------- | |
# step 6 : compiling | |
# ------------------------------------------- | |
make | |
echo "Everything done!" | |
exec 1>&- 2>&- | |
wait $TEEPID | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment