diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-09-19 03:38:26 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-09-19 03:38:26 +0300 |
commit | ccee8c418ead4b58e4b099d99d230c3ab1b93413 (patch) | |
tree | e67a16b274339b38f9dfca49c415a71ffdbaf798 | |
parent | 5506545a01ef8a1371991f9ae139bf008bee457b (diff) |
add some safety checks
-rwxr-xr-x | write-intel-brightness | 29 |
1 files changed, 28 insertions, 1 deletions
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))) |