-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·150 lines (120 loc) · 3.94 KB
/
install.sh
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# NOTE: this script needs root
# NOTE: required commands: acpi, acpi_listen (for user to set vars in config)
# adjust vars in config.sh (more instructions therein)
. ./config.sh
set -e
install -d "$BATTERYDIM"
cat > "$BATTERYDIM"/set-brightness.sh << EOF
#!/usr/bin/env bash
. "$BATTERYDIM"/config.sh
read max < "\$BACKLIGHT/max_brightness"
echo Setting brightness to \$1% of max.
echo "(100*\$MIN_BRIGHTNESS+(100-\$MIN_BRIGHTNESS)*\$1)*\$max/10000" | bc \\
> "\$BACKLIGHT/brightness"
EOF
cat > "$BATTERYDIM"/plug-brightness.sh << EOF
#!/usr/bin/env bash
. "$BATTERYDIM"/config.sh
\$BATTERYDIM/set-brightness.sh "\$PLUG_BRIGHTNESS"
EOF
cat > "$BATTERYDIM"/unplug-brightness.sh << EOF
#!/usr/bin/env bash
. "$BATTERYDIM"/config.sh
\$BATTERYDIM/set-brightness.sh "\$UNPLUG_BRIGHTNESS"
EOF
cat > "$BATTERYDIM"/backlight.sh << EOF
#!/usr/bin/env bash
. "$BATTERYDIM"/config.sh
case \$1/\$2 in
pre/*)
# FIXME: UNIMPLEMENTED
#if [[ \$REMEMBER_STATE ]]
#then
# acpi -a | head -n 1 | cut -d ' ' -f 3 > \$STATEFILE
#fi
;;
post/*)
# something used to override the setting if we didn't wait, but this
# is no longer true, so this isn't necessary
#if [[ "\$2" == "suspend" ]]
#then
# sleep 0.5
#fi
state=\$(acpi -a | head -n 1 | cut -d ' ' -f 3)
if [[ "\$state" == "on-line" ]]
then
echo AC adapter plugged after \$2...
"$BATTERYDIM"/plug-brightness.sh
elif [[ "\$state" == "off-line" ]]
then
echo AC adapter unplugged after \$2...
"$BATTERYDIM"/unplug-brightness.sh
fi
;;
esac
EOF
cat > "$BATTERYDIM"/uninstall.sh << EOF
#!/usr/bin/env bash
# NOTE: this script needs root
# NOTE: this script assumes no changes have been made to relevant files beyond
# what the installation did, and so just deletes them all
. "$BATTERYDIM"/config.sh
systemctl unmask systemd-backlight@backlight:intel_backlight.service
systemctl disable boot_backlight.service sleep-backlight.service
# For unclear reasons (bug?), the sysinit.target.wants/boot-backlight.service
# link isn't removed like sleep.target.wants/sleep-backlight.service, so remove
# it manually
rm /usr/local/lib/systemd/system/sleep-backlight.service \\
/usr/local/lib/systemd/system/boot-backlight.service \\
/etc/systemd/system/sysinit.target.wants/boot-backlight.service
systemctl daemon-reload
rm /etc/acpi/events/ac_{,un}plugged
rm -rf "\$BATTERYDIM"
EOF
chmod 775 "$BATTERYDIM"/*.sh
install -m 644 -t "$BATTERYDIM" config.sh
echo "event=$ACPI_UNPLUG" > /etc/acpi/events/ac_unplugged
echo "action=$BATTERYDIM/unplug-brightness.sh" >> /etc/acpi/events/ac_unplugged
echo "event=$ACPI_PLUG" > /etc/acpi/events/ac_plugged
echo "action=$BATTERYDIM/plug-brightness.sh" >> /etc/acpi/events/ac_plugged
install -d /usr/local/lib/systemd/system
cat > /usr/local/lib/systemd/system/boot-backlight.service << EOF
[Unit]
Description=Set Screen Backlight Brightness Based on AC Plug Status After Boot
DefaultDependencies=no
RequiresMountsFor=$BATTERYDIM
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=sysinit.target shutdown.target
Wants=acpid.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=$BATTERYDIM/backlight.sh post boot
ExecStop=$BATTERYDIM/backlight.sh pre boot
TimeoutSec=90s
[Install]
WantedBy=sysinit.target
EOF
cat > /usr/local/lib/systemd/system/sleep-backlight.service << EOF
[Unit]
Description=Set Screen Backlight Brightness Based on AC Plug Status After Sleep
DefaultDependencies=no
RequiresMountsFor=$BATTERYDIM
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=$BATTERYDIM/backlight.sh pre suspend
ExecStop=$BATTERYDIM/backlight.sh post suspend
TimeoutSec=90s
[Install]
WantedBy=sleep.target
EOF
systemctl daemon-reload
systemctl enable boot-backlight.service sleep-backlight.service
systemctl restart acpid.service
# NOTE: this service may be different on different machines
systemctl mask --now systemd-backlight@backlight\:intel_backlight.service