Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple-binary #45

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ curl https://i.jpillora.com/<query>! | bash
* `type=homebrew` is **not** working at the moment – see [Homebrew](#homebrew)
* `?insecure=1` Force `curl`/`wget` to skip certificate checks
* `?as=` Force the binary to be named as this parameter value
* `?select=` Select binary, if **repository name** and **binary name** in release differs.
* **eg**: repo_name is **foobar** and binary name is **fb-client** and **fb-server** in release, Then `?select=fb-client` & `?select=fb-server` accordingly.

## Security

Expand Down
12 changes: 9 additions & 3 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var (
)

type Query struct {
User, Program, AsProgram, Release string
MoveToPath, Search, Insecure bool
SudoMove bool // deprecated: not used, now automatically detected
User, Program, AsProgram, Selected, Release string
MoveToPath, Search, Insecure bool
SudoMove bool // deprecated: not used, now automatically detected
}

type Result struct {
Expand Down Expand Up @@ -110,6 +110,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
User: "",
Program: "",
Release: "",
Selected: r.URL.Query().Get("select"),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As select is reserved keyword in golang, used selected and user can provide select as params.

Insecure: r.URL.Query().Get("insecure") == "1",
AsProgram: r.URL.Query().Get("as"),
}
Expand All @@ -124,6 +125,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
q.User, rest = splitHalf(path, "/")
q.Program, q.Release = splitHalf(rest, "@")
// no program? treat first part as program, use default user

if q.AsProgram == "" && q.Selected != "" {
q.AsProgram = q.Selected
}

if q.Program == "" {
q.Program = q.User
q.User = h.Config.User
Expand Down
8 changes: 8 additions & 0 deletions handler/handler_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
//only binary containers are supported
//TODO deb,rpm etc
fext := getFileExt(url)

if q.Selected != "" {
//filter binary with it's name
if !strings.Contains(ga.Name[0:len(q.Selected)+1], fmt.Sprint(q.Selected, "-")) {
continue
}
}

if fext == "" && ga.Size > 1024*1024 {
fext = ".bin" // +1MB binary
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/install.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function install {
#settings
USER="{{ .User }}"
PROG="{{ .Program }}"
SEL_BIN="{{ .Selected }}"
ASPROG="{{ .AsProgram }}"
MOVE="{{ .MoveToPath }}"
RELEASE="{{ .Release }}"
Expand Down Expand Up @@ -93,6 +94,9 @@ function install {
#got URL! download it...
echo -n "{{ if .MoveToPath }}Installing{{ else }}Downloading{{ end }}"
echo -n " $USER/$PROG"
if [ ! -z "$SEL_BIN" ]; then
echo -n "/$SEL_BIN"
fi
if [ ! -z "$RELEASE" ]; then
echo -n " $RELEASE"
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/install.txt.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
repository: https://github.com/{{ .User }}/{{ .Program }}
user: {{ .User }}
program: {{ .Program }}{{if .AsProgram }}
program: {{ .Program }}{{if .Selected }}
selected-binary: {{.Selected}}{{end}}{{if .AsProgram }}
as: {{ .AsProgram }}{{end}}
release: {{ .Release }}
move-into-path: {{ .MoveToPath }}
Expand Down