-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbswitchd.spec
170 lines (120 loc) · 4.44 KB
/
bbswitchd.spec
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Name: bbswitchd
Version: 0.1.5
Release: 1%{?dist}
Summary: Daemon for toggling discrete NVIDIA GPU power on Optimus laptops
License: GPLv3+
URL: https://github.com/polter-rnd/bbswitchd
Source0: https://github.com/polter-rnd/bbswitchd/archive/%{version}/bbswitchd-%{version}.tar.gz
BuildRequires: gcc
BuildRequires: meson >= 0.53.0
BuildRequires: systemd
BuildRequires: pkgconfig(libkmod)
Requires: python3
Requires: bbswitch-kmod
Requires(post): dracut
Requires(postun): dracut
Recommends: %{name}-selinux = %{version}-%{release}
%{?systemd_requires}
# UNIX socket group
%define socket_group bbswitchd
# Users from these will be added to socket group
%define admin_groups wheel
%description
Internally uses bbswitch kernel module to switch video adapter power state.
Useful for pre-Turing GPU generations without dynamic power management features,
allows to fully benefit from NVIDIA PRIME Render Offload technology
without need to keep graphics adapter turned on all the time.
%package selinux
Summary: SELinux policies for bbswitchd
BuildRequires: selinux-policy-devel
Requires: policycoreutils, libselinux-utils
Requires(post): selinux-policy-base >= %{_selinux_policy_version}, policycoreutils
Requires(postun): policycoreutils
BuildArch: noarch
%description selinux
SELinux policy module for use with bbswitchd.
%prep
%autosetup -p1 -n bbswitchd-%{version}
%build
%meson -Dselinux=enabled
%meson_build
%install
%meson_install
%post
%systemd_post bbswitch-sleep.service
%systemd_post bbswitchd.service
%systemd_post bbswitchd.socket
if [ "${1}" -eq 1 ]; then
# Add a group and members if the configured group does match the
# default group and if the group is missing
if grep -qx SocketGroup=%{socket_group} %{_unitdir}/bbswitchd.socket &&
! getent group %{socket_group} > /dev/null; then
groupadd --system %{socket_group}
users=$(getent -s files group %{admin_groups} | cut -d: -f4 | tr , '\n' | sort -u)
for user in $users; do
gpasswd -a $user %{socket_group}
done
fi
fi
# Regenerate initramfs on install/upgrade
dracut -f
%posttrans
# Create socket automatically
systemctl start bbswitchd.socket
%preun
%systemd_preun bbswitch-sleep.service
%systemd_preun bbswitchd.service
%systemd_preun bbswitchd.socket
%postun
%systemd_postun bbswitch-sleep.service
%systemd_postun_with_restart bbswitchd.service
%systemd_postun_with_restart bbswitchd.socket
# Regenerate initramfs and remove group on uninstall
if [ "${1}" -eq 0 ]; then
dracut -f
groupdel %{socket_group} || true
fi
%post selinux
%selinux_modules_install %{_datadir}/selinux/packages/bbswitchd.pp
%postun selinux
if [ "${1}" -eq 0 ]; then
%selinux_modules_uninstall bbswitchd
fi
%files
%license LICENSE
%{_bindir}/bbswitch
%{_sbindir}/bbswitchd
%{_unitdir}/bbswitch-sleep.service
%{_unitdir}/bbswitchd.service
%{_unitdir}/bbswitchd.socket
%{_presetdir}/90-bbswitchd.preset
%{_prefix}/lib/modprobe.d/bbswitch.conf
%{_udevrulesdir}/60-bbswitch-nvidia-mutter.rules
%{_udevrulesdir}/90-bbswitch-nvidia-dev.rules
%files selinux
%{_datadir}/selinux/packages/bbswitchd.pp
%{_datadir}/selinux/devel/include/contrib/bbswitchd.if
%changelog
* Sun Dec 03 2023 Pavel Artsishevsky <[email protected]> - 0.1.5-1
- Workaround boot freeze with disabling discrete GPU on boot
* Mon May 01 2023 Pavel Artsishevsky <[email protected]> - 0.1.4-1
- Load bbswitch module on boot
- Fix unintentional turning GPU on after wakeup
- Use socket activation instead of autostarting daemon
* Sat Apr 22 2023 Pavel Artsishevsky <[email protected]> - 0.1.3-2
- Restart bbswitchd.socket on update/reinstall
* Sat Apr 22 2023 Pavel Artsishevsky <[email protected]> - 0.1.3-1
- Add bbswitch-sleep.service for toggling module on sleep/wakeup
* Sun Mar 19 2023 Pavel Artsishevsky <[email protected]> - 0.1.2-2
- Don't remove bbswitchd group on update
* Sun Mar 19 2023 Pavel Artsishevsky <[email protected]> - 0.1.2-1
- Minor fixes
* Wed Feb 08 2023 Pavel Artsishevsky <[email protected]> - 0.1.1-3
- Added dracut to post/postun dependencies
- Fix SELinux dependency definitions
* Thu Jan 26 2023 Pavel Artsishevsky <[email protected]> - 0.1.1-2
- Added Python3 to runtime dependencies
* Thu Jan 26 2023 Pavel Artsishevsky <[email protected]> - 0.1.1-1
- Various packaging updates
* Tue Jan 17 2023 Pavel Artsishevsky <[email protected]> - 0.1.0-1
- Initial release