check root permissions only where needed

This commit is contained in:
Daniel Sommer 2021-04-06 17:07:06 +02:00
parent 6014d630ed
commit 6f99c255ba

View file

@ -9,22 +9,23 @@ blinky_mode="morph"
blinky_duration="2500" blinky_duration="2500"
# temperature # temperature
max_temp="85000" max_temp="65000"
crit_temp="90000" crit_temp="70000"
threshold_upper="66" threshold_upper="66"
threshold_lower="33" threshold_lower="33"
thermal_zones=( thermal_zones=(
"*" "3"
) )
# check for root permissions
[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" && exit 1
# argument to lowercase # argument to lowercase
arg="${1,,}" arg="${1,,}"
# functions # functions
function checkRoot() {
[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" && exit 1
}
# convert a temperature value to a rgb color value # convert a temperature value to a rgb color value
function temperatureToRGB() { function temperatureToRGB() {
[[ ! "$1" ]] && printf "error: did not receive a temperature value to convert to a rgb value\n" && exit 1 [[ ! "$1" ]] && printf "error: did not receive a temperature value to convert to a rgb value\n" && exit 1
@ -76,6 +77,7 @@ function getTemperature() {
# main part # main part
case "$arg" in case "$arg" in
-t|--temp|--temperature) -t|--temp|--temperature)
checkRoot
getTemperature getTemperature
temperatureToRGB "$result" temperatureToRGB "$result"
sendPOST "color=$result" "mode=$blinky_mode" "duration=$blinky_duration" sendPOST "color=$result" "mode=$blinky_mode" "duration=$blinky_duration"