Skip to content

Commit

Permalink
make google search more lax
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed May 29, 2020
1 parent 10f35bd commit fbe493a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Installer is an HTTP server which returns shell scripts. The returned script wil
## Usage

```sh
# install <user>/<repo> from github
curl https://i.jpillora.com/<user>/<repo>@<release>! | bash
```

```sh
# use Google to automatically choose <user>
curl https://i.jpillora.com/<repo>@<release>! | bash
# search Google for github repo <query>
curl https://i.jpillora.com/<query>! | bash
```

*Or you can use* `wget -qO- <url> | bash`
Expand All @@ -26,7 +27,7 @@ curl https://i.jpillora.com/<repo>@<release>! | 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
Expand Down
12 changes: 11 additions & 1 deletion handler/handler_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handler/handler_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion handler/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,6 +17,9 @@ func getOS(s string) string {
if o == "mac" || o == "osx" {
o = "darwin"
}
if o == "win" {
o = "windows"
}
return o
}

Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fbe493a

Please sign in to comment.