Files
build/packages/bsp/odroid/fanctrl
Patrick Yavitz 94f7bfff89 packages: bsp: odroid: fanctrl: maintenance
Signed-off-by: Patrick Yavitz <pyavitz@xxxxx.com>
2023-08-20 19:20:06 +02:00

153 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# Description: Odroid N2L / N2Plus Fan Control
if [[ "$USER" == "root" ]]; then
:;
else
if [[ `command -v sudo` ]]; then
if [[ $EUID -ne 0 ]]; then
sudo "$0" "$@"
exit
fi
else
echo "Please run this as root or with sudo privileges."
exit 0
fi
fi
POINT="55000"
FINDME=`command -v fanctrl`
# Functions
warning (){
WARNING_MSG="Argument is not supported."
echo -e "$WARNING_MSG"
exit 0
}
service (){
# A service runs that tests the fan, so lets double tap the trip point and check that it hasn't changed
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
CURRENT=`cat /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp`
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
sleep 5.5 # delay double tapping the trip point
if [[ "$CURRENT" == "$POINT" ]]; then
:;
else
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
fi
fi
}
trip_point (){
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
else
echo -e "You are missing trip_point_3_temp?"
exit 0
fi
}
65(){ # 65°C
sed -i "s/^POINT=.*/POINT="'"65000"'"/" $FINDME
sleep .25
fanctrl run
}
55(){ # 55°C
sed -i "s/^POINT=.*/POINT="'"55000"'"/" $FINDME
sleep .25
fanctrl run
}
45(){ # 45°C
sed -i "s/^POINT=.*/POINT="'"45000"'"/" $FINDME
sleep .25
fanctrl run
}
35(){ # 35°C
sed -i "s/^POINT=.*/POINT="'"35000"'"/" $FINDME
sleep .25
fanctrl run
}
25(){ # 25°C
sed -i "s/^POINT=.*/POINT="'"25000"'"/" $FINDME
sleep .25
fanctrl run
}
run (){ # run script
trip_point
}
menu (){
while [ 1 ]
do
CHOICE=$(
export NEWT_COLORS='root=,black roottext=lightgray,black title=black,lightgray'
whiptail --backtitle "Current Trip Point: $POINT" --title "Fan Control" --menu "" --nocancel 0 0 0 \
"6)" "65°C" \
"5)" "55°C" \
"4)" "45°C" \
"3)" "35°C" \
"2)" "25°C" \
"E)" "Exit .." 3>&2 2>&1 1>&3
)
case $CHOICE in
"6)")
clear -x
fanctrl 65
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 65°C" 0 0
;;
"5)")
clear -x
fanctrl 55
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 55°C" 0 0
;;
"4)")
clear -x
fanctrl 45
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 45°C" 0 0
;;
"3)")
clear -x
fanctrl 35
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 35°C" 0 0
;;
"2)")
clear -x
fanctrl 25
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 25°C" 0 0
;;
"E)")
clear -x
exit 0
;;
esac
done
}
if [ $# -eq 0 ]; then
>&2 echo -e "Arguments: 65 55 45 35 25 menu run"
exit 1
fi
case $1 in
65|55|45|35|25|menu|run|service)
;;
*)
echo -e "Arguments: 65 55 45 35 25 menu run" >&2
exit 1
esac
FANCTRL=`echo $1`
$FANCTRL
exit 0