Both scripts had real macOS branches already — MACOS_SKIP, Xcode CLT, Docker Desktop
detection — but neither had ever run past its own library load on a real Mac, and
verifying that live is what this commit is. This machine is the Mac.
The root cause was the interpreter, not missing OS coverage: macOS's stock /bin/bash is
3.2.57 (Apple stopped shipping newer once bash went GPLv3) and this machine has no newer
one installed. Both scripts used bash 4+/4.3+ syntax with zero version guard, so a real
run died in seconds — declare -A (base.sh, associative array), local -n (packages.sh,
nameref), mapfile (5 sites), ${var,,} (both scripts' own step() — confirmed --only killed
the ENTIRE run), and machine-setup.sh's own pre-flight hard-refused brew outright ("this
script does not implement yet") even once the bash-4 crash was fixed. Each got rewritten
to its bash-3.2-safe equivalent rather than requiring a newer bash and re-executing under
it — nine call sites, a bounded fix, and one less thing that can go wrong before the
script can report what's wrong.
Past that gate, a live probe run (real account/path prompts, killed before Database/
Services could touch this machine's actual state) reproduced a second bug in the first
few seconds: resolve_user_home used getent (Linux/glibc, absent on macOS) with a
hardcoded /home/<user> fallback, so Layout tried `install -d /home/pastilhas` and failed
with "Operation not supported". Fixed with the portable `eval echo ~user` tilde-expansion
idiom, re-ran the same probe, and it correctly created /Users/pastilhas/officerdev/ and
started a real git clone.
Everything else follows the same shape — an unguarded Linux-only tool with a portable or
brew-based macOS equivalent:
- grep -oP (4 sites: both --list flags, env.sh's tailnet lookup, build.sh's schema
table count) — BSD grep has no -P at all. Portable ERE+sed where regex was enough;
jq where the input was already JSON (tailnet lookup) — jq is already an unconditional
dependency elsewhere in this script, so that's a correctness fix, not just a port.
- ss (postgres.sh, proxy.sh — is anything listening on this port, and is it bound wide
enough for NPM's container to reach) — both silently mis-reported on macOS, since the
"command not found" was swallowed by 2>/dev/null and read as "nothing's listening".
New shared `listening_addrs()` in officer-setup's base.sh, branching to lsof.
- getent hosts (proxy.sh's DNS-wait loop) — same silent-failure shape, would have spun
its full 30-minute timeout regardless of whether the record actually resolved. macOS
branch uses dscacheutil.
- stat -c (layout.sh's ownership check) — BSD stat has no -c, confirmed live ("illegal
option -- c"), and the failure was VISIBLE and made every layout directory report as
wrong-owner. Portable file_owner() tries -c then falls back to -f %Su.
- apt-only Postgres client, NodeSource's Debian-only setup script, lazydocker/lazygit's
installers (one literally named install_update_linux.sh, the other hardcoding
"_Linux_" into the release asset URL) — each gets a brew branch, formula names
verified against the live Homebrew catalog rather than assumed.
- sudo -u "$USERNAME" to become the SAME account the process already is — real on
Linux, where this whole script runs as root and dropping to the owner needs no
password; on macOS the process never escalates in the first place, so re-invoking
sudo for yourself asks for a real password on every call, or fails outright without
sudo rights. machine-setup's dev.sh had ~10 inline call sites (git, bun, deno, claude,
opencode, editor detection) rerouted through a new shared run_as_owner(); officer-
setup's own as_owner() (already the shared entry point there) got the same branch,
and six direct sudo call sites in build.sh/secrets.sh/services.sh that bypassed it
were rerouted through it too.
Three things stay Linux-only rather than getting an unverified macOS implementation,
each skipped with a stated reason at the point it would otherwise run: pm2's boot-
persistence hook (needs a launchd plist generated and loaded, not a systemd unit
printed and eval'd — real, separate work), the Tailscale exit-node NIC/sysctl tuning
(no macOS equivalent concept, and advertising a laptop as an exit node is already the
edge case MACOS_SKIP treats it as), and ufw's bridge-to-host firewall rule (pf is a
different rule language entirely, and Docker Desktop's own VM-based networking may not
even have the problem this rule exists to solve — guessing at a firewall rule felt like
the wrong place to be wrong).
Verified: both --list flags print step names instead of a grep usage error. A bounded
officer-setup.sh run (killed before Database) resolved the real macOS home directory,
created the layout with correct ownership, and began a real git clone — cleaned up
after (rm -rf the test directory, the gitignored .setup-progress file, the stray
install-report). machine-setup.sh's pre-flight now reports "Packages: brew" and reaches
the account/path prompts instead of refusing the OS outright. bash -n clean on all 16
files under bash 3.2, the actual interpreter these scripts run under on a Mac.
Not run further live: Database, Secrets, Services and Proxy would mutate this machine's
real state (a live Postgres, a live set of pm2 processes this session runs through) and
were left for a deliberate, supervised run rather than folded into validation.
55 lines
2.4 KiB
Bash
55 lines
2.4 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# officer-setup — schema and build
|
|
# =============================================================================
|
|
#
|
|
# Definitions only.
|
|
#
|
|
# Both run AS the owner, from the repo. Neither is idempotent in the sense of
|
|
# "does nothing the second time" — both are safe to repeat, which is not the same
|
|
# thing and is the property that matters for a script people re-run.
|
|
|
|
[[ -n "${OFFICER_SETUP_BUILD_LOADED:-}" ]] && return 0
|
|
OFFICER_SETUP_BUILD_LOADED=1
|
|
|
|
# `bun db:push` — drizzle-kit diffs the schema code against the live database.
|
|
#
|
|
# No migrations here and no __drizzle_migrations table: the schema code IS the
|
|
# source of truth (src/databases/CLAUDE.md). On the empty database section 5 just
|
|
# created there is nothing to drop, so the prompt drizzle-kit shows for a
|
|
# destructive change cannot appear.
|
|
#
|
|
# It can still appear on a RE-RUN against a database with data, and a prompt
|
|
# nobody sees would hang the script forever — so stdin is closed rather than left
|
|
# attached. drizzle-kit then fails instead of waiting, which is the outcome you
|
|
# want at 3am.
|
|
push_schema() {
|
|
as_owner "cd '$(platform_dir)' && bun db:push </dev/null" 2>&1
|
|
}
|
|
|
|
# What tables the schema will create, read from the aggregator rather than
|
|
# guessed. This is what makes the section able to say what it is about to do.
|
|
#
|
|
# Portable ERE + sed rather than GNU grep's -P/lookbehind: BSD grep on macOS has no -P at
|
|
# all (confirmed live — errors immediately), and its 2>/dev/null here would have hidden that
|
|
# and reported "0 tables" on every macOS run instead, cosmetic but silently wrong.
|
|
schema_table_count() {
|
|
local dir
|
|
dir="$(platform_dir)/src/databases/officer_db/src"
|
|
grep -E "^export \* from '\./" "$dir/schema.ts" 2>/dev/null |
|
|
sed -E "s/^export \* from '\.\/([A-Za-z0-9_-]+)\/schema'.*/\1/" | while read -r f; do
|
|
grep -c "pgTable(" "$dir/$f/schema.ts" 2>/dev/null || true
|
|
done | awk '{s+=$1} END {print s+0}'
|
|
}
|
|
|
|
# `bun gen:index` — substitutes PUBLIC_URL into index.html and writes
|
|
# index.gen.html, which is what the server actually imports.
|
|
#
|
|
# Not optional and not cosmetic: without it the server has no page to serve. It
|
|
# is gitignored, so a fresh clone never has one.
|
|
gen_index() {
|
|
as_owner "cd '$(platform_dir)' && bun gen:index '$ENV_PUBLIC_URL'" 2>&1
|
|
}
|
|
|
|
gen_index_output() { echo "$(platform_dir)/src/apps/officer-web/index.gen.html"; }
|