#!/bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2020-present Fewtarius ## Load minimal distribution settings to improve ## performance. . /etc/profile.d/02-distribution BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)" BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}" MIN=0 MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit)) STEP="$(echo "scale=1; (${MAX} / 10)" | bc)" if [ ! -f "${BRIGHTNESS_DEV}" ] then echo "ERROR: There is no BRIGHTNESS object to manage." exit 1 fi getBrightness() { echo $(<${BRIGHTNESS_DEV}) } setBrightness() { echo "${1}" > ${BRIGHTNESS_DEV} set_setting system.brightness "${2}" } stepUp() { CURRENT=$(get_setting system.brightness) NEXT=$(( ${CURRENT} + 1 )) if (( ${NEXT} > 10 )) then NEXT=10 fi BRIGHTNESS=$(printf '%.0f' "$(echo "scale=1; ${STEP} * ${NEXT}" | bc)") setBrightness ${BRIGHTNESS} ${NEXT} } stepDown() { CURRENT=$(get_setting system.brightness) NEXT=$(( ${CURRENT} - 1 )) if (( ${NEXT} < 0 )) then NEXT=0 fi BRIGHTNESS=$(printf '%.0f' "$(echo "scale=1; ${STEP} * ${NEXT}" | bc)") setBrightness ${BRIGHTNESS} ${NEXT} } case ${1} in "up") stepUp ;; "down") stepDown ;; "device") echo ${BRIGHTNESS_DEV} ;; "path") echo ${BRIGHTNESS_PATH} ;; "set") setBrightness "$(printf '%.0f' "$(echo "scale=1; ${STEP} * ${2}" | bc)")" ${2} ;; *) echo $(getBrightness) ;; esac