Add missing ACPI volume and brightness scripts
[hvlinux.git] / stage2 / misc / acpi / brightness.sh
diff --git a/stage2/misc/acpi/brightness.sh b/stage2/misc/acpi/brightness.sh
new file mode 100755 (executable)
index 0000000..5e884dc
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+basedir=/sys/class/backlight
+
+# In percent
+min=10
+step=10
+
+dir=$(find ${basedir} -type l)
+
+read max_raw < ${dir}/max_brightness
+read cur_raw < ${dir}/brightness
+
+min_raw=$(echo "scale=0; (${min} * ${max_raw}) / 100" | bc)
+step_raw=$(echo "scale=0; (${step} * ${max_raw}) / 100" | bc)
+
+case $1 in
+    -)
+        new=`expr ${cur_raw} - ${step_raw}`
+        if [ ${new} -le ${min_raw} ]; then
+            new=${min_raw}
+        fi
+        ;;
+    +)
+        new=`expr ${cur_raw} + ${step_raw}`
+        if [ ${new} -ge ${max_raw} ]; then
+            new=${max_raw}
+        fi
+        ;;
+    *)
+        exit 1
+        ;;
+esac
+
+echo ${new} > ${dir}/brightness