home · contact · privacy
bce6b30039f635fec143094f071af741f11e986b
[config] / bin / w530_backlight.sh
1 #!/bin/sh
2 # A very primitive backlight setter with a hardcoded backlight path, to replace
3 # xbacklight which currently does not work on my system.
4 if ! echo "${1}" | egrep -q '^[0-9]+$'; then
5   echo 'Argument must be a number.'
6   exit 1
7 fi
8 percentage=${1}
9 backlight_dir=/sys/class/backlight/intel_backlight
10 max_brightness=$(cat "${backlight_dir}"/max_brightness)
11 if [ "${percentage}" = '100' ]; then
12   sudo sh -c 'echo '"${max_brightness}"' > '"${backlight_dir}"'/brightness'
13 else
14   fract=$(expr "${max_brightness}" / 100)
15   brightness=$(expr "${percentage}" \* "${fract}")
16   sudo sh -c 'echo '"${brightness}"' > '"${backlight_dir}"'/brightness'
17 fi