Esempio n. 1
0
func httpsCertCsrCLI() {
	domain := ""
	outDir := ""
	flag.StringVar(&domain, "domain", "", "the domain need to generate csr(google.com)")
	flag.StringVar(&outDir, "outDir", "", "the output dir(default to ./doc/cert/{domain})")
	flag.Parse()
	if domain == "" {
		flag.Usage()
		os.Exit(1)
	}
	if outDir == "" {
		outDir = "doc/cert/" + domain
	}
	kmgFile.Mkdir(outDir)
	kmgCmd.CmdSlice([]string{"openssl", "req", "-out", "domain.csr", "-new", "-newkey", "rsa:4096", "-nodes",
		"-keyout", "domain.key", "-subj", "/C=US/ST=US/L=US/O=US/OU=US/CN=" + domain + "/"}).SetDir(outDir).ProxyRun()
}
Esempio n. 2
0
File: zip.go Progetto: keysonZZZ/kmg
func ZipUncompressFromBytesToDir(zipB []byte, dir string, trimPrefix string) (err error) {
	buf := bytes.NewReader(zipB)
	reader, err := zip.NewReader(buf, int64(len(zipB)))
	if err != nil {
		kmgErr.LogErrorWithStack(err)
		return
	}
	for _, file := range reader.File {

		fullPath := filepath.Join(dir, strings.TrimPrefix(file.Name, trimPrefix))
		if file.FileInfo().IsDir() {
			err = kmgFile.Mkdir(fullPath)
			if err != nil {
				kmgErr.LogErrorWithStack(err)
				return
			}
			continue
		}
		err = kmgFile.MkdirForFile(fullPath)
		if err != nil {
			kmgErr.LogErrorWithStack(err)
			return
		}
		rc, err := file.Open()
		if err != nil {
			kmgErr.LogErrorWithStack(err)
			return err
		}
		f, err := os.Create(fullPath)
		if err != nil {
			kmgErr.LogErrorWithStack(err)
			rc.Close()
			return err
		}
		_, err = io.Copy(f, rc)
		rc.Close()
		f.Close()
		if err != nil {
			kmgErr.LogErrorWithStack(err)
			return err
		}
	}
	return nil
}
Esempio n. 3
0
func TestGitFixNameCaseWithFile(ot *testing.T) {
	oldWd, err := os.Getwd()
	kmgTest.Equal(err, nil)
	kmgFile.MustDelete("testfile")
	kmgFile.Mkdir("testfile")
	os.Chdir("testfile")
	defer os.Chdir(oldWd)
	kmgFile.MustWriteFile("a.txt", []byte("abc"))
	kmgCmd.MustRun("git init")
	kmgCmd.MustRun("git add -A")
	kmgCmd.MustRun("git commit -am'save'")
	err = os.Rename("a.txt", "A.txt")
	kmgTest.Equal(err, nil)

	err = GitFixNameCase(filepath.Join(oldWd, "testfile"))
	kmgTest.Equal(err, nil)

	kmgCmd.MustRun("git status")
	kmgCmd.MustRun("git add -A")
	kmgCmd.MustRun("git commit -am'save'")
}
Esempio n. 4
0
func init() {
	if defaultEnv.Env != nil {
		kmgFile.Mkdir(defaultEnv.Env.LogPath)
	}
}