cos-gpu-installer: add --nvidia-installer-url-open flag

Add the "-nvidia-installer-url-open" flag

This enables installation of GSP firmware and user-space NVIDIA GPU
driver components from a corresponding OSS driver release from an arbitrary URL.
It is useful for testing and debugging.

This separate flag is chosen over the existing -nvidia-installer-url flag to
specify the location as the -nvidia-installer-url flag cannot operate with the
-version flag, which is required to find the OSS prebuilt kernel modules.

BUG=b/297371653
TEST=install OSS drivers with installer runfile from custom location.

Change-Id: Ic35adeb7bd4c762bd72ca37ffee60f636f2e932c
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/56307
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
Tested-by: Arnav Kansal <rnv@google.com>
Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com>
diff --git a/src/cmd/cos_gpu_installer/internal/commands/install.go b/src/cmd/cos_gpu_installer/internal/commands/install.go
index c33b522..34bb411 100644
--- a/src/cmd/cos_gpu_installer/internal/commands/install.go
+++ b/src/cmd/cos_gpu_installer/internal/commands/install.go
@@ -103,20 +103,21 @@
 
 // InstallCommand is the subcommand to install GPU drivers.
 type InstallCommand struct {
-	driverVersion      string
-	hostInstallDir     string
-	unsignedDriver     bool
-	gcsDownloadBucket  string
-	gcsDownloadPrefix  string
-	nvidiaInstallerURL string
-	signatureURL       string
-	debug              bool
-	test               bool
-	prepareBuildTools  bool
-	kernelOpen         bool
-	noVerify           bool
-	kernelModuleParams modules.ModuleParameters
-	selfPrecompiled    bool
+	driverVersion          string
+	hostInstallDir         string
+	unsignedDriver         bool
+	gcsDownloadBucket      string
+	gcsDownloadPrefix      string
+	nvidiaInstallerURL     string
+	signatureURL           string
+	debug                  bool
+	test                   bool
+	prepareBuildTools      bool
+	kernelOpen             bool
+	noVerify               bool
+	kernelModuleParams     modules.ModuleParameters
+	selfPrecompiled        bool
+	nvidiaInstallerURLOpen string
 }
 
 // Name implements subcommands.Command.Name.
@@ -156,6 +157,7 @@
 			"This flag must be used with `-allow-unsigned-driver`. This flag is only for debugging and testing.")
 	f.StringVar(&c.signatureURL, "signature-url", "",
 		"A URL to the driver signature. This flag can only be used together with `-test` and `-nvidia-installer-url` for for debugging and testing.")
+	f.StringVar(&c.nvidiaInstallerURLOpen, "nvidia-installer-url-open", "", "This can be used to specify the location of the GSP firmware and user-space NVIDIA GPU driver components from a corresponding driver release of the OSS kernel modules. This flag is only for debugging and testing.")
 	f.BoolVar(&c.debug, "debug", false,
 		"Enable debug mode.")
 	f.BoolVar(&c.test, "test", false,
@@ -177,6 +179,9 @@
 	if c.signatureURL != "" && (c.nvidiaInstallerURL == "" || c.test == false) {
 		return stderrors.New("-signature-url must be used with -nvidia-installer-url and -test")
 	}
+	if c.nvidiaInstallerURLOpen != "" && (c.driverVersion == "" || c.test == false) {
+		return stderrors.New("-nvidia-installer-url-open must be used with -test and -version")
+	}
 	return nil
 }
 
@@ -257,7 +262,7 @@
 
 	var cacher *installer.Cacher
 	// We only want to cache drivers installed from official sources.
-	if c.nvidiaInstallerURL == "" {
+	if c.nvidiaInstallerURL == "" && c.nvidiaInstallerURLOpen == "" {
 		cacher = installer.NewCacher(hostInstallDir, envReader.BuildNumber(), c.driverVersion)
 		if isCached, isOpen, err := cacher.IsCached(); isCached && err == nil {
 			log.V(2).Info("Found cached version, NOT building the drivers.")
@@ -426,7 +431,12 @@
 	}
 	defer func() { callback <- 0 }()
 
-	installerFile, err := installer.DownloadGenericDriverInstaller(c.driverVersion)
+	var installerFile string
+	if c.nvidiaInstallerURLOpen == "" {
+		installerFile, err = installer.DownloadGenericDriverInstaller(c.driverVersion)
+	} else {
+		installerFile, err = installer.DownloadToInstallDir(c.nvidiaInstallerURLOpen, "Unofficial GPU driver installer")
+	}
 	if err != nil {
 		return err
 	}