From 86aed12d4034bcc4a38b386d4e792987a1608708 Mon Sep 17 00:00:00 2001 From: Ziad Arafat Date: Wed, 2 Dec 2026 09:48:36 -0700 Subject: [PATCH] Select Bitwarden server by dotfiles profile --- README.md | 2 +- bin/dot | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99b1ad7..9782638 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ curl -fsSL -H "Authorization: token $GITEA_TOKEN" \ On SteamOS, the one sudo prompt makes `/nix` owned by `deck`. Nix then runs in single-user mode, with no daemon and no units in `/etc`. -Then, once per machine (`bw` already points at `https://vault.etvamerica.com`; override with `BW_SERVER=...`): +Then, once per machine. The personal and headless profiles default to `https://vault.godemperordoge.org`, and `full-work` defaults to `https://vault.etvamerica.com`. Set `BW_SERVER` to override the profile default. If Bitwarden is already signed in to another server, run `bw logout` before retrying setup or `dot secrets`. ```bash bw login && export BW_SESSION=$(bw unlock --raw) diff --git a/bin/dot b/bin/dot index c15d58c..61fb279 100755 --- a/bin/dot +++ b/bin/dot @@ -356,18 +356,35 @@ cmd_boxes() { # ---------------------------------------------------------------- secrets (Bitwarden) BW_PREFIX="dotfiles" -BW_SERVER="${BW_SERVER:-https://vault.etvamerica.com}" +bw_target_server() { + if [ -n "${BW_SERVER:-}" ]; then + printf '%s\n' "$BW_SERVER" + elif [ "$(profile)" = full-work ]; then + echo https://vault.etvamerica.com + else + echo https://vault.godemperordoge.org + fi +} -# Point bw at the Vaultwarden instance (only possible while logged out). +# Bitwarden only accepts a server change when logged out. bw_server() { have bw || return 0 - [ "$(bw config server 2>/dev/null)" = "$BW_SERVER" ] && return 0 - [ "$(bw status | jq -r .status)" = unauthenticated ] && bw config server "$BW_SERVER" >/dev/null && ok "bw server → $BW_SERVER" + local target state current status + target="$(bw_target_server)" + state="$(bw status)" || return 1 + current="$(jq -r '.serverUrl // empty' <<<"$state")" || return 1 + status="$(jq -r '.status // empty' <<<"$state")" || return 1 + [ "${current%/}" = "${target%/}" ] && return 0 + if [ "$status" != unauthenticated ]; then + warn "bw must be logged out before switching to $target (run: bw logout, then retry)" + return 1 + fi + bw config server "$target" >/dev/null && ok "bw server → $target" } bw_ready() { have bw || die "bitwarden-cli missing (dot switch)" - bw_server + bw_server || die "Bitwarden server does not match the selected profile" local status; status="$(bw status | jq -r .status)" case "$status" in unlocked) return 0 ;;