示例#1
0
//由于bash过度难用,直接安装kmg的时候又会遇到很复杂的情况,此处用于处理某些复杂情况
func selfInstallCmd() {
	//迁移代码,从/bin/kmg迁移到/usr/local/bin/kmg
	if kmgFile.MustFileExist("/bin/kmg") {
		kmgCmd.MustRunInBash("sudo rm /bin/kmg;hash -r")
	}
	kmgFile.MustEnsureBinPath("/usr/local/bin/kmg")
}
示例#2
0
文件: install.go 项目: keysonZZZ/kmg
func installGolangWithUrlMap(urlMap map[string]string) {
	p := kmgPlatform.GetCompiledPlatform()
	if p.Compatible(kmgPlatform.WindowsAmd64) {
		contentB, err := kmgHttp.UrlGetContent(urlMap["windows_amd64"])
		kmgConsole.ExitOnErr(err)
		kmgFile.MustDelete(`c:\go`)
		err = kmgCompress.ZipUncompressFromBytesToDir(contentB, `c:\go`, "go")
		kmgConsole.ExitOnErr(err)
		err = kmgFile.CopyFile(`c:\go\bin\go.exe`, `c:\windows\system32\go.exe`)
		kmgConsole.ExitOnErr(err)
		err = kmgFile.CopyFile(`c:\go\bin\godoc.exe`, `c:\windows\system32\godoc.exe`)
		kmgConsole.ExitOnErr(err)
		err = kmgFile.CopyFile(`c:\go\bin\gofmt.exe`, `c:\windows\system32\gofmt.exe`)
		kmgConsole.ExitOnErr(err)
		return
	}
	tmpPath := kmgFile.MustChangeToTmpPath()
	defer kmgFile.MustDelete(tmpPath)
	if !kmgSys.MustIsRoot() {
		fmt.Println("you need to be root to install golang")
		return
	}

	url, ok := urlMap[p.String()]
	if !ok {
		kmgConsole.ExitOnErr(fmt.Errorf("not support platform [%s]", p))
	}
	packageName := path.Base(url)
	contentB := kmgHttp.MustUrlGetContentProcess(url)

	kmgFile.MustWriteFile(packageName, contentB)
	kmgCmd.ProxyRun("tar -xf " + packageName)
	if kmgFile.MustFileExist("/usr/local/go") {
		kmgCmd.ProxyRun("mv /usr/local/go /usr/local/go.bak." + time.Now().Format(kmgTime.FormatFileNameV2))
	}
	kmgCmd.ProxyRun("cp -rf go /usr/local")
	kmgFile.MustDeleteFile("/bin/go")
	kmgCmd.ProxyRun("ln -s /usr/local/go/bin/go /bin/go")
	kmgFile.MustDeleteFile("/bin/godoc")
	kmgCmd.ProxyRun("ln -s /usr/local/go/bin/godoc /bin/godoc")
	kmgFile.MustDeleteFile("/bin/gofmt")
	kmgCmd.ProxyRun("ln -s /usr/local/go/bin/gofmt /bin/gofmt")
	kmgFile.MustEnsureBinPath("/bin/go")
	kmgFile.MustEnsureBinPath("/bin/godoc")
	kmgFile.MustEnsureBinPath("/bin/gofmt")
}