we add the pve-nvidia-vgpu-helper script to make the installation of the
required nvidia vgpu driver dependencies more convenient.
We also add a Makefile to assist in building the debian package and
installing the script

Signed-off-by: Hannes Duerr <h.du...@proxmox.com>
---
 Makefile               | 54 ++++++++++++++++++++++++++++++++++++
 pve-nvidia-vgpu-helper | 63 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 Makefile
 create mode 100755 pve-nvidia-vgpu-helper

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c6e461d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,54 @@
+include /usr/share/dpkg/default.mk
+
+PACKAGE=pve-nvidia-vgpu-helper
+
+BINDIR=/usr/bin/
+DESTDIR=
+
+GITVERSION:=$(shell git rev-parse HEAD)
+
+BUILDDIR ?= $(PACKAGE)-$(DEB_VERSION)
+DSC=$(PACKAGE)_$(DEB_VERSION).dsc
+
+DEB=$(PACKAGE)_$(DEB_VERSION_UPSTREAM_REVISION)_all.deb
+
+all:
+deb: $(DEB)
+
+$(BUILDDIR): debian
+       rm -rf $@ $@.tmp
+       rsync -a * $@.tmp/
+       echo "git clone 
git://git.proxmox.com/git/pve-nvidia-vgpu-helper.git\\ngit checkout 
$(GITVERSION)" > $@.tmp/debian/SOURCE
+       mv $@.tmp $@
+
+$(DEB): $(BUILDDIR)
+       cd $(BUILDDIR); dpkg-buildpackage -b -uc -us
+       lintian $(DEB)
+
+dsc: $(DSC)
+       $(MAKE) clean
+       $(MAKE) $(DSC)
+       lintian $(DSC)
+
+$(DSC): $(BUILDDIR)
+       cd $(BUILDDIR); dpkg-buildpackage -S -uc -us
+
+sbuild: $(DSC)
+       sbuild $(DSC)
+
+.PHONY: install
+install: pve-nvidia-vgpu-helper
+       install -d $(DESTDIR)$(BINDIR)
+       install -m 0755 pve-nvidia-vgpu-helper $(DESTDIR)$(BINDIR)
+
+.PHONY: upload
+upload: UPLOAD_DIST ?= $(DEB_DISTRIBUTION)
+upload: $(DEB)
+       tar cf - $(DEB)|ssh repo...@repo.proxmox.com -- upload --product pve 
--dist $(UPLOAD_DIST)
+
+.PHONY: distclean
+distclean: clean
+
+.PHONY: clean
+clean:
+       rm -rf *~ $(PACKAGE)-[0-9]*/ $(PACKAGE)*.tar.* *.deb *.dsc *.changes 
*.build *.buildinfo
diff --git a/pve-nvidia-vgpu-helper b/pve-nvidia-vgpu-helper
new file mode 100755
index 0000000..885b879
--- /dev/null
+++ b/pve-nvidia-vgpu-helper
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use PVE::Tools qw(run_command);
+use AptPkg::Cache;
+
+my @apt_install = qw(apt-get --no-install-recommends install --);
+my @dependencies = qw(dkms libc6-dev proxmox-default-headers);
+my @missing_packages;
+
+die "Please execute the script with root privileges\n" if $>;
+
+my $apt_cache = AptPkg::Cache->new();
+die "unable to initialize AptPkg::Cache\n" if !$apt_cache; 
+
+sub package_is_installed {
+    my ($package) = @_;
+    my $p = $apt_cache->{$package};
+    if (!defined($p->{CurrentState}) || $p->{CurrentState} ne "Installed") {
+       push(@missing_packages, $package);
+    }
+}
+
+foreach my $dependency (@dependencies) {
+    package_is_installed($dependency);
+}
+
+
+my $running_kernel;
+run_command( ['/usr/bin/uname', '-r' ],
+    outfunc => sub { $running_kernel = shift } );
+
+run_command(['/usr/bin/dpkg-query', '-W', 'proxmox-kernel-*-pve'],
+    outfunc => sub {
+       my $installed_kernel = shift;
+       $installed_kernel =~ 
s/^\s*proxmox-kernel(-\d+.\d+.\d+-\d+-pve)\s*$/proxmox-headers$1/;
+       package_is_installed($installed_kernel);
+    });
+
+
+
+if ($running_kernel =~ m/^\d+\.\d+\.\d+-\d+-pve$/) {
+    print "You are running the proxmox kernel 
`proxmox-kernel-$running_kernel`\n";
+} else {
+    die "You are not using a proxmox-kernel, please make sure that the 
appropriate header package is installed.\n";
+}
+
+if (!@missing_packages){
+    print "All required packages are installed, you can continue with the 
Nvidia vGPU driver installation.\n";
+    exit;
+} else {
+    print "The following packages are missing:\n" . join("\n", 
@missing_packages) ."\n";
+    print "Would you like to install them now (y/n)?\n";
+}
+
+my $answer = <STDIN>;
+if (defined($answer) && $answer =~ m/^\s*y(?:es)?\s*$/i) {
+    if (system(@apt_install, @missing_packages) != 0) {
+       die "apt failed during the installation: ($?)\n";
+    }
+}
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to