Make the script work on an M1 mac
Mahoney opened this issue · comments
The script currently requires bash 5
& needs to run as root (it alters /etc/hosts
).
A Mac comes with bash 3.2
(and zsh 5.x
).
brew install bash
on an M1/ARM64 Mac installs bash 5.x
, but to /opt/homebrew/bin
- which is not on root's path. (On an x64 Mac it is installed to /usr/local/bin
, which is on root's path, so it works.)
So #! /usr/bin/env bash
loads bash 3.2
.
Options:
- Alter root's path to include
/opt/homebrew/bin
- Find some mechanism for a script to discover later versions of bash if installed?!
- Migrate the script to
zsh
which is installed - Migrate the script to
bash 3.2
- Just document that it's the user's problem to make
/usr/bin/env bash
resolve to bash 5.x - Use another approach entirely (dns server running in docker?)
I'm not a massive fan of any of them...
- Making root's path include homebrew when homebrew doesn't seems like an invasive thing to do... I'd like this to be less reliant on running as & mucking about with root, not more
- I don't even know if this is possible
- I've got a reasonable way with this... need a replacement for
shopt -s extglob
and possibly then replacements for bash's${sanitised//+([^A-Za-z0-9\.])/-}
,${sanitised#[^[:alnum:]]}
&${sanitised%[^[:alnum:]]}
variable substituting
More seriously, the tests are in bats which seems to be bash specific - I haven't located a zsh test framework yet. - Not sure how to work around the lack of associative arrays...
- I hate when things don't install nicely - it's already a bit painful with all the manual
chown
. Also I'd want to give specific instructions on the "right" way to do this and I'm not sure what that is - alter root's path to include/opt/homebrew/bin
I suppose, bit see objections to 1! - This exists - e.g. https://github.com/aacebedo/dnsdock or https://github.com/mageddo/dns-proxy-server - run a dns server inside docker that will pick up containers starting and stopping and use it as the host's DNS.
I was reluctant to go this way because mucking about with how macOs does DNS choice is something I'm a bit uncomfortable with. If docker isn't running your DNS is broken, for a start. And you have to work out how to configure this DNS server to resolve to the correct "real" DNS server(s). Just mutating /etc/hosts leaves the actual DNS server configuration alone.