From e1b85c3263ccc3a3302ae8cb4d1fa0fe02aad5b0 Mon Sep 17 00:00:00 2001 From: aliriza Date: Tue, 11 Apr 2023 07:33:10 +0000 Subject: [PATCH] add extra services --- .../openrc/extras/backlight-restore.initd | 45 +++++++++++++++++++ .../openrc/extras/disable-secondary-gpu.initd | 11 +++++ .../openrc/extras/disable-secondary-gpu.sh | 29 ++++++++++++ sys/apps/openrc/ympbuild | 13 +++++- 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 sys/apps/openrc/extras/backlight-restore.initd create mode 100644 sys/apps/openrc/extras/disable-secondary-gpu.initd create mode 100644 sys/apps/openrc/extras/disable-secondary-gpu.sh diff --git a/sys/apps/openrc/extras/backlight-restore.initd b/sys/apps/openrc/extras/backlight-restore.initd new file mode 100644 index 00000000..ea730da5 --- /dev/null +++ b/sys/apps/openrc/extras/backlight-restore.initd @@ -0,0 +1,45 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2015 The OpenRC Authors. +# See the Authors file at the top-level directory of this distribution and +# https://github.com/OpenRC/openrc/blob/master/AUTHORS +# +# This file is part of OpenRC. It is subject to the license terms in +# the LICENSE file found in the top-level directory of this +# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE +# This file may not be copied, modified, propagated, or distributed +# except according to the terms contained in the LICENSE file. + +description="Save & restore backlight state." + +depend() +{ + after * +} + +start() +{ + if [ ! -d /var/cache/backlight ] ; then + mkdir -p /var/cache/backlight + fi + for device in $(ls /sys/class/backlight/) ; do + if [ -f /var/cache/backlight/${device} ] ; then + cat /var/cache/backlight/${device} > /sys/class/backlight/${device}/brightness + fi + done + return 0 +} + +stop() +{ + if [ ! -d /var/cache/backlight ] ; then + mkdir -p /var/cache/backlight + fi + for device in $(ls /sys/class/backlight/) ; do + cat /sys/class/backlight/${device}/brightness > /var/cache/backlight/${device} + done + return 0 +} +restart(){ + stop + start +} diff --git a/sys/apps/openrc/extras/disable-secondary-gpu.initd b/sys/apps/openrc/extras/disable-secondary-gpu.initd new file mode 100644 index 00000000..e6f75ed4 --- /dev/null +++ b/sys/apps/openrc/extras/disable-secondary-gpu.initd @@ -0,0 +1,11 @@ +#!/sbin/openrc-run + +name=disable-secondary-gpu + +depend() { + before dbus +} + +start() { + /usr/libexec/disable-secondary-gpu +} diff --git a/sys/apps/openrc/extras/disable-secondary-gpu.sh b/sys/apps/openrc/extras/disable-secondary-gpu.sh new file mode 100644 index 00000000..42c6ba04 --- /dev/null +++ b/sys/apps/openrc/extras/disable-secondary-gpu.sh @@ -0,0 +1,29 @@ +#!/bin/bash +if [[ ! -f /var/cache/disable-gpu ]] &>/dev/null; then + exit 0 +fi +if grep "nomodeset" /proc/cmdline ; then + exit 0 +fi + +remove_pci(){ + if [[ -d "/sys/bus/pci/devices/0000:$1/driver" ]] ; then + module=$(basename $(readlink /sys/bus/pci/devices/0000:$1/driver/module)) + echo "Disabled: $module ($1)" + rmmod -f $module + fi + echo 1 > /sys/bus/pci/devices/0000:$1/remove +} + +echo 1 > /sys/bus/pci/rescan + +for dir in /sys/class/drm/card[0-9*] ; do + # 03 Display controller + # 02 3D controller + if grep "^0x0302" $dir/device/class ; then + pci="$(basename $(readlink $dir/device))" + echo "Found 3D controller: ${pci:5}" + remove_pci "${pci:5}" + fi +done +udevadm control --reload diff --git a/sys/apps/openrc/ympbuild b/sys/apps/openrc/ympbuild index 9d5439f6..f10c687f 100644 --- a/sys/apps/openrc/ympbuild +++ b/sys/apps/openrc/ympbuild @@ -10,10 +10,16 @@ license=('GPLv3') source=("https://github.com/OpenRC/openrc/archive/refs/tags/$version.zip" "openrc.sysconf" "reboot" - "poweroff") + "poweroff" + "extras/backlight-restore.initd" + "extras/disable-secondary-gpu.initd" + "extras/disable-secondary-gpu.sh") depends=() makedepends=() md5sums=('8b74d3db544b496f6bb33d2648db5d2f' + 'SKIP' + 'SKIP' + 'SKIP' 'SKIP' 'SKIP' 'SKIP') @@ -61,5 +67,10 @@ package(){ install ../reboot ${DESTDIR}/sbin/reboot install ../poweroff ${DESTDIR}/sbin/poweroff ln -s openrc-shutdown ${DESTDIR}/sbin/shutdown + # install extras + mkdir -p ${DESTDIR}/usr/libexec + install ../disable-secondary-gpu.sh ${DESTDIR}/usr/libexec/disable-secondary-gpu + install ../disable-secondary-gpu.initd ${DESTDIR}/etc/init.d + install ../backlight-restore.initd ${DESTDIR}/etc/init.d }