-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbacklight
75 lines (45 loc) · 1.55 KB
/
checkbacklight
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# checkbacklight - script to hook udev and set min/max backlight
# Set paths for the udev rule and settings file
rule="/etc/udev/rules.d/99-checkbacklight.rules"
settings="/etc/default/backlight"
# Check for root permissions
if [ "$(id -u)" == 0 ]; then
if [ ! $(which checkbacklight) ]; then
echo "script isn't executable in root's PATH."
exit 1
fi
else
echo "You must be root to use this script."
exit 1
fi
# Check for backlightctl
if [ ! $(which brightnessctl) ]; then
echo "brightnessctl not found, please install."
exit 1
fi
# Check for settings file, create if doesn't exist
if [ ! -f "$settings" ]; then
echo "# Default settings for backlight" > "$settings"
echo "# WARNING: there is no stupid-user protection here," >> "$settings"
echo "# DO NOT set max_brightness to 0 or something." >> "$settings"
echo "max_brightness=$(brightnessctl m)" >> "$settings"
echo "min_brightness=0" >> "$settings"
fi
# Check for udev rule, create if doesn't exist
if [ ! -f "$rule" ]; then
echo "ACTION=='change', SUBSYSTEM=='backlight', RUN+='$(which checkbacklight)'" > "$rule"
udevadm control --reload-rules
echo "udev rule created."
exit 0
fi
# Read settings file
source "$settings"
# Check the current brightness level
current_brightness=$(brightnessctl g)
# Adjust brightness if too high/low based on settings file
if [ $(("$current_brightness")) -gt $(("$max_brightness")) ]; then
brightnessctl s "$max_brightness"
elif [ $(("$current_brightness")) -lt $(("$min_brightness")) ]; then
brightnessctl s "$min_brightness"
fi