Example #1
0
func (e Env) runFleetCmdInternal(getOutput bool, args ...string) (string, error) {
	if e.config.Fleet.Endpoint == "" {
		return "", errors.New("Cannot find fleet.endpoint env config to call fleetctl")
	}
	endpoint := "http://" + e.config.Fleet.Endpoint
	os.Setenv(FLEETCTL_ENDPOINT, endpoint)
	if e.config.Fleet.Username != "" {
		os.Setenv(FLEETCTL_SSH_USERNAME, e.config.Fleet.Username)
	}
	os.Setenv(FLEETCTL_STRICT_HOST_KEY_CHECKING, fmt.Sprintf("%t", e.config.Fleet.Strict_host_key_checking))
	os.Setenv(FLEETCTL_SUDO, fmt.Sprintf("%t", e.config.Fleet.Sudo))

	var out string
	var err error
	if getOutput {
		out, err = cntUtils.ExecCmdGetOutput("fleetctl", args...)
	} else {
		err = cntUtils.ExecCmd("fleetctl", args...)
	}

	os.Setenv(FLEETCTL_ENDPOINT, "")
	os.Setenv(FLEETCTL_SSH_USERNAME, "")
	os.Setenv(FLEETCTL_STRICT_HOST_KEY_CHECKING, "")
	os.Setenv(FLEETCTL_SUDO, "")
	return out, err
}
Example #2
0
func checkRktVersion() {
	output, err := utils.ExecCmdGetOutput("rkt")
	if err != nil {
		panic("rkt is required in PATH")
	}

	scanner := bufio.NewScanner(strings.NewReader(output))
	for scanner.Scan() {
		line := scanner.Text()
		if strings.TrimSpace(line) == "VERSION:" {
			scanner.Scan()
			versionString := strings.TrimSpace(scanner.Text())
			version, err := semver.NewVersion(versionString)
			if err != nil {
				panic("Cannot parse version of rkt" + versionString)
			}
			supported, _ := semver.NewVersion(RKT_SUPPORTED_VERSION)
			if version.LessThan(*supported) {
				panic("rkt version in your path is too old. Require >= " + RKT_SUPPORTED_VERSION)
			}
			break
		}
	}

}
Example #3
0
func checkFleetVersion() {
	output, err := utils.ExecCmdGetOutput("fleetctl")
	if err != nil {
		log.Fatal("fleetctl is required in PATH")
	}

	scanner := bufio.NewScanner(strings.NewReader(output))
	for scanner.Scan() {
		line := scanner.Text()
		if strings.TrimSpace(line) == "VERSION:" {
			scanner.Scan()
			versionString := strings.TrimSpace(scanner.Text())
			version, err := semver.NewVersion(versionString)
			if err != nil {
				log.Error("Cannot parse version of fleetctl", versionString)
				os.Exit(1)
			}
			supported, _ := semver.NewVersion(FLEET_SUPPORTED_VERSION)
			if version.LessThan(*supported) {
				log.Error("fleetctl version in your path is too old. Require >= " + FLEET_SUPPORTED_VERSION)
				os.Exit(1)
			}
			break
		}
	}
}
Example #4
0
func init() {
	cntConfig = CntConfig{Path: "/root/.config/cnt"}
	user := os.Getenv("SUDO_USER")
	if user != "" {
		home, err := utils.ExecCmdGetOutput("bash", "-c", "echo ~"+user)
		if err != nil {
			panic("Cannot find user home" + err.Error())
		}
		cntConfig.Path = home + "/.config/cnt"
	}
	//	switch runtime.GOOS {
	//	case "windows":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/AppData/Local/Cnt"
	//	case "darwin":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/Library/Cnt"
	//	case "linux":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/.config/cnt"
	//	default:
	//		log.Get().Panic("Unsupported OS, please fill a bug repost")
	//	}

	if source, err := ioutil.ReadFile(cntConfig.Path + "/config.yml"); err == nil {
		err = yaml.Unmarshal([]byte(source), &cntConfig)
		if err != nil {
			panic(err)
		}
	}

	log.Debug("Home folder is " + cntConfig.Path)
}
Example #5
0
func (aci *Aci) Install() {
	aci.CheckBuilt()
	if aci.args.Test {
		aci.args.Test = false
		aci.Test()
	}
	os.Remove(aci.target + PATH_INSTALLED)
	hash, err := utils.ExecCmdGetOutput("rkt", "--insecure-options=image", "fetch", aci.target+PATH_IMAGE_ACI)
	if err != nil {
		panic("Cannot install" + err.Error())
	}
	ioutil.WriteFile(aci.target+PATH_INSTALLED, []byte(hash), 0644)
}
Example #6
0
func DefaultHomeFolder() string {
	//	switch runtime.GOOS {
	//	case "windows":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/AppData/Local/Cnt"
	//	case "darwin":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/Library/Cnt"
	//	case "linux":
	//		cntConfig.Path = utils.UserHomeOrFatal() + "/.config/cnt"
	//	default:
	//		log.Get().Panic("Unsupported OS, please fill a bug repost")
	//	}

	path := "/root/.config/cnt"
	user := os.Getenv("SUDO_USER")
	if user != "" {
		home, err := utils.ExecCmdGetOutput("bash", "-c", "echo ~"+user)
		if err != nil {
			panic("Cannot find user home" + err.Error())
		}
		path = home + "/.config/cnt"
	}
	return path
}
Example #7
0
func checkSystemdNspawn() {
	_, err := utils.ExecCmdGetOutput("systemd-nspawn", "--version")
	if err != nil {
		logs.WithE(err).Fatal("system-nspawn is required")
	}
}