Skip to content
This repository has been archived by the owner on Jul 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #410 from sathishvj/master
Browse files Browse the repository at this point in the history
prints path in which executable is already installed #162
  • Loading branch information
jstrachan committed Jun 28, 2017
2 parents 76cd534 + d204bf0 commit 78856ac
Showing 1 changed file with 118 additions and 113 deletions.
231 changes: 118 additions & 113 deletions cmds/install.go
Expand Up @@ -129,6 +129,7 @@ func install(isMinishift bool) {
util.Warnf("Unable to download funktion operator %v\n", err)
}
}

func downloadDriver() (err error) {
if runtime.GOOS == "darwin" {
util.Infof("fabric8 recommends OSX users use the xhyve driver\n")
Expand Down Expand Up @@ -174,7 +175,8 @@ func downloadDriver() (err error) {

util.Success("xhyve driver installed\n")
} else {
util.Success("xhyve driver already installed\n")
pgmPath, _ := exec.LookPath("docker-machine-driver-xhyve")
util.Successf("xhyve driver is already available on your PATH at %s\n", pgmPath)
}

} else if runtime.GOOS == "linux" {
Expand All @@ -183,48 +185,49 @@ func downloadDriver() (err error) {
return nil
}

func downloadKubernetes(d downloadProperties) (err error) {
func downloadKubernetes(d downloadProperties) error {
os := runtime.GOOS
arch := runtime.GOARCH

if runtime.GOOS == "windows" {
d.kubeBinary += ".exe"
}

_, err = exec.LookPath(d.kubeBinary)
if err != nil {
// fix minishift version to 0.9.0 until we can address issues running on 1.x
latestVersion := "0.9.0"
if !d.isMiniShift {
semverVersion, err := getLatestVersionFromGitHub(d.kubeDistroOrg, d.kubeDistroRepo)
latestVersion = semverVersion.String()
if err != nil {
util.Errorf("Unable to get latest version for %s/%s %v", d.kubeDistroOrg, d.kubeDistroRepo, err)
return err
}
}

kubeURL := fmt.Sprintf(d.downloadURL+d.kubeDistroRepo+"/releases/"+d.extraPath+"v%s/%s-%s-%s", latestVersion, d.kubeDistroRepo, os, arch)
if runtime.GOOS == "windows" {
kubeURL += ".exe"
}
util.Infof("Downloading %s...\n", kubeURL)
pgmPath, err := exec.LookPath(d.kubeBinary)
if err == nil {
util.Successf("%s is already available on your PATH at %s\n", d.kubeBinary, pgmPath)
return nil
}

fullPath := filepath.Join(getFabric8BinLocation(), d.kubeBinary)
err = downloadFile(fullPath, kubeURL)
// fix minishift version to 0.9.0 until we can address issues running on 1.x
latestVersion := "0.9.0"
if !d.isMiniShift {
semverVersion, err := getLatestVersionFromGitHub(d.kubeDistroOrg, d.kubeDistroRepo)
latestVersion = semverVersion.String()
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, kubeURL, err)
util.Errorf("Unable to get latest version for %s/%s %v", d.kubeDistroOrg, d.kubeDistroRepo, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", d.kubeBinary)
}

kubeURL := fmt.Sprintf(d.downloadURL+d.kubeDistroRepo+"/releases/"+d.extraPath+"v%s/%s-%s-%s", latestVersion, d.kubeDistroRepo, os, arch)
if runtime.GOOS == "windows" {
kubeURL += ".exe"
}
util.Infof("Downloading %s...\n", kubeURL)

fullPath := filepath.Join(getFabric8BinLocation(), d.kubeBinary)
err = downloadFile(fullPath, kubeURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, kubeURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)

return nil
}

func downloadKubectlClient() (err error) {
func downloadKubectlClient() error {

os := runtime.GOOS
arch := runtime.GOARCH
Expand All @@ -234,129 +237,131 @@ func downloadKubectlClient() (err error) {
kubectlBinary += ".exe"
}

_, err = exec.LookPath(kubectlBinary)
pgmPath, err := exec.LookPath(kubectlBinary)
if err == nil {
util.Successf("%s is already available on your PATH at %s\n", kubectlBinary, pgmPath)
return nil
}

latestVersion, err := getLatestVersionFromKubernetesReleaseUrl()
if err != nil {
latestVersion, err := getLatestVersionFromKubernetesReleaseUrl()
if err != nil {
return fmt.Errorf("Unable to get latest version for %s/%s %v", kubernetes, kubernetes, err)
}
return fmt.Errorf("Unable to get latest version for %s/%s %v", kubernetes, kubernetes, err)
}

clientURL := fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/v%s/bin/%s/%s/%s", latestVersion, os, arch, kubectlBinary)
clientURL := fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/v%s/bin/%s/%s/%s", latestVersion, os, arch, kubectlBinary)

util.Infof("Downloading %s...\n", clientURL)
util.Infof("Downloading %s...\n", clientURL)

fullPath := filepath.Join(getFabric8BinLocation(), kubectlBinary)
err = downloadFile(fullPath, clientURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, clientURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", kubectlBinary)
fullPath := filepath.Join(getFabric8BinLocation(), kubectlBinary)
err = downloadFile(fullPath, clientURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, clientURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)

return nil
}

func downloadOpenShiftClient() (err error) {
func downloadOpenShiftClient() error {
var arch string

ocBinary := "oc"
if runtime.GOOS == "windows" {
ocBinary += ".exe"
}

_, err = exec.LookPath(ocBinary)
if err != nil {
pgmPath, err := exec.LookPath(ocBinary)
if err == nil {
util.Successf("%s is already available on your PATH at %s\n", oc, pgmPath)
return nil
}

// need to fix the version we download as not able to work out the oc sha in the URL yet
sha := "dad658de7465ba8a234a4fb40b5b446a45a4cee1"
latestVersion := "1.3.1"

clientURL := fmt.Sprintf("https://github.com/openshift/origin/releases/download/v%s/openshift-origin-client-tools-v%s-%s", latestVersion, latestVersion, sha)

extension := ".zip"
switch runtime.GOOS {
case "windows":
clientURL += "-windows.zip"
case "darwin":
clientURL += "-mac.zip"
default:
switch runtime.GOARCH {
case "amd64":
arch = "64bit"
case "386":
arch = "32bit"
}
extension = ".tar.gz"
clientURL += fmt.Sprintf("-%s-%s.tar.gz", runtime.GOOS, arch)
// need to fix the version we download as not able to work out the oc sha in the URL yet
sha := "dad658de7465ba8a234a4fb40b5b446a45a4cee1"
latestVersion := "1.3.1"

clientURL := fmt.Sprintf("https://github.com/openshift/origin/releases/download/v%s/openshift-origin-client-tools-v%s-%s", latestVersion, latestVersion, sha)

extension := ".zip"
switch runtime.GOOS {
case "windows":
clientURL += "-windows.zip"
case "darwin":
clientURL += "-mac.zip"
default:
switch runtime.GOARCH {
case "amd64":
arch = "64bit"
case "386":
arch = "32bit"
}
extension = ".tar.gz"
clientURL += fmt.Sprintf("-%s-%s.tar.gz", runtime.GOOS, arch)
}

util.Infof("Downloading %s...\n", clientURL)
util.Infof("Downloading %s...\n", clientURL)

writeFileLocation := getFabric8BinLocation()
fullPath := filepath.Join(getFabric8BinLocation(), oc+extension)
dotPath := filepath.Join(getFabric8BinLocation(), ".")
writeFileLocation := getFabric8BinLocation()
fullPath := filepath.Join(getFabric8BinLocation(), oc+extension)
dotPath := filepath.Join(getFabric8BinLocation(), ".")

err = downloadFile(fullPath, clientURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", writeFileLocation+oc, clientURL, err)
return err
}

err = downloadFile(fullPath, clientURL)
switch extension {
case ".zip":
err = unzip(fullPath, dotPath)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", writeFileLocation+oc, clientURL, err)
util.Errorf("Unable to unzip %s %v", fullPath, err)
return err
}

switch extension {
case ".zip":
err = unzip(fullPath, dotPath)
if err != nil {
util.Errorf("Unable to unzip %s %v", fullPath, err)
return err
}
case ".tar.gz":
err = untargz(fullPath, dotPath, []string{"oc"})
if err != nil {
util.Errorf("Unable to untar %s %v", writeFileLocation+oc+".tar.gz", err)
return err
}
os.Remove(fullPath)
case ".tar.gz":
err = untargz(fullPath, dotPath, []string{"oc"})
if err != nil {
util.Errorf("Unable to untar %s %v", writeFileLocation+oc+".tar.gz", err)
return err
}

util.Successf("Downloaded %s\n", oc)
} else {
util.Successf("%s is already available on your PATH\n", oc)
os.Remove(fullPath)
}

util.Successf("Downloaded %s\n", oc)

return nil
}

func downloadFunktion() (err error) {
func downloadFunktion() error {
os := runtime.GOOS
arch := runtime.GOARCH

_, err = exec.LookPath(funktion)
pgmPath, err := exec.LookPath(funktion)
if err == nil {
util.Successf("%s is already available on your PATH at %s\n", funktion, pgmPath)
return nil
}

latestVersion, err := getLatestVersionFromGitHub(fabric8io, funktionOperator)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(fabric8io, funktionOperator)
if err != nil {
util.Errorf("Unable to get latest version for %s/%s %v", fabric8io, funktionOperator, err)
return err
}
util.Errorf("Unable to get latest version for %s/%s %v", fabric8io, funktionOperator, err)
return err
}

funktionURL := fmt.Sprintf(githubURL+fabric8io+"/"+funktionOperator+"/releases/download/v%s/%s-%s-%s", latestVersion, funktionOperator, os, arch)
if runtime.GOOS == "windows" {
funktionURL += ".exe"
}
util.Infof("Downloading %s...\n", funktionURL)
funktionURL := fmt.Sprintf(githubURL+fabric8io+"/"+funktionOperator+"/releases/download/v%s/%s-%s-%s", latestVersion, funktionOperator, os, arch)
if runtime.GOOS == "windows" {
funktionURL += ".exe"
}
util.Infof("Downloading %s...\n", funktionURL)

fullPath := filepath.Join(getFabric8BinLocation(), funktion)
err = downloadFile(fullPath, funktionURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, funktionURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", funktion)
fullPath := filepath.Join(getFabric8BinLocation(), funktion)
err = downloadFile(fullPath, funktionURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, funktionURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)

return nil
}
Expand Down

0 comments on commit 78856ac

Please sign in to comment.