示例#1
0
func main() {
	if len(os.Args) < 2 || os.Args[1] == "-h" {
		fmt.Println("Please supply a page id!\nUsage: PageAction [pageName] [args...]")
		fmt.Println("      		   [setup]")
		fmt.Println("      		   [suggestion]")
		fmt.Println("      		   [install_config] [location] [execlocation]")
		fmt.Println("      		   [install_dependency]")
		fmt.Println("      		   [installation] [nextpage|install]")
		fmt.Println("      		   [device_setup] [nextpage|install]")
		fmt.Println("      		   [deploy_samples] [nextpage|install]")
		fmt.Println("      		   [finished]")
		fmt.Println("      		   [query] [compName]")
		os.Exit(-1)
	}
	if os.Args[1] == "query" {
		//query whethter the component selected
		compName := os.Args[2]
		if global.ComponentSelect(compName) {
			fmt.Println("0")
		} else {
			fmt.Println("-1")
		}
		os.Exit(0)
	}
	pkgname := os.Args[1]
	if comp, ok := comps[pkgname]; ok {
		comp.PostAction(os.Args[2:]...)
	} else {
		fmt.Println("the pageName is invalidate")
	}
}
示例#2
0
func (ds *DeviceSetup) PostAction(args ...string) {
	//device_setup nextpage|install
	action := args[0]

	if action == "nextpage" {
		//set the NextPage
		if global.ComponentSelect("allowcompile") {
			ds.NextPage = "deploy_samples"
		} else {
			ds.NextPage = "finished"
		}
		fmt.Println(ds.NextPage)
	} else if action == "install" {
		if len(args) < 2 {
			fmt.Println(`Wrong args input. Please input as followings
			PageAction device_setup install [installdir]`)
			os.Exit(-1)
		}
		installdir := args[1]
		adb_path := filepath.Join(installdir, "android-sdk-linux", "platform-tools", "adb")
		console := filepath.Join(installdir, "console")

		//deploy the cuda runtime to devices
		//fmt.Println("the devices have been detected: ", global.Detect_devices(installdir))
		if global.Detect_devices(installdir) {
			//device is arm64-v8a
			exec.Command(adb_path, "wait-for-device").Output()
			oe, re := exec.Command(adb_path, "root").Output()
			if re != nil || strings.Contains(string(oe), "adbd cannot run as root in production builds") {
				//adb root error
				fmt.Println("Your device is not connected or not allowed adb root.")
				os.Exit(2)
			}
			cuda_runtime := filepath.Join(installdir, "cuda-android-7.0", "aarch64-linux-androideabi")
			cuda_device := "/data/cuda-toolkit-7.0"
			_, e := exec.Command(console, "-t", "Pushing cuda-toolkit-7.0", adb_path+" push "+cuda_runtime+" "+cuda_device).Output()
			if e != nil {
				fmt.Print(e)
				os.Exit(2)
			}
		} else {
			//device is armeabi-v7a
			exec.Command(adb_path, "wait-for-device").Output()
			oe, re := exec.Command(adb_path, "root").Output()
			if re != nil || strings.Contains(string(oe), "adbd cannot run as root in production builds") {
				//adb root error
				fmt.Println("Your device is not connected or not allowed adb root.")
				os.Exit(2)
			}
			cuda_runtime := filepath.Join(installdir, "cuda-android-6.5")
			cuda_device := "/data/cuda-toolkit-6.0"
			_, e := exec.Command(console, "-t", "Pushing cuda-toolkit-6.5", adb_path+" push "+cuda_runtime+" "+cuda_device).Output()
			if e != nil {
				fmt.Print(e)
				os.Exit(2)
			}
		}
	} else {
		fmt.Println("Wrong args input.")
		os.Exit(-1)
	}

}
示例#3
0
func (f *Finished) PostAction(args ...string) {
	//finished page actions
	//option
	option := args[0]

	installdir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		panic(err)
	}

	if option == "create_shortcut" {
		if global.Global_OS == "windows" {
			win_sc_folder := filepath.Join(os.Getenv("APPDATA"), "Microsoft", "Windows", "Start Menu", "Programs", "NIDIA Corporation")
			cmd := os.Getenv("ComSpec")
			if global.ComponentSelect("docs") {
				exec.Command(cmd, "/c", `mklink "AndroidWorks Docs" `+filepath.Join(installdir, "docs", "index.html")).Output()
				os.Rename("AndroidWorks Docs", win_sc_folder)
			}

		}
		return
	}

	if option == "remove_logs" {
		os.RemoveAll(filepath.Join(installdir, "_installer"))
	}

	if option == "browse_docs" {
		var url string
		if global.ComponentSelect("docs") {
			installdir = strings.Replace(installdir, "\\", "/", -1)
			//url = "file://" + installdir + "/docs/index.html"
			url = filepath.Join(installdir, "docs", "index.html")

		} else {
			url = "http://docs.nvidia.com/gameworks/index.html#developertools/mobile/androidworks/androidworks.htm"
		}
		global.OpenDocs(url)
		return
	}
	if option == "restart" {
		exec.Command(os.Getenv("ComSpec"), "/c", "shutdown /r /f").Output()
		return
	}

	if option == "browse_ibdocs" {
		//browse the incredibuild docs (incredibuild.chm)
		e1 := exec.Command("cmd", "/c", filepath.Join(os.Getenv("ProgramFiles(x86)"), "Xoreax", "IncrediBuild", "IncrediBuild.chm")).Start()
		if e1 != nil {
			fmt.Println(e1)
			os.Exit(2)
		}

	}

	if option == "create_workspace" {
		var create_workspace = 0
		//create the nvsample workspace for eclipse
		if global.ComponentSelect("eclipse") {
			if global.ComponentSelect("tdksample") || global.ComponentSelect("opencv") ||
				global.ComponentSelect("cudasamples65") || global.ComponentSelect("cudasamples70") {
				create_workspace = 1
			}
		}
		//fmt.Println(create_workspace)
		if create_workspace == 1 {
			var eclipse string
			if global.Global_OS == "windows" {
				eclipse = filepath.Join(installdir, "eclipse", "eclipse.exe")
			} else {
				eclipse = filepath.Join(installdir, "eclipse", "eclipse")
			}
			if global.ComponentSelect("tdksample") {
				exec.Command(eclipse, "-nosplash", "-data", filepath.Join(installdir, "nvsample_workspace"),
					"-application", "org.eclipse.cdt.managedbuilder.core.headlessbuild", "-importAll",
					filepath.Join(installdir, "Samples", "TDK_Samples")).Output()
				//fmt.Println(e)
			}
			if global.ComponentSelect("opencv") {
				exec.Command(eclipse, "-nosplash", "-data", filepath.Join(installdir, "nvsample_workspace"),
					"-application", "org.eclipse.cdt.managedbuilder.core.headlessbuild", "-importAll",
					filepath.Join(installdir, "OpenCV-2.4.8.2-Tegra-sdk")).Output()
			}
			if global.ComponentSelect("cudasamples65") || global.ComponentSelect("cudasamples70") {
				var cudasample_path = filepath.Join(installdir, "CUDA_Samples")
				if global.Exist(filepath.Join(installdir, "CUDA_Samples", "7.0")) {
					cudasample_path = filepath.Join(cudasample_path, "7.0")
				} else {
					cudasample_path = cudasample_path
				}

				exec.Command(eclipse, "-nosplash", "-data", filepath.Join(installdir, "nvsample_workspace"),
					"-application", "org.eclipse.cdt.managedbuilder.core.headlessbuild", "-importAll",
					filepath.Join(installdir, "Samples", cudasample_path)).Output()
			}
		}
	}
}
示例#4
0
func (i *Installation) PostAction(args ...string) {
	if len(args) < 1 {
		fmt.Println("Please input the option nextpage|install to continue")
		os.Exit(-1)
	}
	option := args[0]

	if option == "nextpage" {
		i.NextPage = "finished"

		if global.ComponentSelect("drivertools") {
			i.NextPage = "device_setup"
		} else if global.ComponentSelect("allowcompile") {
			i.NextPage = "deploy_samples"
		} else {
			i.NextPage = "finished"
		}
		fmt.Println(i.NextPage)
	} else if option == "install" {
		//copy the files to the installdir
		if len(args) < 4 {
			fmt.Println("Please input the args as followings ")
			fmt.Println("PageAction installation install [pksrc] [installdir] [exefile]")
			os.Exit(2)
		}
		pksrc := args[1]
		installdir := args[2]
		exefile := args[3]

		if _, e1 := os.Stat(installdir); e1 != nil {
			os.Mkdir(installdir, 0777)
		}

		if _, se := os.Stat(filepath.Join(installdir, "_installer")); se != nil {
			os.Mkdir(filepath.Join(installdir, "_installer"), 0777)
		}
		e := global.CopyFileExp(pksrc, installdir, exefile)
		if e != nil {
			fmt.Println(e)
		}
		//fmt.Println(os.Args[0])

		if global.Global_OS == "darwin" {
			global.CopyFile(os.Args[0], filepath.Join(installdir, "PageAction"))
			os.Chmod(filepath.Join(installdir, "PageAction"), 0777)
		} else if global.Global_OS == "linux" {
			//add the Chooser to desktop entry
			chooser_entry := `[Desktop Entry]
Type=Application
Name=AndroidWorks Component Manager
GenericName=AndroidWorks Component Manager
Icon=` + filepath.Join(installdir, "TegraDeveloperKit.ico") + `
Exec=` + filepath.Join(installdir, "Chooser") + `
TryExec=` + filepath.Join(installdir, "Chooser") + `
Keywords=androidworks;nvidia;
Terminal=No
Categories=Development;`
			entry_folder := os.Getenv("HOME") + "/.local/share/applications"
			if _, se := os.Stat(entry_folder); se != nil {
				//fmt.Println("no folder exist")
				_, ce := exec.Command("mkdir", "-p", entry_folder).Output()
				if ce != nil {
					fmt.Println(ce)
				}
			}
			fp, fe := os.OpenFile(entry_folder+"/AndroidWorks.desktop", os.O_CREATE|os.O_RDWR, 0600)
			if fe != nil {
				fmt.Println(fe)
			}
			fp.WriteString(chooser_entry)
		}
		//set the uninstaller to the registery
		if global.Global_OS == "windows" {
			_, e0 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "DisplayVersion", "/d", `1R1`, "/f").Output()
			_, e1 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "NoModify", "/d", "0", "/f").Output()
			_, e2 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "Publisher", "/d", `NVIDIA Corpration`, "/f").Output()
			_, e3 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "DisplayIcon", "/d", filepath.Join(installdir, "Chooser.exe"), "/f").Output()
			_, e4 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "ModifyPath", "/d", filepath.Join(installdir, "Chooser.exe"), "/f").Output()
			_, e5 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "UninstallString", "/d", filepath.Join(installdir, "Uninstaller.bat"), "/f").Output()
			_, e6 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\microsoft\windows\CurrentVersion\Uninstall\NVIDIA AndroidWorks`, "/v", "DisplayName", "/d", `NVIDIA AndroidWorks`, "/f").Output()

			if e0 != nil || e1 != nil || e2 != nil || e3 != nil || e4 != nil || e5 != nil || e6 != nil {
				fmt.Println(e1, e2, e3, e4, e5, e6)
			}

			df, _ := os.OpenFile(filepath.Join(installdir, "uninstaller.bat"), os.O_CREATE|os.O_RDWR, 0777)
			_, e7 := df.WriteString("@cd %~dp0\r\n@set /a count=0\r\n@start /wait Chooser.exe -u -v\r\n" +
				"@ping 127.0.0.1 -n 10 -w 1000>null\r\n" + ":Repeat\r\n" + "@del Chooser.exe\r\n" + "@set /a count=%count%+1\r\n" +
				"@ping 127.0.0.1 -n 3 -w 1000>null\r\n" + "@if exist Chooser.exe (\r\n" + "@if %count NEQ 60 goto Repeat\r\n" + ")\r\n" +
				"@reg delete \"HKLM\\Software\\Wow6432Node\\microsoft\\windows\\CurrentVersion\\Uninstall\\NVIDIA AndroidWorks\" /f\r\n" +
				"@rmdir /S /Q " + installdir + "\r\n@del null\r\n" + "@del Uninstaller.bat\r\n")
			if e7 != nil {
				fmt.Println(e7)
			}
			//add the AndroidWorks to HKLM\Software\Wow6432Node\NVIDIA Corporation\AndroidWorks
			_, e8 := exec.Command("reg", "add", `HKLM\Software\Wow6432Node\NVIDIA Corporation\AndroidWorks`, "/v", "Location", "/d", installdir, "/f").Output()
			if e8 != nil {
				fmt.Println(e8)
			}
		}
	}

}