Пример #1
0
func main() {
	flag.Parse()
	fmt.Println(os.Args)

	v2rayOS := parseOS(*targetOS)
	v2rayArch := parseArch(*targetArch)

	version, err := git.RepoVersionHead()
	if version == git.VersionUndefined {
		version = "custom"
	}
	if err != nil {
		fmt.Println("Unable to detect V2Ray version: " + err.Error())
		return
	}
	fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)
	version = "v1.0"

	targetDir, err := createTargetDirectory(version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to create directory " + targetDir + ": " + err.Error())
	}

	targetFile := getTargetFile(v2rayOS)
	err = buildV2Ray(filepath.Join(targetDir, targetFile), version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to build V2Ray: " + err.Error())
	}

	err = copyConfigFiles(targetDir, v2rayOS)
	if err != nil {
		fmt.Println("Unable to copy config files: " + err.Error())
	}
}
Пример #2
0
func build(targetOS, targetArch string, archive bool, version string, metadataFile string) {
	v2rayOS := parseOS(targetOS)
	v2rayArch := parseArch(targetArch)

	if len(version) == 0 {
		v, err := git.RepoVersionHead()
		if v == git.VersionUndefined {
			v = "custom"
		}
		if err != nil {
			fmt.Println("Unable to detect V2Ray version: " + err.Error())
			return
		}
		version = v
	}
	fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)

	targetDir, err := createTargetDirectory(version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to create directory " + targetDir + ": " + err.Error())
	}

	targetFile := getTargetFile(v2rayOS)
	err = buildV2Ray(filepath.Join(targetDir, targetFile), version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to build V2Ray: " + err.Error())
	}

	err = copyConfigFiles(targetDir, v2rayOS)
	if err != nil {
		fmt.Println("Unable to copy config files: " + err.Error())
	}

	if archive {
		err := os.Chdir(binPath)
		if err != nil {
			fmt.Printf("Unable to switch to directory (%s): %v\n", binPath, err)
		}
		suffix := getSuffix(v2rayOS, v2rayArch)
		zipFile := "v2ray" + suffix + ".zip"
		root := filepath.Base(targetDir)
		err = zipFolder(root, zipFile)
		if err != nil {
			fmt.Printf("Unable to create archive (%s): %v\n", zipFile, err)
		}

		metadataWriter, err := os.OpenFile(filepath.Join(binPath, metadataFile), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
		if err != nil {
			fmt.Printf("Unable to create metadata file (%s): %v\n", metadataFile, err)
		}
		defer metadataWriter.Close()

		err = CalcMetadata(zipFile, metadataWriter)
		if err != nil {
			fmt.Printf("Failed to calculate metadata for file (%s): %v", zipFile, err)
		}
	}
}
Пример #3
0
func main() {
	flag.Parse()

	v2rayOS := parseOS(*targetOS)
	v2rayArch := parseArch(*targetArch)

	version, err := git.RepoVersionHead()
	if version == git.VersionUndefined {
		version = "custom"
	}
	if err != nil {
		fmt.Println("Unable to detect V2Ray version: " + err.Error())
		return
	}
	fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)

	targetDir, err := createTargetDirectory(version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to create directory " + targetDir + ": " + err.Error())
	}

	targetFile := getTargetFile(v2rayOS)
	err = buildV2Ray(filepath.Join(targetDir, targetFile), version, v2rayOS, v2rayArch)
	if err != nil {
		fmt.Println("Unable to build V2Ray: " + err.Error())
	}

	err = copyConfigFiles(targetDir, v2rayOS)
	if err != nil {
		fmt.Println("Unable to copy config files: " + err.Error())
	}

	if *archive {
		GOPATH := os.Getenv("GOPATH")
		binPath := filepath.Join(GOPATH, "bin")
		err := os.Chdir(binPath)
		if err != nil {
			fmt.Printf("Unable to switch to directory (%s): %v\n", binPath, err)
		}
		suffix := getSuffix(v2rayOS, v2rayArch)
		zipFile := "v2ray" + suffix + ".zip"
		root := filepath.Base(targetDir)
		err = zipFolder(root, zipFile)
		if err != nil {
			fmt.Println("Unable to create archive (%s): %v\n", zipFile, err)
		}
	}
}