(ctx context.Context, version string)
| 33 | } |
| 34 | |
| 35 | func createScriptFile(ctx context.Context, version string) (string, error) { |
| 36 | var url string |
| 37 | switch version { |
| 38 | case "nightly": |
| 39 | url = "https://cdn.rilldata.com/rill/nightly/install.sh" |
| 40 | case "latest", "": |
| 41 | url = "https://cdn.rilldata.com/rill/install.sh" |
| 42 | default: |
| 43 | url = fmt.Sprintf("https://raw.githubusercontent.com/rilldata/rill/%s/scripts/install.sh", version) |
| 44 | } |
| 45 | |
| 46 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) |
| 47 | if err != nil { |
| 48 | return "", fmt.Errorf("failed to create request: %w", err) |
| 49 | } |
| 50 | |
| 51 | client := &http.Client{} |
| 52 | resp, err := client.Do(req) |
| 53 | if err != nil { |
| 54 | return "", fmt.Errorf("failed to download install script from %s: %w", url, err) |
| 55 | } |
| 56 | defer resp.Body.Close() |
| 57 | |
| 58 | if resp.StatusCode != http.StatusOK { |
| 59 | return "", fmt.Errorf("failed to download install script from %s: HTTP %d", url, resp.StatusCode) |
| 60 | } |
| 61 | |
| 62 | out, err := os.CreateTemp("", "install*.sh") |
| 63 | if err != nil { |
| 64 | return "", err |
| 65 | } |
| 66 | defer out.Close() |
| 67 | |
| 68 | _, err = io.Copy(out, resp.Body) |
| 69 | if err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | |
| 73 | return out.Name(), nil |
| 74 | } |
no test coverage detected