Ejemplo n.º 1
0
func selfUpdate() {
	prefixB, err := kmgHttp.UrlGetContent("http://kmgtools.qiniudn.com/v1/kmgUrlPrefix.txt?v=" + kmgRand.MustCryptoRandToAlphaNum(16))
	kmgConsole.ExitOnErr(err)

	exeContent, err := kmgHttp.UrlGetContent(string(prefixB) + "_windows_amd64.exe")
	kmgConsole.ExitOnErr(err)

	//cmd 这个东西有超级神力,直接os.Rename不行 但是360会报警
	// 已经试过下列方案:
	// 1.os.Rename 后面的write会没有权限,原因不明
	// 2.move windows上面没有这个命令
	kmgCmd.ProxyRun(`cmd /c move C:\windows\system32\kmg.exe C:\windows\system32\kmg-old.exe`)

	kmgFile.MustWriteFile(`C:\windows\system32\kmg.exe`, exeContent)
}
Ejemplo n.º 2
0
func selfUpdate() {
	baseFileContent, err := kmgHttp.UrlGetContent("http://kmgtools.qiniudn.com/v1/installKmg.bash?v=" + kmgRand.MustCryptoRandToAlphaNum(16))
	kmgConsole.ExitOnErr(err)

	baseFilePath := "/tmp/installKmg.bash"
	kmgFile.MustDeleteFile(baseFilePath)
	kmgFile.MustAppendFile(baseFilePath, baseFileContent)
	kmgCmd.MustRunInBash(baseFilePath)
}
Ejemplo n.º 3
0
// 通知验证接口
// 和支付宝手机接口一模一样.
func (ot *OverseaTrade) VerifyNotify(NotifyId string) (err error) {
	u := kmgHttp.MustSetParameterMapToUrl("https://mapi.alipay.com/gateway.do", map[string]string{
		"service":   "notify_verify",
		"partner":   ot.PartnerId,
		"notify_id": NotifyId,
	})
	content, err := kmgHttp.UrlGetContent(u)
	if err != nil {
		return err
	}
	if !bytes.Equal(content, []byte(`true`)) {
		return fmt.Errorf("notify_id verify fail")
	}
	return nil
}
Ejemplo n.º 4
0
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")
}