Skip to content

Commit

Permalink
add script
Browse files Browse the repository at this point in the history
Signed-off-by: Mattéo Rossillol‑‑Laruelle <beatussum@protonmail.com>
  • Loading branch information
beatussum committed Dec 27, 2019
1 parent a9b3159 commit 51f36f5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PREFIX ?= /usr/local
DESTDIR ?=

INITDDIR ?= $(DESDIR)$(PREFIX)/etc/init.d

INSTALL ?= install -D -m755
RM ?= rm -f

.PHONY: install
install:
$(INSTALL) backlight-restorer $(INITDDIR)/backlight-restorer

.PHONY: uninstall
uninstall:
$(RM) $(INITDDIR)/backlight-restorer
51 changes: 51 additions & 0 deletions backlight-restorer
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/sbin/openrc-run

# Copyright (C) 2019 Mattéo Rossillol‑‑Laruelle <beatussum@protonmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


description="An OpenRC service for restoring the last brightness level on reboot"

start() {
ebegin "Restoring the screen brightness"

for card in $(basename /sys/class/backlight/*); do
local -r blight=$(cat "/var/cache/backlight/${card}")
if [ ${blight} -ne 0 ]; then
echo ${blight} > "/sys/class/backlight/${card}/brightness"
fi

sts=$?
test ${sts} -ne 0 || break
done

eend ${sts} "Cannot restore the brightness of ${card}"
}

stop() {
ebegin "Saving the screen brightness"

checkpath -D -o "root:root" /var/cache/backlight

for card in $(basename /sys/class/backlight/*); do
cp "/sys/class/backlight/${card}/brightness" \
"/var/cache/backlight/${card}"

sts=$?
test ${sts} -ne 0 || break
done

eend ${sts} "Cannot save the brightness of ${card}"
}

0 comments on commit 51f36f5

Please sign in to comment.