Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 1037fcd

Browse files
authored
Merge pull request #62 from t0xic0der/prime-config
Added option to enable/disable PRIME support on Optimus-supported devices
2 parents 8536351 + 3288bfc commit 1037fcd

File tree

3 files changed

+210
-26
lines changed

3 files changed

+210
-26
lines changed

nvautoinstall.spec

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%global srcname nvidia-auto-installer-for-fedora
22

33
Name: nvautoinstall
4-
Version: 0.3.6
4+
Version: 0.3.7
55
Release: 0%{?dist}
66
Summary: NVIDIA Auto Installer for Fedora
77

@@ -36,10 +36,17 @@ A CLI tool which lets you install proprietary NVIDIA drivers and much more
3636

3737
#-- CHANGELOG -----------------------------------------------------------------#
3838
%changelog
39+
40+
* Sat May 22 2021 Akashdeep Dhar <[email protected]>
41+
- v0.3.7
42+
- Added option to enable/disable PRIME support on Optimus-supported devices
43+
- Added other miscellaneous changes for ease of maintenance
44+
3945
* Sun May 09 2021 Akashdeep Dhar <[email protected]>
4046
- v0.3.6
4147
- Reworked installation method for CUDA repo compatibility
4248
- Minor patch leading to a version bump
49+
4350
* Thu Apr 29 2021 Akashdeep Dhar <[email protected]>
4451
- v0.3.5
4552
- Corrected unicode escape sequences for colors
@@ -48,6 +55,7 @@ A CLI tool which lets you install proprietary NVIDIA drivers and much more
4855
- Refactored the code to remove needless lines
4956
- Made compliance related changes here and there
5057
- Tested and confirmed the tool to be working in F34 Workstation
58+
5159
* Thu Jun 04 2020 Akashdeep Dhar <[email protected]>
5260
- v0.3.0
5361
- Combined RPM Fusion pinging, checking, installing into a single module
@@ -67,11 +75,13 @@ A CLI tool which lets you install proprietary NVIDIA drivers and much more
6775
- Added checks for NVIDIA repository and RPM Fusion repository availability
6876
- Added network availability check before pinging respective repo servers
6977
- Improved handling of interrupt. halt and suspend system calls for tool
78+
7079
* Mon Jun 01 2020 Akashdeep Dhar <[email protected]>
7180
- v0.2.6
7281
- Fixed broken repository addition module
7382
- Added installation of fedora-workstation-repositories first
7483
- Added enabling of repository after the install is complete
84+
7585
* Sun May 31 2020 Akashdeep Dhar <[email protected]>
7686
- v0.2.5
7787
- Removed mandatory sleep for kernel module load
@@ -81,6 +91,7 @@ A CLI tool which lets you install proprietary NVIDIA drivers and much more
8191
- Fixed boolean choices in main function
8292
- Fixed boolean choices in package check
8393
- Fixed prompt colors for custom-themed terminals
94+
8495
* Wed May 27 2020 Akashdeep Dhar <[email protected]>
8596
- v0.2.0
8697
- Cleaned up repeated code using class implemented decorator calls
@@ -92,6 +103,7 @@ A CLI tool which lets you install proprietary NVIDIA drivers and much more
92103
- Added dedicated status check for kernel module reader
93104
- Fixed confirmation choice during package check
94105
- Fixed typo in RPM Fusion mentions throughout the tool interface
106+
95107
* Fri May 22 2020 Akashdeep Dhar <[email protected]>
96108
- v0.1.0
97109
- Added host detection with display of system details and hostname

src/nvautoinstall/MainFunction.py

