Select Bitwarden server by dotfiles profile

This commit is contained in:
Ziad Arafat committed 2026-12-02 09:48:36 -07:00
1 parent a69f108c27
commit 86aed12d40
2 files changed
+23 -6

No files matched your search

+1 -1
View File
@@ -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)
+22 -5
View File
@@ -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 ;;