#!/bin/bash
# Created from sonybright.sh to
# support also other computers
# Changes are marked with "MODI"
# For me: NEC LaVie


test -f /usr/share/acpi-support/key-constants || exit 0

# MODI: Use variables for device files
BRIGHTNESS_DEV="/sys/class/backlight/*/brightness"
MAX_BRIGHTNESS_DEV="/sys/class/backlight/*/max_brightness"

# MODI: Try wildcard catcher
# BRIGHTNESS=$(cat /sys/class/backlight/sony/brightness)
BRIGHTNESS=$(cat $BRIGHTNESS_DEV )
# MODI: Get max_brightness also
MAX_BRIGHTNESS=$(cat $MAX_BRIGHTNESS_DEV)

# MODI: This check not needed
#if [ "$BRIGHTNESS" -gt $MAX_BRIGHTNESS ]; then
#	BRIGHTNESS=0
#fi

# MODI: use BRTUP/BRTDN ($2) as parameters
if [ "x$2" = "xBRTDN" ]; then
   if [ "x$BRIGHTNESS" != "x0" ]; then
      BRIGHTNESS=$(( $BRIGHTNESS - 1 ))
      echo $BRIGHTNESS > $BRIGHTNESS_DEV
   fi
   # MODI: remove sony-only different methods
elif [ "x$2" = "xBRTUP" ]; then
   if [ "x$BRIGHTNESS" != "x${MAX_BRIGHTNESS}" ]; then
      BRIGHTNESS=$(( $BRIGHTNESS + 1 ))
      echo $BRIGHTNESS > $BRIGHTNESS_DEV
   fi
   # MODI: remove sony-only different methods
else
   echo >&2 Unknown argument $2
fi

