Skip to content

Commit

Permalink
split initial bitwarden sync
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmccracken committed Nov 15, 2023
1 parent 6fa0d81 commit 7e2de9f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 34 deletions.
45 changes: 28 additions & 17 deletions bootstrap-workstation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@ function install_nix_darwin() {

# install_nix_darwin_function ends here

# [[file:workstation.org::initial_bitwarden_sync_function][initial_bitwarden_sync_function]]
# The initial BitWarden Sync process. Requires wshs/bww executable to
# be built and available. This could all be more robust
# extracting it is theoretically useful as it provides a mechanism for
# resetting the secrets.
# Likely this should be broken down into separate functions that can be reused.
function initial_bitwarden_sync() {
# why is bash so cryptic
if [ ! -z "${BW_CLIENTID+x}" ] && \
[ ! -z "${BW_CLIENTSECRET+x}" ] && \
[ ! -z "${WS_BW_MASTER_PASS+x}" ]; then
info variables requried to run bww force-sync are set, running
if [ ! -d ~/secrets ]; then
mkdir ~/secrets;
fi
# overwriting anything that was previously in the file
echo "${WS_BW_MASTER_PASS}" > ~/secrets/bw_pass
bw login --apikey
bw_unlock
bw sync
$(nix path-info .#"wshs:exe:bww")/bin/bww force-sync
else
info variables required to run bww force sync are MISSING, skipping
fi
}
# initial_bitwarden_sync_function ends here
info starting workstation bootstrap
is_mac && {
info ensuring xcode is installed
Expand Down Expand Up @@ -421,23 +448,7 @@ else
fi
# why is bash so cryptic
if [ ! -z "${BW_CLIENTID+x}" ] && \
[ ! -z "${BW_CLIENTSECRET+x}" ] && \
[ ! -z "${WS_BW_MASTER_PASS+x}" ]; then
info variables requried to run bww force-sync are set, running
if [ ! -d ~/secrets ]; then
mkdir ~/secrets;
fi
# overwriting anything that was previously in the file
echo "${WS_BW_MASTER_PASS}" > ~/secrets/bw_pass
bw login --apikey
bw_unlock
bw sync
$(nix path-info .#"wshs:exe:bww")/bin/bww force-sync
else
info variables required to run bww force sync are MISSING, skipping
fi
initial_bitwarden_sync
cat <<-EOF
Expand Down
29 changes: 29 additions & 0 deletions lib/shell/setup/initial_bitwarden_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# [[file:../../../workstation.org::*Initial Bitwarden Sync][Initial Bitwarden Sync:2]]
# The initial BitWarden Sync process. Requires wshs/bww executable to
# be built and available. This could all be more robust
# extracting it is theoretically useful as it provides a mechanism for
# resetting the secrets.
# Likely this should be broken down into separate functions that can be reused.
function initial_bitwarden_sync() {
# why is bash so cryptic
if [ ! -z "${BW_CLIENTID+x}" ] && \
[ ! -z "${BW_CLIENTSECRET+x}" ] && \
[ ! -z "${WS_BW_MASTER_PASS+x}" ]; then
info variables requried to run bww force-sync are set, running
if [ ! -d ~/secrets ]; then
mkdir ~/secrets;
fi
# overwriting anything that was previously in the file
echo "${WS_BW_MASTER_PASS}" > ~/secrets/bw_pass
bw login --apikey
bw_unlock
bw sync
$(nix path-info .#"wshs:exe:bww")/bin/bww force-sync
else
info variables required to run bww force sync are MISSING, skipping
fi
}
initial_bitwarden_sync
# Initial Bitwarden Sync:2 ends here
58 changes: 41 additions & 17 deletions workstation.org
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ fi

«install_nix_darwin_function»

«initial_bitwarden_sync_function»
#+end_src
*** Log that bootstrap is starting
#+begin_src shell
Expand Down Expand Up @@ -434,23 +435,7 @@ fi
*** set up workstation secrets
#+begin_src shell :noweb yes

# why is bash so cryptic
if [ ! -z "${BW_CLIENTID+x}" ] && \
[ ! -z "${BW_CLIENTSECRET+x}" ] && \
[ ! -z "${WS_BW_MASTER_PASS+x}" ]; then
info variables requried to run bww force-sync are set, running
if [ ! -d ~/secrets ]; then
mkdir ~/secrets;
fi
# overwriting anything that was previously in the file
echo "${WS_BW_MASTER_PASS}" > ~/secrets/bw_pass
bw login --apikey
bw_unlock
bw sync
$(nix path-info .#"wshs:exe:bww")/bin/bww force-sync
else
info variables required to run bww force sync are MISSING, skipping
fi
initial_bitwarden_sync

#+end_src
*** output final manual setup notes
Expand Down Expand Up @@ -746,6 +731,45 @@ function install_home_manager() {
install_home_manager

#+end_src

*** Initial Bitwarden Sync

#+name: initial_bitwarden_sync_function
#+begin_src shell
# The initial BitWarden Sync process. Requires wshs/bww executable to
# be built and available. This could all be more robust
# extracting it is theoretically useful as it provides a mechanism for
# resetting the secrets.
# Likely this should be broken down into separate functions that can be reused.
function initial_bitwarden_sync() {
# why is bash so cryptic
if [ ! -z "${BW_CLIENTID+x}" ] && \
[ ! -z "${BW_CLIENTSECRET+x}" ] && \
[ ! -z "${WS_BW_MASTER_PASS+x}" ]; then
info variables requried to run bww force-sync are set, running
if [ ! -d ~/secrets ]; then
mkdir ~/secrets;
fi
# overwriting anything that was previously in the file
echo "${WS_BW_MASTER_PASS}" > ~/secrets/bw_pass
bw login --apikey
bw_unlock
bw sync
$(nix path-info .#"wshs:exe:bww")/bin/bww force-sync
else
info variables required to run bww force sync are MISSING, skipping
fi
}

#+end_src

#+begin_src sh :tangle ./lib/shell/setup/initial_bitwarden_sync.sh :shebang "#!/usr/bin/env bash" :noweb yes

«initial_bitwarden_sync_function»
initial_bitwarden_sync

#+end_src

* Nix components
** Home Manager
I use home manager as the primary method for installing and configuring software
Expand Down

0 comments on commit 7e2de9f

Please sign in to comment.