示例#1
0
func SoftCheck() {
	sanity_map := BuildSanitymap()
	for _, check := range sanity_map {
		fmt.Printf("Checking %s...\n", termcolor.Colorize(check.name, termcolor.Cyan, false))
		_, err := Execute(check.cmd_exist, false)
		if err != nil {
			fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] No "+check.name+" found in your path"))
		} else {
			fmt.Printf("%s\n", termcolor.SuccessColor("  Found "+check.name+" installed"))
			out, err := Execute(check.cmd_version, false)
			if err != nil {
				fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] Not able to determine your "+check.name+" version"))
			}

			var cur_version string
			if len(string(out)) > 1 {
				cur_version = string(out[:len(string(out))-1])
			} else {
				cur_version = "NIL"
			}
			if cur_version == "NIL" {
				fmt.Printf("%s\n", termcolor.WarnColor("  [Warnning] "+check.name+" version unknown, try install "+check.expect_version+" or newer"))
			} else if IsVersionNewer(cur_version, check.expect_version) {
				fmt.Printf("%s\n", termcolor.SuccessColor("  Detect "+check.name+" version ("+cur_version+") fulfill expected version ("+check.expect_version+")"))
			} else {
				fmt.Printf("%s\n", termcolor.WarnColor("  [Warnning] Detect "+check.name+" version ("+cur_version+") lower than expected ("+check.expect_version+")"))
			}
		}
	}
}
示例#2
0
func SetupManifest() error {
	cf_release_dir := os.Getenv("CF_RELEASE_DIR")

	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}

	if cf_release_dir == "" {
		cf_release_dir = usr.HomeDir + "/workspace/cf-release"
	}
	_, err = os.Stat(cf_release_dir)
	if err != nil {
		fmt.Printf("%s\n", termcolor.FailureColor("[ERROR] cf-release dir: "+cf_release_dir+" not found, set CF_RELEASE_DIR env first"))
		return err
	}

	_, err = Execute("which bosh", false)
	if err != nil {
		fmt.Printf("%s\n", termcolor.FailureColor("[ERROR] No bosh found, install bosh cli first"))
		return err
	}
	_, err = Execute("bosh status|grep 'Bosh Lite Director'", false)
	if err != nil {
		fmt.Printf("%s\n", termcolor.WarnColor("[Warnning] Can only target Bosh Lite Director, Please use 'bosh target' before running this script."))
		return err
	}
	uuid, err := Execute("bosh status | grep UUID | awk '{print $2}'", false)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", termcolor.SuccessColor("Generating Stub file with uuid:"+string(uuid)))
	cpi, err := Execute("bosh status | grep CPI | awk '{print $2}'", false)
	if err != nil {
		log.Fatal(err)
	}
	if string(cpi) != "warden\n" {
		fmt.Printf("%s\n", termcolor.WarnColor("[Warnning] You are targeting NONE Bosh Lite Director, aborting..."))
		return nil
	}
	err = GenStub(string(uuid))
	if err != nil {
		log.Fatal(err)
	}

	cmd := cf_release_dir + "/generate_deployment_manifest warden /tmp/bosh-lite-manifest-stub " + cf_release_dir + "/templates/cf-minimal-dev.yml"
	fmt.Printf("%s\n", termcolor.SuccessColor("Generating deployment file ./bosh-lite-cf-manifest.yml"))
	_, err = Execute(cmd+" > ./bosh-lite-cf-manifest.yml", false)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", termcolor.SuccessColor("Seting bosh deployment ./bosh-lite-cf-manifest.yml"))
	_, err = Execute("bosh deployment ./bosh-lite-cf-manifest.yml", false)
	if err != nil {
		log.Fatal(err)
	}
	return err
}