diff --git a/README.md b/README.md index 4a7e89d..2c826e9 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,13 @@ Installer is an HTTP server which returns shell scripts. The returned script wil ## Usage ```sh +# install / from github curl https://i.jpillora.com//@! | bash ``` ```sh -# use Google to automatically choose -curl https://i.jpillora.com/@! | bash +# search Google for github repo +curl https://i.jpillora.com/! | bash ``` *Or you can use* `wget -qO- | bash` @@ -26,7 +27,7 @@ curl https://i.jpillora.com/@! | bash * `!` When provided, downloads binary directly into `/usr/local/bin/` (defaults to working directory) * `!!` Uses `sudo` to `mv` into `/usr/local/bin/` -**Query API** +**Query Params** * `?type=` Force the return type to be one of: `script` or `homebrew` * `type` is normally detected via `User-Agent` header diff --git a/handler/handler_github.go b/handler/handler_github.go index 0017ce1..6fccf9d 100644 --- a/handler/handler_github.go +++ b/handler/handler_github.go @@ -32,7 +32,11 @@ func (h *Handler) getAssets(q *query) error { user, program, gerr := searchGoogle(q.Program) if gerr != nil { log.Printf("google search failed: %s", gerr) - } else if program == q.Program { + } else { + if program == q.Program { + log.Printf("program mismatch: got %s: expected %s", q.Program, program) + } + q.Program = program q.User = user //retry assets... err = h.getAssetsNoCache(q) @@ -106,6 +110,12 @@ func (h *Handler) getAssetsNoCache(q *query) error { //match os := getOS(ga.Name) arch := getArch(ga.Name) + //windows not supported yet + if os == "windows" { + //TODO: powershell + // EG: iwr https://deno.land/x/install/install.ps1 -useb | iex + continue + } //unknown os, cant use if os == "" { continue diff --git a/handler/handler_search.go b/handler/handler_search.go index 7cd34dd..c677c8c 100644 --- a/handler/handler_search.go +++ b/handler/handler_search.go @@ -29,7 +29,7 @@ func searchGoogle(phrase string) (user, project string, err error) { //roundtripper doesn't follow redirects resp, err := http.DefaultTransport.RoundTrip(req) if err != nil { - return "", "", err + return "", "", fmt.Errorf("request failed: %s", err) } resp.Body.Close() //assume redirection diff --git a/handler/strings.go b/handler/strings.go index ff445aa..f33080f 100644 --- a/handler/strings.go +++ b/handler/strings.go @@ -8,7 +8,7 @@ import ( var ( archRe = regexp.MustCompile(`(arm|386|amd64|32|64)`) fileExtRe = regexp.MustCompile(`(\.[a-z][a-z0-9]+)+$`) - posixOSRe = regexp.MustCompile(`(darwin|linux|(net|free|open)bsd|mac|osx)`) + posixOSRe = regexp.MustCompile(`(darwin|linux|(net|free|open)bsd|mac|osx|windows|win)`) ) func getOS(s string) string { @@ -17,6 +17,9 @@ func getOS(s string) string { if o == "mac" || o == "osx" { o = "darwin" } + if o == "win" { + o = "windows" + } return o } diff --git a/main.go b/main.go index 1f80e0c..70eef4a 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,8 @@ import ( "net/http" "strconv" - "github.com/jpillora/opts" - "github.com/jpillora/installer/handler" + "github.com/jpillora/opts" ) var version = "0.0.0-src"