func (i *installer) run(scripts []string, dstDir string) []api.InstallResult { var userResults, sourceResults, defaultResults map[string]*downloadResult // get scripts from user provided URL if i.scriptsURL != "" { userResults = i.download(i.scriptsURL, scripts, filepath.Join(dstDir, api.UserScripts)) } // get scripts from source sourceResults = make(map[string]*downloadResult, len(scripts)) for _, script := range scripts { sourceResults[script] = &downloadResult{location: api.SourceScripts} file := filepath.Join(dstDir, api.SourceScripts, script) if !i.fs.Exists(file) { sourceResults[script].err = errors.NewDownloadError(file, -1) } } // get scripts from default URL defaultURL, err := i.docker.GetScriptsURL(i.image) if err == nil && defaultURL != "" { defaultResults = i.download(defaultURL, scripts, filepath.Join(dstDir, api.DefaultScripts)) } return i.install(scripts, userResults, sourceResults, defaultResults, dstDir) }
func (i *installer) run(scripts []string, dstDir string) []api.InstallResult { var userResults, sourceResults, defaultResults map[string]*downloadResult // get scripts from user provided URL if i.scriptsURL != "" { userResults = i.download(i.scriptsURL, scripts, filepath.Join(dstDir, api.UserScripts)) } // get scripts from source sourceResults = make(map[string]*downloadResult, len(scripts)) for _, script := range scripts { sourceResults[script] = &downloadResult{location: api.SourceScripts} file := filepath.Join(dstDir, api.SourceScripts, script) if !i.fs.Exists(file) { sourceResults[script].err = errors.NewDownloadError(file, -1) } checkLocation := filepath.Join(dstDir, strings.TrimSuffix(api.SourceScripts, "/bin"), script) if i.fs.Exists(checkLocation) { glog.Warningf("The %q script found in .sti/%s, should be in .sti/bin/%s.", script, script, script) } } // get scripts from default URL defaultURL, err := i.docker.GetScriptsURL(i.image) if err == nil && defaultURL != "" { defaultResults = i.download(defaultURL, scripts, filepath.Join(dstDir, api.DefaultScripts)) } return i.install(scripts, userResults, sourceResults, defaultResults, dstDir) }
// Read produces an io.Reader from an http(s) URL. func (h *HttpURLReader) Read(url *url.URL) (io.ReadCloser, error) { resp, err := h.Get(url.String()) if err != nil { if resp != nil { defer resp.Body.Close() } return nil, err } if resp.StatusCode == 200 || resp.StatusCode == 201 { return resp.Body, nil } return nil, errors.NewDownloadError(url.String(), resp.StatusCode) }