Lines changed: 196 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""
2+
##########################################################################
3+
*
4+
* Copyright © 2019-2021 Akashdeep Dhar <[email protected]>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*
19+
##########################################################################
20+
"""
21+
122
import os
223
import subprocess
324
import sys
@@ -179,6 +200,23 @@ def main(self):
179200
return data == 0
180201

181202

203+
class CollPrimeSupportEnabler(object):
204+
def main(self, opts):
205+
try:
206+
with open("/usr/share/X11/xorg.conf.d/nvidia.conf", "r") as sharconf:
207+
shardata = sharconf.read()
208+
primemod = ""
209+
for indx in shardata.split("\n"):
210+
primemod += indx + "\n"
211+
if opts is True and indx == "\tOption \"BaseMosaic\" \"on\"":
212+
primemod += "\tOption \"PrimaryGPU\" \"yes\"" + "\n"
213+
with open("/etc/X11/xorg.conf.d/nvidia.conf", "w") as etcdconf:
214+
etcdconf.write(primemod)
215+
return True
216+
except Exception:
217+
return False
218+
219+
182220
SupportCheck = CollSupportCheck()
183221
RPMFHandler = CollRPMFHandler()
184222
DriverInstaller = CollDriverInstaller()
@@ -188,6 +226,7 @@ def main(self):
188226
VidAccInstaller = CollVidAccInstaller()
189227
VulkanInstaller = CollVulkanInstaller()
190228
SuperuserCheck = CollSuperuserCheck()
229+
PrimeSupportEnabler = CollPrimeSupportEnabler()
191230

192231

193232
class InstallationMode(object):
@@ -204,6 +243,7 @@ def __init__(self):
204243
"--getall " : "This mode installs all the above packages.",
205244
"--cheksu " : "This mode allows you to check the user privilege level.",
206245
"--compat " : "This mode allows you to check your compatibility.",
246+
"--primec " : "This mode allows you to setup PRIME configuration.",
207247
"--version" : "Show the version and exit.",
208248
"--help " : "Show this message and exit.",
209249
}
@@ -555,6 +595,56 @@ def compat(self):
555595
DecoratorObject.failure_message("Leaving installer")
556596
sys.exit(0)
557597

598+
def primec(self):
599+
DecoratorObject.section_heading("CHECKING SUPERUSER PERMISSIONS...")
600+
if SuperuserCheck.main():
601+
DecoratorObject.success_message("Superuser privilege acquired")
602+
DecoratorObject.section_heading("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...")
603+
if RPMFHandler.avbl():
604+
DecoratorObject.warning_message("RPM Fusion repository for Proprietary NVIDIA Driver was detected")
605+
DecoratorObject.section_heading("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...")
606+
if RPMFHandler.conn():
607+
DecoratorObject.success_message("Connection to RPM Fusion servers was established")
608+
DecoratorObject.section_heading("LOOKING FOR EXISTING DRIVER PACKAGES...")
609+
data = DriverInstaller.avbl()
610+
if data is False:
611+
DecoratorObject.failure_message("No existing NVIDIA driver packages were detected")
612+
else:
613+
qant = 0
614+
for indx in data:
615+
if indx != "":
616+
qant += 1
617+
DecoratorObject.general_message(indx)
618+
DecoratorObject.warning_message("A total of " + str(qant) + " driver packages were detected")
619+
DecoratorObject.section_heading("SETTING UP PRIME SUPPORT...")
620+
DecoratorObject.warning_message("Intervention required")
621+
DecoratorObject.general_message(click.style("< Y >", fg="green", bold=True) + " to enable PRIME support")
622+
DecoratorObject.general_message(click.style("< N >", fg="red", bold=True) + " to disable PRIME support")
623+
DecoratorObject.general_message(click.style("< * >", fg="yellow", bold=True) + " anything else to leave")
624+
solution = input("[Y/N] ")
625+
if solution == "Y" or solution == "y":
626+
DecoratorObject.section_heading("ENABLING PRIME SUPPORT...")
627+
if PrimeSupportEnabler.main(True):
628+
DecoratorObject.success_message("PRIME Support was successfully enabled")
629+
else:
630+
DecoratorObject.failure_message("PRIME Support could not be enabled")
631+
elif solution == "N" or solution == "n":
632+
DecoratorObject.section_heading("DISABLING PRIME SUPPORT...")
633+
if PrimeSupportEnabler.main(False):
634+
DecoratorObject.success_message("PRIME Support was successfully disabled")
635+
else:
636+
DecoratorObject.failure_message("PRIME Support could not be disabled")
637+
else:
638+
DecoratorObject.section_heading("SAFE AND GOOD ANSWER...")
639+
else:
640+
DecoratorObject.failure_message("Connection to RPM Fusion servers could not be established")
641+
else:
642+
DecoratorObject.failure_message("RPM Fusion repository for Proprietary NVIDIA Driver was not detected")
643+
else:
644+
DecoratorObject.failure_message("Superuser privilege could not be acquired")
645+
DecoratorObject.failure_message("Leaving installer")
646+
sys.exit(0)
647+
558648
def lsmenu(self):
559649
DecoratorObject.section_heading("OPTIONS")
560650
for indx in self.menudict.keys():
@@ -563,33 +653,115 @@ def lsmenu(self):
563653

564654

565655
@click.command()
566-
@click.option("--rpmadd", "instmode", flag_value="rpmadd", help="This mode enables the RPM Fusion NVIDIA drivers repository")
567-
@click.option("--driver", "instmode", flag_value="driver", help="This mode simply installs the NVIDIA driver")
568-
@click.option("--x86lib", "instmode", flag_value="x86lib", help="This mode installs only the x86 libraries for Xorg")
569-
@click.option("--nvrepo", "instmode", flag_value="nvrepo", help="This mode enables the Official NVIDIA repository for CUDA")
570-
@click.option("--plcuda", "instmode", flag_value="plcuda", help="This mode installs only the CUDA support softwares")
571-
@click.option("--ffmpeg", "instmode", flag_value="ffmpeg", help="This mode installs only the FFMPEG acceleration")
572-
@click.option("--vulkan", "instmode", flag_value="vulkan", help="This mode installs only the Vulkan renderer")
573-
@click.option("--vidacc", "instmode", flag_value="vidacc", help="This mode installs only the VDPAU/VAAPI acceleration")
574-
@click.option("--getall", "instmode", flag_value="getall", help="This mode installs all the above packages")
575-
@click.option("--cheksu", "instmode", flag_value="cheksu", help="This mode allows you to check the user privilege level")
576-
@click.option("--compat", "instmode", flag_value="compat", help="This mode allows you to check your compatibility")
577-
@click.version_option(version=__version__, prog_name=click.style("NVAutoInstall by Akashdeep Dhar <[email protected]>", fg="green", bold=True))
656+
@click.option(
657+
"--rpmadd",
658+
"instmode",
659+
flag_value="rpmadd",
660+
help="This mode enables the RPM Fusion NVIDIA drivers repository."
661+
)
662+
@click.option(
663+
"--driver",
664+
"instmode",
665+
flag_value="driver",
666+
help="This mode simply installs the NVIDIA driver."
667+
)
668+
@click.option(
669+
"--x86lib",
670+
"instmode",
671+
flag_value="x86lib",
672+
help="This mode installs only the x86 libraries for Xorg."
673+
)
674+
@click.option(
675+
"--nvrepo",
676+
"instmode",
677+
flag_value="nvrepo",
678+
help="This mode enables the Official NVIDIA repository for CUDA."
679+
)
680+
@click.option(
681+
"--plcuda",
682+
"instmode",
683+
flag_value="plcuda",
684+
help="This mode installs only the CUDA support softwares."
685+
)
686+
@click.option(
687+
"--ffmpeg",
688+
"instmode",
689+
flag_value="ffmpeg",
690+
help="This mode installs only the FFMPEG acceleration."
691+
)
692+
@click.option(
693+
"--vulkan",
694+
"instmode",
695+
flag_value="vulkan",
696+
help="This mode installs only the Vulkan renderer."
697+
)
698+
@click.option(
699+
"--vidacc",
700+
"instmode",
701+
flag_value="vidacc",
702+
help="This mode installs only the VDPAU/VAAPI acceleration."
703+
)
704+
@click.option(
705+
"--getall",
706+
"instmode",
707+
flag_value="getall",
708+
help="This mode installs all the above packages."
709+
)
710+
@click.option(
711+
"--cheksu",
712+
"instmode",
713+
flag_value="cheksu",
714+
help="This mode allows you to check the user privilege level."
715+
)
716+
@click.option(
717+
"--compat",
718+
"instmode",
719+
flag_value="compat",
720+
help="This mode allows you to check your compatibility."
721+
)
722+
@click.option(
723+
"--primec",
724+
"instmode",
725+
flag_value="primec",
726+
help="This mode allows you to setup PRIME configuration."
727+
)
728+
@click.version_option(
729+
version=__version__,
730+
prog_name=click.style(
731+
"NVAutoInstall by Akashdeep Dhar <[email protected]>",
732+
fg="green",
733+
bold=True
734+
)
735+
)
578736
def clim(instmode):
579737
instobjc = InstallationMode()
580738
click.echo(click.style("[ # ] NVIDIA AUTOINSTALLER FOR FEDORA", fg="green", bold=True))
581-
if instmode == "rpmadd": instobjc.rpmadd()
582-
elif instmode == "driver": instobjc.driver()
583-
elif instmode == "x86lib": instobjc.x86lib()
584-
elif instmode == "nvrepo": instobjc.nvrepo()
585-
elif instmode == "plcuda": instobjc.plcuda()
586-
elif instmode == "ffmpeg": instobjc.ffmpeg()
587-
elif instmode == "vulkan": instobjc.vulkan()
588-
elif instmode == "vidacc": instobjc.vidacc()
589-
elif instmode == "getall": instobjc.getall()
590-
elif instmode == "cheksu": instobjc.cheksu()
591-
elif instmode == "compat": instobjc.compat()
592-
else: instobjc.lsmenu()
739+
if instmode == "rpmadd":
740+
instobjc.rpmadd()
741+
elif instmode == "driver":
742+
instobjc.driver()
743+
elif instmode == "x86lib":
744+
instobjc.x86lib()
745+
elif instmode == "nvrepo":
746+
instobjc.nvrepo()
747+
elif instmode == "plcuda":
748+
instobjc.plcuda()
749+
elif instmode == "ffmpeg":
750+
instobjc.ffmpeg()
751+
elif instmode == "vulkan":
752+
instobjc.vulkan()
753+
elif instmode == "vidacc":
754+
instobjc.vidacc()
755+
elif instmode == "getall":
756+
instobjc.getall()
757+
elif instmode == "cheksu":
758+
instobjc.cheksu()
759+
elif instmode == "compat":
760+
instobjc.compat()
761+
elif instmode == "primec":
762+
instobjc.primec()
763+
else:
764+
instobjc.lsmenu()
593765

594766

595767
if __name__ == "__main__":

src/nvautoinstall/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with nvautoinstall. If not, see <https://www.gnu.org/licenses/>.
1717

18-
__version__ = '0.3.6'
18+
__version__ = "0.3.7"

0 commit comments

Comments
 (0)