From 51f36f5a8280a4dcc21aa7b06a6b53c2e479e576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Rossillol=E2=80=91=E2=80=91Laruelle?= Date: Fri, 27 Dec 2019 23:54:27 +0100 Subject: [PATCH] add script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattéo Rossillol‑‑Laruelle --- Makefile | 15 ++++++++++++++ backlight-restorer | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Makefile create mode 100755 backlight-restorer diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a53c469 --- /dev/null +++ b/Makefile @@ -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 diff --git a/backlight-restorer b/backlight-restorer new file mode 100755 index 0000000..f895a56 --- /dev/null +++ b/backlight-restorer @@ -0,0 +1,51 @@ +#!/sbin/openrc-run + +# Copyright (C) 2019 Mattéo Rossillol‑‑Laruelle +# +# 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 . + + +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}" +}