home · contact · privacy
Add mail data migration to mail setup script.
[config] / bin / w530_backlight.sh
1 #!/bin/sh
2
3 # A very primitive backlight setter with a hardcoded backlight path, to replace
4 # xbacklight which currently does not work on my system.
5
6 if ! echo "${1}" | egrep -q '^[0-9]+$' && ! [ "${1}" = "+" -o "${1}" = "-" ]; then
7   echo 'Argument must be a number, or "+", or "-".'
8   exit 1
9 fi
10 backlight_dir=/sys/class/backlight/intel_backlight
11 max_brightness=$(cat "${backlight_dir}"/max_brightness)
12 target="${backlight_dir}"/brightness
13 if [ "${1}" = "+" -o "${1}" = "-" ]; then
14   fract=$(expr "${max_brightness}" / 20)
15   cur_brightness=$(cat "${backlight_dir}"/brightness)
16   brightness=$(expr "${cur_brightness}" "${1}" "${fract}")
17   if [ "${brightness}" -gt "${max_brightness}" ]; then
18     brightness="${max_brightness}"
19   elif [ "${brightness}" -lt "0" ]; then
20     brightness=0
21   fi
22   sudo sh -c 'echo '"${brightness}"' > '"${target}"
23   exit 0
24 fi
25 percentage=${1}
26 if [ "${percentage}" = '100' ]; then
27   sudo sh -c 'echo '"${max_brightness}"' > '"${target}"
28 else
29   fract=$(expr "${max_brightness}" / 100)
30   brightness=$(expr "${percentage}" \* "${fract}")
31   sudo sh -c 'echo '"${brightness}"' > '"${target}"
32 fi