#!/bin/sh

BRIGHTNESS_FILE=/etc/current_brightness
SYSTEM_BRIGHTNESS=/sys/class/backlight/backlight/brightness

# Check args
if [ ${#} -ne 1 ]; then
    echo "Usage: $(basename ${0}) new_brightness_percentage"
    exit 1
fi

# Check value's range
if [ ${1} -gt 100 ]; then
    echo "Usage: Wrong brightness percentage (${1}), must be between 0 and 100"
    exit 1
fi
brightness_percentage=${1}

# Set new brightness percentage
let value=${1}+10
let value/=10
echo ${value} > ${SYSTEM_BRIGHTNESS}

# Set new brightness value in brightness file
if [ ${?} -eq 0 ]; then
    rw
    echo ${brightness_percentage} > ${BRIGHTNESS_FILE}
    ro
fi
exit 0
