configurator / bashttpd

Static file server in bash
MIT License
20 stars 0 forks source link

FreeBSD: nc: invalid option -- q #1

Open probonopd opened 1 year ago

probonopd commented 1 year ago
FreeBSD% ./bashttpd.sh 
nc: invalid option -- q
usage: nc [-46DdEFhklNnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]
          [--no-tcpopt] [--sctp]
          [-P proxy_username] [-p source_port] [-s source] [-T ToS]
          [-V rtable] [-w timeout] [-X proxy_protocol]
          [-x proxy_address[:port]] [destination] [port]

https://www.freebsd.org/cgi/man.cgi?nc

gabrielmaldi commented 1 year ago

The same happens in macOS Monterey 12.6:

nc: invalid option -- q
usage: nc [-46AacCDdEFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] [-p source_port]
      [--apple-recv-anyif] [--apple-awdl-unres]
      [--apple-boundif ifbound]
      [--apple-no-cellular] [--apple-no-expensive]
      [--apple-no-flowadv] [--apple-tcp-timeout conntimo]
      [--apple-tcp-keepalive keepidle] [--apple-tcp-keepintvl keepintvl]
      [--apple-tcp-keepcnt keepcnt] [--apple-tclass tclass]
      [--tcp-adp-rtimo num_probes] [--apple-initcoproc-allow]
      [--apple-tcp-adp-wtimo num_probes]
      [--setsockopt-later] [--apple-no-connectx]
      [--apple-delegate-pid pid] [--apple-delegate-uuid uuid]
      [--apple-kao] [--apple-ext-bk-idle]
      [--apple-netsvctype svc] [---apple-nowakefromsleep]
      [--apple-notify-ack] [--apple-sockev]
      [--apple-tos tos] [--apple-tos-cmsg]
      [-s source_ip_address] [-w timeout] [-X proxy_version]
      [-x proxy_address[:port]] [hostname] [port[s]]

Also using Homebrew's netcat:

nc --version
netcat (The GNU Netcat) 0.7.1
Copyright (C) 2002 - 2003  Giovanni Giacobbi

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program under the terms of
the GNU General Public License.
For more information about these matters, see the file named COPYING.

Original idea and design by Avian Research <hobbit@avian.org>,
Written by Giovanni Giacobbi <giovanni@giacobbi.net>.
nc: invalid option -- q
Try `nc --help' for more information.
gabrielmaldi commented 1 year ago

I cloned and built https://github.com/jasonuhl/netcat-openbsd-mac:

git clone https://github.com/danmindru/responsive-html-email-signature.git
make
# make sure the produced nc is in your path

I had to edit bashttpd.sh to remove the -p option:

---  <"$fifo" nc -q 0 -l -p "$PORT" | cleanAndHandleRequest
+++  <"$fifo" nc -q 0 -l "$PORT" | cleanAndHandleRequest

Then found out macOS ships with a really old version of bash:

~/.local/bin/bashttpd: line 114: local: -A: invalid option
local: usage: local name[=value] ...
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

So I installed Homebrew's bash:

GNU bash, version 5.2.2(1)-release (aarch64-apple-darwin21.6.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

And now bashttpd kinda works: some requests do work and others timeout. So I'll be sticking with python3 -m http.server 8080 for the time being.

But anyways, thank you for writing this, @configurator! ❤️ Will definitely keep an eye on the repo in case you decide to add compatibility with macOS. Thanks!