From 83e1bd3a00719ff4b0a495390b833f1c87418c87 Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Jun 04 2020 12:24:41 +0000 Subject: Merge pull request #42 from t0xic0der/porting-click-interface Porting click interface --- diff --git a/ColoramaCalls.py b/ColoramaCalls.py index d34fc3e..8b4959f 100644 --- a/ColoramaCalls.py +++ b/ColoramaCalls.py @@ -1,4 +1,5 @@ -from colorama import init, Fore, Style +import click +from colorama import Fore, Style class StatusDecorator(object): def __init__(self): @@ -9,16 +10,16 @@ class StatusDecorator(object): self.STDS = " " def SuccessMessage(self, RequestMessage): - print(self.PASS + " " + Style.RESET_ALL + RequestMessage) + click.echo(self.PASS + " " + Style.RESET_ALL + RequestMessage) def FailureMessage(self, RequestMessage): - print(self.FAIL + " " + Style.RESET_ALL + RequestMessage) + click.echo(self.FAIL + " " + Style.RESET_ALL + RequestMessage) def WarningMessage(self, RequestMessage): - print(self.WARN + " " + Style.RESET_ALL + RequestMessage) + click.echo(self.WARN + " " + Style.RESET_ALL + RequestMessage) def SectionHeader(self, RequestMessage): - print(self.HEAD + " " + Fore.CYAN + RequestMessage + Style.RESET_ALL) + click.echo(self.HEAD + " " + Fore.CYAN + Style.BRIGHT + RequestMessage + Style.RESET_ALL) def NormalMessage(self, RequestMessage): - print(self.STDS + " " + Style.RESET_ALL + RequestMessage) \ No newline at end of file + click.echo(self.STDS + " " + Style.RESET_ALL + RequestMessage) \ No newline at end of file diff --git a/DriverInstaller.py b/DriverInstaller.py deleted file mode 100644 index fea06a3..0000000 --- a/DriverInstaller.py +++ /dev/null @@ -1,20 +0,0 @@ -import os, sys, time -from colorama import init, Fore, Style -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("INSTALLING PROPRIETARY DRIVERS...") - ExecStatusCode = os.system("dnf install -y gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686") - if ExecStatusCode == 0: - DecoratorObject.SuccessMessage("Driver package installation completed") - DecoratorObject.WarningMessage("Kernel modules would be built up on the next boot") - else: - DecoratorObject.FailureMessage("Could not install proprietary drivers") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/HostDetection.py b/HostDetection.py deleted file mode 100644 index 761b3ca..0000000 --- a/HostDetection.py +++ /dev/null @@ -1,30 +0,0 @@ -import os, distro, sys -from colorama import init -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("GATHERING ACTIVE INFORMATION...") - DecoratorObject.SuccessMessage("Host information was gathered") - datadict = { - "System": str(os.uname().sysname) + " v" + str(os.uname().release), - "Hostname": str(os.uname().nodename), - "Version": str(os.uname().version), - "Distribution": str(distro.os_release_info()["name"]) + " " + str(distro.os_release_info()["version_id"]) + " " + str(os.uname().machine), - } - for indx in datadict.keys(): - DecoratorObject.NormalMessage(indx + ": " + datadict[indx]) - if str(distro.os_release_info()["name"]) == "Fedora": - if int(distro.os_release_info()["version_id"]) >= 32: - DecoratorObject.SuccessMessage("Supported OS detected - " + datadict["Distribution"]) - else: - DecoratorObject.WarningMessage("Minimally supported OS detected - " + datadict["Distribution"]) - else: - DecoratorObject.FailureMessage("Unsupported OS detected - " + datadict["Distribution"]) - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/MainFunction.py b/MainFunction.py index efff168..fd24dca 100644 --- a/MainFunction.py +++ b/MainFunction.py @@ -1,56 +1,596 @@ -import os, sys -import HostDetection, SupportCheck, RPMFHandler, PackageCheck, RepoInstaller, DriverInstaller +import os, subprocess, sys, click, distro from colorama import init, Fore, Style from ColoramaCalls import StatusDecorator init() DecoratorObject = StatusDecorator() -def main(): - print(Style.BRIGHT + Fore.LIGHTCYAN_EX + "[ # ] NVIDIA AUTOINSTALLER FOR FEDORA 32 AND ABOVE" + Style.RESET_ALL) - if os.geteuid() == 0: - HostDetection.main() - SupportCheck.main() - userinst = PackageCheck.main() - if userinst == 1: - repofetc = RPMFHandler.main() - if repofetc == 1: - RepoInstaller.main() - DriverInstaller.main() - DecoratorObject.SectionHeader("DRIVER INSTALLATION SUCCESSFULLY COMPLETED") - while True: - userpick = input(Style.BRIGHT + Fore.YELLOW + "[ ! ]" + Style.RESET_ALL + " " + "Do you wish to reboot your system now? (Y/N) ") - if userpick == "y" or userpick == "Y": - DecoratorObject.WarningMessage("Rebooting now") - os.system("systemctl reboot") - elif userpick == "n" or userpick == "N": - DecoratorObject.WarningMessage("You would need to reboot to load up installed drivers") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - elif repofetc == -1: - DecoratorObject.FailureMessage("Installation cannot proceed without RPM Fusion NVIDIA repository!") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - else: - DriverInstaller.main() - DecoratorObject.SectionHeader("DRIVER INSTALLATION SUCCESSFULLY COMPLETED") - while True: - userpick = input(Style.BRIGHT + Fore.YELLOW + "[ ! ]" + Style.RESET_ALL + " " + "Do you wish to reboot your system now? (Y/N) ") - if userpick == "y" or userpick == "Y": - DecoratorObject.WarningMessage("Rebooting now") - os.system("systemctl reboot") - elif userpick == "n" or userpick == "N": - DecoratorObject.WarningMessage("You would need to reboot to load up installed drivers") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - else: - DecoratorObject.FailureMessage("Installation was cancelled voluntarily") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - else: - DecoratorObject.FailureMessage("Installer cannot proceed without root privileges") +class Coll_SupportCheck(object): + def gpuc(self): + comand = "lspci | grep -E 'VGA|3D'" + prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = prompt.communicate()[0].decode("utf-8") + linect = output.count("\n") + pkname = output.split("\n") + if "NVIDIA" not in output: + return False + else: + if linect == 1: + supprt = "single" + else: + supprt = "optims" + jsondt = { + "supprt": supprt, + "gpuqnt": linect, + "gpulst": pkname, + } + return jsondt + + def main(self): + jsondt = { + "System": str(os.uname().sysname) + " v" + str(os.uname().release), + "Hostname": str(os.uname().nodename), + "Version": str(os.uname().version), + "Distribution": str(distro.os_release_info()["name"]) + " " + str(distro.os_release_info()["version_id"]) + " " + str(os.uname().machine), + } + return jsondt + + def avbl(self): + if str(distro.os_release_info()["name"]) == "Fedora": + if int(distro.os_release_info()["version_id"]) >= 32: + return "full" + else: + return "half" + else: + return False + +class Coll_RPMFHandler(object): + def avbl(self): + comand = "dnf repolist | grep 'rpmfusion-nonfree-nvidia-driver'" + prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = prompt.communicate()[0].decode("utf-8") + if "rpmfusion-nonfree-nvidia-driver" in output: + return True + else: + return False + + def conn(self): + retndata = subprocess.getstatusoutput("ping -c 3 -W 3 rpmfusion.org")[0] + if retndata == 0: + return True + else: + return False + + def main(self): + os.system("dnf install -y fedora-workstation-repositories") + retndata = subprocess.getstatusoutput("dnf config-manager --set-enable rpmfusion-nonfree-nvidia-driver")[0] + if retndata == 0: + return True + else: + return False + +class Coll_DriverInstaller(object): + def main(self): + ExecStatusCode = os.system( + "dnf install -y gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs") + if ExecStatusCode == 0: + return True + else: + return False + + def avbl(self): + comand = "rpm -qa | grep 'nvidia'" + prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = prompt.communicate()[0].decode("utf-8") + linect = output.count("\n") + if linect == 0: + return False + else: + pkname = output.split("\n") + return pkname + +class Coll_X86LibInstaller(object): + def main(self): + ExecStatusCode = os.system("dnf install -y xorg-x11-drv-nvidia-libs.i686") + if ExecStatusCode == 0: + return True + else: + return False + +class Coll_PlCudaInstaller(object): + def rpck(self): + comand = "dnf repolist | grep 'cuda'" + prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = prompt.communicate()[0].decode("utf-8") + if "cuda" in output: + return True + else: + return False + + def rpin(self): + retndata = subprocess.getstatusoutput("dnf config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/fedora29/x86_64/cuda-fedora29.repo")[0] + print(retndata) + if retndata == 0: + return True + else: + return False + + def conn(self): + retndata = subprocess.getstatusoutput("ping -c 3 -W 3 developer.download.nvidia.com")[0] + if retndata == 0: + return True + else: + return False + + def rpup(self): + ExecStatusCode = os.system("dnf clean all") + if ExecStatusCode == 0: + return True + else: + return False + + def meta(self): + ExecStatusCode = os.system("dnf install -y xorg-x11-drv-nvidia-cuda") + if ExecStatusCode == 0: + return True + else: + return False + + def main(self): + ExecStatusCode = os.system("dnf install -y cuda") + if ExecStatusCode == 0: + return True + else: + return False + +class Coll_FFMPEGInstaller(object): + def main(self): + ExecStatusCode = os.system("dnf install -y xorg-x11-drv-nvidia-cuda-libs") + if ExecStatusCode == 0: + return True + else: + return False + +class Coll_VidAccInstaller(object): + def main(self): + ExecStatusCode = os.system("dnf install -y vdpauinfo libva-vdpau-driver libva-utils") + if ExecStatusCode == 0: + return True + else: + return False + +class Coll_VulkanInstaller(object): + def main(self): + ExecStatusCode = os.system("dnf install -y vulkan") + if ExecStatusCode == 0: + return True + else: + return False + +class Coll_SuperuserCheck(object): + def main(self): + data = os.geteuid() + if data == 0: + return True + else: + return False + +SupportCheck = Coll_SupportCheck() +RPMFHandler = Coll_RPMFHandler() +DriverInstaller = Coll_DriverInstaller() +x86LibInstaller = Coll_X86LibInstaller() +PlCudaInstaller = Coll_PlCudaInstaller() +FFMPEGInstaller = Coll_FFMPEGInstaller() +VidAccInstaller = Coll_VidAccInstaller() +VulkanInstaller = Coll_VulkanInstaller() +SuperuserCheck = Coll_SuperuserCheck() + +class InstallationMode(object): + def __init__(self): + self.menudict = { + "--rpmadd " : "This mode enables the RPM Fusion NVIDIA drivers repository.", + "--driver " : "This mode simply installs the NVIDIA driver.", + "--x86lib " : "This mode installs only the x86 libraries for Xorg.", + "--nvrepo " : "This mode enables the Official NVIDIA repository for CUDA.", + "--plcuda " : "This mode installs only the CUDA support softwares.", + "--ffmpeg " : "This mode installs only the FFMPEG acceleration.", + "--vulkan " : "This mode installs only the Vulkan renderer.", + "--vidacc " : "This mode installs only the VDPAU/VAAPI acceleration.", + "--getall " : "This mode installs all the above packages.", + "--cheksu " : "This mode allows you to check the user privilege level.", + "--compat " : "This mode allows you to check your compatibility.", + "--version" : "Show the version and exit.", + "--help " : "Show this message and exit.", + } + + def rpmadd(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SuccessMessage("No further action is necessary") + else: + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + DecoratorObject.WarningMessage("Repository enabling is required") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("INSTALLING RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.main(): + DecoratorObject.SuccessMessage("RPM Fusion NVIDIA repository was enabled") + else: + DecoratorObject.FailureMessage("RPM Fusion NVIDIA repository could not be enabled") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def driver(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.WarningMessage("No existing NVIDIA driver packages were detected") + DecoratorObject.SectionHeader("INSTALLING PROPRIETARY DRIVERS...") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("REINSTALLING PROPRIETARY DRIVERS...") + if DriverInstaller.main(): + DecoratorObject.SuccessMessage("Driver package installation completed") + else: + DecoratorObject.FailureMessage("Proprietary drivers could not be installed") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") DecoratorObject.FailureMessage("Leaving installer") sys.exit(0) + def x86lib(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.FailureMessage("No existing NVIDIA driver packages were detected") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("INSTALLING x86 LIBRARIES FOR XORG...") + if x86LibInstaller.main(): + DecoratorObject.SuccessMessage("x86 libraries for XORG were successfully installed") + else: + DecoratorObject.FailureMessage("x86 libraries for XORG could not be installed") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def nvrepo(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF OFFICIAL CUDA REPOSITORY...") + if PlCudaInstaller.rpck(): + DecoratorObject.WarningMessage("Official CUDA repository was detected") + DecoratorObject.SuccessMessage("No further action is necessary") + else: + DecoratorObject.WarningMessage("Official CUDA repository was not detected") + DecoratorObject.WarningMessage("Repository enabling is required") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO NVIDIA SERVERS...") + if PlCudaInstaller.conn(): + DecoratorObject.SuccessMessage("Connection to NVIDIA servers was established") + DecoratorObject.SectionHeader("INSTALLING OFFICIAL CUDA REPOSITORY...") + if PlCudaInstaller.rpin(): + DecoratorObject.SuccessMessage("Official CUDA repository was enabled") + DecoratorObject.SectionHeader("REFRESHING REPOSITORY LIST...") + if PlCudaInstaller.rpup(): + DecoratorObject.SuccessMessage("Repositories have been refreshed") + else: + DecoratorObject.FailureMessage("Repositories could not be refreshed") + else: + DecoratorObject.FailureMessage("Official CUDA repository could not be enabled") + else: + DecoratorObject.FailureMessage("Connection to NVIDIA servers could not be established") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def plcuda(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.FailureMessage("No existing NVIDIA driver packages were detected") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF OFFICIAL CUDA REPOSITORY...") + if PlCudaInstaller.rpck(): + DecoratorObject.WarningMessage("Official CUDA repository was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO NVIDIA SERVERS...") + if PlCudaInstaller.conn(): + DecoratorObject.SuccessMessage("Connection to NVIDIA servers was established") + DecoratorObject.SectionHeader("INSTALLING RPM FUSION METAPACKAGE FOR CUDA...") + if PlCudaInstaller.meta(): + DecoratorObject.SuccessMessage("RPM Fusion CUDA metapackage was successfully installed") + DecoratorObject.SectionHeader("INSTALLING NVIDIA CUDA CORE PACKAGES...") + if PlCudaInstaller.main(): + DecoratorObject.SuccessMessage("NVIDIA CUDA core packages were successfully installed") + else: + DecoratorObject.FailureMessage("NVIDIA CUDA core packages could not be installed") + else: + DecoratorObject.FailureMessage("RPM Fusion CUDA metapackage packages could not be installed") + else: + DecoratorObject.FailureMessage("Connection to NVIDIA servers could not be established") + else: + DecoratorObject.FailureMessage("Official CUDA repository was not detected") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def ffmpeg(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.FailureMessage("No existing NVIDIA driver packages were detected") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("INSTALLING NVENC/NVDEC FOR FFMPEG ACCELERATION...") + if FFMPEGInstaller.main(): + DecoratorObject.SuccessMessage("NVENC/NVDEC for FFMPEG acceleration were successfully installed") + else: + DecoratorObject.FailureMessage("NVENC/NVDEC for FFMPEG acceleration could not be installed") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def vulkan(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.FailureMessage("No existing NVIDIA driver packages were detected") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("INSTALLING VULKAN RENDERER SUPPORT...") + if VulkanInstaller.main(): + DecoratorObject.SuccessMessage("Vulkan renderer support were successfully installed") + else: + DecoratorObject.FailureMessage("Vulkan renderer support could not be installed") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def vidacc(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("CHECKING AVAILABILITY OF RPM FUSION NVIDIA REPOSITORY...") + if RPMFHandler.avbl(): + DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver was detected") + DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION SERVERS...") + if RPMFHandler.conn(): + DecoratorObject.SuccessMessage("Connection to RPM Fusion servers was established") + DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") + data = DriverInstaller.avbl() + if data is False: + DecoratorObject.FailureMessage("No existing NVIDIA driver packages were detected") + else: + qant = 0 + for indx in data: + if indx != "": + qant += 1 + DecoratorObject.NormalMessage(indx) + DecoratorObject.WarningMessage("A total of " + str(qant) + " driver packages were detected") + DecoratorObject.SectionHeader("INSTALLING VIDEO ACCELERATION SUPPORT...") + if VidAccInstaller.main(): + DecoratorObject.SuccessMessage("Video acceleration were successfully installed") + else: + DecoratorObject.FailureMessage("Video acceleration could not be installed") + else: + DecoratorObject.FailureMessage("Connection to RPM Fusion servers could not be established") + else: + DecoratorObject.FailureMessage("RPM Fusion repository for Proprietary NVIDIA Driver was not detected") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def getall(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser privilege acquired") + DecoratorObject.SectionHeader("FULL FLEDGED INSTALLATION BEGINNING...") + DecoratorObject.NormalMessage("This mode is yet to be implemented") + else: + DecoratorObject.FailureMessage("Superuser privilege could not be acquired") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def cheksu(self): + DecoratorObject.SectionHeader("CHECKING SUPERUSER PERMISSIONS...") + if SuperuserCheck.main(): + DecoratorObject.SuccessMessage("Superuser permission is available") + DecoratorObject.NormalMessage("This tool is expected to work correctly here") + else: + DecoratorObject.FailureMessage("Superuser permission is not available") + DecoratorObject.NormalMessage("This tool cannot be used here") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def compat(self): + DecoratorObject.SectionHeader("CHECKING FOR GPU COMPATIBILITY...") + data = SupportCheck.gpuc() + DecoratorObject.WarningMessage("Compatibility infomation was obtained") + if data is False: + DecoratorObject.FailureMessage("No supported NVIDIA GPU was detected") + else: + DecoratorObject.SuccessMessage("One or more active NVIDIA GPUs were detected") + supprt = data["supprt"] + gpulst = data["gpulst"] + for indx in gpulst: + if indx != "": + DecoratorObject.NormalMessage(indx) + if supprt == "single": + DecoratorObject.SuccessMessage("An single dedicated GPU setup was detected") + else: + DecoratorObject.SuccessMessage("An Optimus Dual GPU setup was detected") + DecoratorObject.SectionHeader("GATHERING CURRENT HOST INFORMATION...") + data = SupportCheck.main() + DecoratorObject.WarningMessage("Host information was gathered") + for indx in data.keys(): + DecoratorObject.NormalMessage(indx + ": " + data[indx]) + DecoratorObject.SectionHeader("CHECKING FOR HOST COMPATIBILITY...") + data = SupportCheck.avbl() + if data is False: + DecoratorObject.FailureMessage("Unsupported OS detected") + DecoratorObject.NormalMessage("This tool cannot be used here") + else: + if data == "full": + DecoratorObject.SuccessMessage("Supported OS detected") + DecoratorObject.NormalMessage("This tool is expected to work correctly here") + elif data == "half": + DecoratorObject.WarningMessage("Minimally supported OS detected") + DecoratorObject.NormalMessage("Discretion is advised while using this tool") + DecoratorObject.FailureMessage("Leaving installer") + sys.exit(0) + + def lsmenu(self): + DecoratorObject.SectionHeader("OPTIONS") + for indx in self.menudict.keys(): + DecoratorObject.NormalMessage(Style.BRIGHT + Fore.GREEN + indx + Style.RESET_ALL + " → " + self.menudict[indx]) + sys.exit(0) + +@click.command() +@click.option("--rpmadd", "instmode", flag_value="rpmadd", help="This mode enables the RPM Fusion NVIDIA drivers repository") +@click.option("--driver", "instmode", flag_value="driver", help="This mode simply installs the NVIDIA driver") +@click.option("--x86lib", "instmode", flag_value="x86lib", help="This mode installs only the x86 libraries for Xorg") +@click.option("--nvrepo", "instmode", flag_value="nvrepo", help="This mode enables the Official NVIDIA repository for CUDA") +@click.option("--plcuda", "instmode", flag_value="plcuda", help="This mode installs only the CUDA support softwares") +@click.option("--ffmpeg", "instmode", flag_value="ffmpeg", help="This mode installs only the FFMPEG acceleration") +@click.option("--vulkan", "instmode", flag_value="vulkan", help="This mode installs only the Vulkan renderer") +@click.option("--vidacc", "instmode", flag_value="vidacc", help="This mode installs only the VDPAU/VAAPI acceleration") +@click.option("--getall", "instmode", flag_value="getall", help="This mode installs all the above packages") +@click.option("--cheksu", "instmode", flag_value="cheksu", help="This mode allows you to check the user privilege level") +@click.option("--compat", "instmode", flag_value="compat", help="This mode allows you to check your compatibility") +@click.version_option(version="v0.3.0", prog_name="NVAutoInstFedora32 by t0xic0der") +def clim(instmode): + instobjc = InstallationMode() + print(Style.BRIGHT + Fore.GREEN + "[ # ] NVIDIA AUTOINSTALLER FOR FEDORA 32 AND ABOVE" + Style.RESET_ALL) + if instmode == "rpmadd": + instobjc.rpmadd() + elif instmode == "driver": + instobjc.driver() + elif instmode == "x86lib": + instobjc.x86lib() + elif instmode == "nvrepo": + instobjc.nvrepo() + elif instmode == "plcuda": + instobjc.plcuda() + elif instmode == "ffmpeg": + instobjc.ffmpeg() + elif instmode == "vulkan": + instobjc.vulkan() + elif instmode == "vidacc": + instobjc.vidacc() + elif instmode == "getall": + instobjc.getall() + elif instmode == "cheksu": + instobjc.cheksu() + elif instmode == "compat": + instobjc.compat() + else: + instobjc.lsmenu() + if __name__ == "__main__": - main() \ No newline at end of file + clim() \ No newline at end of file diff --git a/PackageCheck.py b/PackageCheck.py deleted file mode 100644 index d4ef95f..0000000 --- a/PackageCheck.py +++ /dev/null @@ -1,36 +0,0 @@ -import subprocess -from colorama import init, Fore, Style -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("LOOKING FOR EXISTING DRIVER PACKAGES...") - comand = "rpm -qa | grep 'nvidia'" - prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output = prompt.communicate()[0].decode("utf-8") - linect = output.count("\n") - if linect == 0: - DecoratorObject.WarningMessage("No existing NVIDIA drivers were detected!") - while True: - userpick = input(Style.BRIGHT + Fore.YELLOW + "[ ! ]" + Style.RESET_ALL + " " + "Do you wish to install the drivers? (Y/N) ") - if userpick == "y" or userpick == "Y": - return 1 - elif userpick == "n" or userpick == "N": - return -1 - else: - DecoratorObject.SuccessMessage("A total of " + str(linect) + " driver packages were detected!") - pkname = output.split("\n") - for indx in pkname: - if indx != "": - DecoratorObject.NormalMessage(indx) - while True: - userpick = input(Style.BRIGHT + Fore.YELLOW + "[ ! ]" + Style.RESET_ALL + " " + "Do you wish to reinstall the drivers? (Y/N) ") - if userpick == "y" or userpick == "Y": - return 1 - elif userpick == "n" or userpick == "N": - return -1 - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/RPMFHandler.py b/RPMFHandler.py deleted file mode 100644 index 5af55f2..0000000 --- a/RPMFHandler.py +++ /dev/null @@ -1,33 +0,0 @@ -import subprocess, sys -from colorama import init, Fore, Style -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("ATTEMPTING CONNECTION TO RPM FUSION...") - retndata = subprocess.getstatusoutput("ping -c 3 -W 3 rpmfusion.org")[0] - if retndata == 0: - DecoratorObject.SuccessMessage("Connection to RPM Fusion server was estabilished") - comand = "dnf repolist | grep 'rpmfusion-nonfree-nvidia-driver'" - prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output = prompt.communicate()[0].decode("utf-8") - if "rpmfusion-nonfree-nvidia-driver" in output: - DecoratorObject.SuccessMessage("RPM Fusion repository for Proprietary NVIDIA Driver detected") - return 0 - else: - DecoratorObject.WarningMessage("RPM Fusion repository for Proprietary NVIDIA Driver not detected") - while True: - userpick = input(Style.BRIGHT + Fore.YELLOW + "[ ! ]" + Style.RESET_ALL + " " + "Do you wish to fetch packages from this repository? (Y/N) ") - if userpick == "y" or userpick == "Y": - return 1 - elif userpick == "n" or userpick == "N": - return -1 - else: - DecoratorObject.FailureMessage("Connection to RPM Fusion server could not be established") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/RepoInstaller.py b/RepoInstaller.py index bfc70fa..e69de29 100644 --- a/RepoInstaller.py +++ b/RepoInstaller.py @@ -1,22 +0,0 @@ -import subprocess, os, sys -from colorama import init -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("FETCHING REPOSITORY DATA...") - os.system("dnf install -y fedora-workstation-repositories") - retndata = subprocess.getstatusoutput("dnf config-manager --set-enable rpmfusion-nonfree-nvidia-driver")[0] - if retndata == 0: - DecoratorObject.SuccessMessage("RPM Fusion NVIDIA repository was enabled") - os.system("dnf update --refresh") - DecoratorObject.SuccessMessage("Your packages have been updated") - else: - DecoratorObject.FailureMessage("RPM Fusion NVIDIA repository could not be enabled") - DecoratorObject.FailureMessage("Leaving installer") - sys.exit(0) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/SupportCheck.py b/SupportCheck.py deleted file mode 100644 index a571fe3..0000000 --- a/SupportCheck.py +++ /dev/null @@ -1,31 +0,0 @@ -import subprocess, sys -from colorama import init -from ColoramaCalls import StatusDecorator - -init() -DecoratorObject = StatusDecorator() - -def main(): - DecoratorObject.SectionHeader("CHECKING FOR GPU COMPATIBILITY...") - comand = "lspci | grep -E 'VGA|3D'" - prompt = subprocess.Popen(comand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output = prompt.communicate()[0].decode("utf-8") - linect = output.count("\n") - pkname = output.split("\n") - DecoratorObject.SuccessMessage("Compatibility infomation was obtained") - for indx in pkname: - if indx != "": - DecoratorObject.NormalMessage(indx) - if "NVIDIA" not in output: - DecoratorObject.FailureMessage("No supported NVIDIA GPU was detected!") - DecoratorObject.FailureMessage("Leaving installer with ERROR CODE - NVNF") - sys.exit(0) - else: - DecoratorObject.SuccessMessage("An active NVIDIA GPU was detected!") - if linect == 1: - DecoratorObject.SuccessMessage("An single dedicated GPU setup was detected!") - else: - DecoratorObject.SuccessMessage("An Optimus Dual GPU setup was detected!") - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..c95a4cd --- /dev/null +++ b/TODO.md @@ -0,0 +1,57 @@ +# To-do + +## Converting to Click composition tool +[Click](https://click.palletsprojects.com/en/7.x/) is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with sensible defaults out of the box. + +It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API. + +## Purpose of converting to composition options +The installer is under diverse development process now. It is self sufficient to just install the NVIDIA drivers right now but it is too limited to do this task only. The aim of this conversion is grow this installer into a capable NVIDIA manager. + +This planned manager would be then able to +- **Install** + - **NVIDIA drivers (without x86 libraries)** + By default, the Xorg x86 libraries are not required for general applications which are not based on x86 architecture - so it been done away in the default mode of installation. No option argument is required to trigger this type of installation. + - **NVIDIA drivers (with x86 libraries)** + As the Xorg x86 libraries are required for applications for Steam Proton, DXVK and Lutris, installing and configuring x86 libraries along with the driver installation would be a right thing to do. This installation mode can be selected during execution. + - **CUDA support softwares** + The CUDA support softwares are important for machine learning and deep learning applications so it would be only justified if the CUDA modules are installed along with drivers. This installation mode can be selected during execution. + - **NVENC/NVDEC for FFMPEG support** + RPM Fusion support ffmpeg compiled with NVENC/NVDEC with Fedora 25 and later. You need to have a recent NVIDIA card (see the support matrix), and install the cuda sub-package. This installation mode can be selected during execution. + - **Vulkan API for display rendering** + Vulkan is a low-overhead, cross-platform 3D graphics and computing API. Vulkan targets high-performance realtime 3D graphics applications such as interactive media across all platforms. This installation mode can be selected during execution. + - **VDPAU/VAAPI for video acceleration support** + With recent enough discrete NVIDIA GPU (any GPU with Geforce 8 series and above), video accleration can be provided to video players using these modules if they are installed. This installation mode can be selected during exectution. + +- **Uninstall** + - **NVIDIA drivers** + - **Xorg x86 libraries** + - **CUDA support softwares** + - **Vulkan (Fall back to OpenGL)** + - **VDPAU/VAAPI** + +- **Recover from binary installation** + - Installing via the NVIDIA's RUN binary available on the official website is truly a bad option. Just because it is general to most distributions, changes are not made keeping Fedora in mind so there are a lot of untracked changes. + - With that, even uninstalling and updating is difficult from the binary so this is definitely not a recommended way to get the proprietary drivers. If at all, you might have used it then this mode will help you clean up the mess made. + +## Modes of installation + +- **`--driver`** +This mode simply installs the NVIDIA driver +- **`--x86lib`** +This mode installs only the x86 libraries for Xorg +- **`--plcuda`** +This mode installs only the CUDA support softwares +- **`--ffmpeg`** +This mode installs only the FFMPEG acceleration +- **`--vulkan`** +This mode installs only the Vulkan renderer +- **`--vidacc`** +This mode installs only the VDPAU/VAAPI acceleration +- **`--getall`** +This mode installs all the above packages + +## Notes +- Some packages might overlap due to them being interdependent. In such cases, installation of an already installed package would be skipped and only the new package would be installed. +- Uninstalling some packages might fail with some packages as there are other packages dependent on it. If you are persistent on removing them, you are better off removing the dependent apps first. +- If you are a machine learning enthusiast or an avid gaming or multimedia fan, the simplest way would be to install all the packages provided herewith using the **`--getall`** mode of installation. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4ae7986..1e467c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ +click==7.1.2 colorama==0.4.3 +distro==1.5.0