From ccee8c418ead4b58e4b099d99d230c3ab1b93413 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 19 Sep 2021 03:38:26 +0300 Subject: add some safety checks --- write-intel-brightness | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/write-intel-brightness b/write-intel-brightness index 5960144..fe12b5d 100755 --- a/write-intel-brightness +++ b/write-intel-brightness @@ -1,9 +1,36 @@ #!/bin/bash +PROGNAME="$0" + echoerr() { - >&2 echo "$@" + >&2 echo "error: $@" +} + +die() { + echoerr "$@" + exit 1 +} + +usage() { + cat <<-_EOF + Usage: $PROGNAME +|- + _EOF + exit } +command_exists() { + command -V "$1" >/dev/null 2>&1 +} + +[ -z "$1" ] && usage +[ "$EUID" != 0 ] && die "must be run as root" + +for c in intel_reg awk; do + if ! command_exists $c; then + die "$c not found" + fi +done + max=$(intel_reg read 0xC8254 2>/dev/null | awk '{print $3}') max=${max:2:4} max_dec=$(printf "%d" $((16#$max))) -- cgit v1.2.3