Bashbro – Make Any Comp a Web-Based File Server
github.com
github.com
Ok, checked it out, dufs is a cool tool. Definitely replaces python -m http.server. This is a new standard rightalong side ripgrep.
Cargo is the package manager that pip wanted to be. We should just use cargo anyway. Why have distros when you have Cargo? Why have homebrew when you have Cargo?
Dufs support of webdav is nascent.
I kid, but only a little bit.
I looked at the Bashbro source and said NOPE. And I've written a lot of increasingly complex Bash. At some point you just have to realize that you're using the wrong tool for the job. Dufs even has tests!
Congrats!
package main
import (
"net/http"
"os"
)
func main() {
if err := http.ListenAndServe(os.Args[1], http.FileServer(http.Dir(os.Args[2]))); err != nil {
panic(err)
}
}What does this mean?
("cal" obviously stands for "calculator")
Bashbro, on the other hand, seems to require socat. I wonder if there's any bash-istic method of listening to a port...
In a purpose-built environment there is practically no need for such a feature aside from mischief.
But nc is not bash.
https://gist.github.com/alganet/140c7c12d1603c244a01
nc is almost everywhere, you can count on it.
Ultimately, this is a toy, but it can be handy. I originally made it to attempt using for serving config for networked debian unattended installations[1] while automating VM creation, but never went that far.
[1]: https://debian-handbook.info/browse/en-US/stable/sect.automa...
That's a problematic distinction in some situations.
edit:
https://unix.stackexchange.com/questions/49936/dev-tcp-liste...
gives some pointers
You can do it in python with python -m http.server also!
Is there a way to manage all these port numbers? And why can't we use strings, even if just locally?
And what do people use to allocate port numbers in a way that you'll never get clashes?
You could set up Nginx and some local subdomains to reverse proxy to the intended applications, regardless of whether they're hosted on Unix sockets or plain ports, if that makes accessing them easier. It definitely makes them easier to make accessible outside of the local machine.
As for using Nginx, you should be able to install Nginx and enable its service and in that way immediately get a local HTTP server. You can then edit the config such that requests for the Host `myfiles.localhost` are `proxy_pass ...` to your bashbro server. Then `http://myfiles.localhost` in your browser should just work.
run-http-service myfiles bashbro -s -p PORT
And then it would just allocate a new port (clash-free), invoke bashbro with the given flags and substitute PORT by the newly allocated port number, and such that it uses myfiles.localhost as the domain. And when bashbro exits, the port number is garbage collected. Somehow, it feels like this should already exist ...I would not bother with service management to the extent that you are checking to see if the process is still running. Maybe garbage collection is worth doing, you could do it in a single run of `lsof` (the temptation to do it with multiple should be resisted).
I think this does not exist because stuff like foreman/overmind have their own method for allocating ports per-project (add 100 for each line in the config file, set the PORT env var to that) as would any sort of production-ready solution.
But it is a fun idea. And perhaps it should exist.
ss -lntp | grep 'pid=<SERVER'S PID>' | awk '{ print $4 }'
takes care of servers who don't report the port they're actually listening on.