aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-12 00:56:27 -0500
committerCraig Jennings <c@cjennings.net>2026-05-12 00:56:27 -0500
commit839bbeb14a92a777a3857102dba08a212b21443d (patch)
tree67cadf65b818b17d8421e4063a06d51895e4584b /scripts
parent18ba99fda928769adb235bd85b485c8be94c3ddd (diff)
downloaddotemacs-839bbeb14a92a777a3857102dba08a212b21443d.tar.gz
dotemacs-839bbeb14a92a777a3857102dba08a212b21443d.zip
test(scripts): add bats coverage for setup-email.sh password helpers
`setup-email.sh' ran top to bottom, so the only way to exercise `install_encrypted_password' / `decrypt_password' was to run the whole new-machine setup (mbsync, mu init). Its procedural body now lives in a `main()' function guarded by the usual `[[ "${BASH_SOURCE[0]}" == "${0}" ]]' check, so sourcing the script just defines the helpers, and running it directly is unchanged. New `tests/test-setup-email.bats' sources the script, points the password dirs at a per-test tmpdir, and covers both helpers across the normal / skip-existing / missing-source / (for decrypt) gpg-failure paths, stubbing `gpg' so no real key is needed. `make test-bash' runs the bats files, and `make test' picks them up after the Elisp suite when bats is installed.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/setup-email.sh82
1 files changed, 45 insertions, 37 deletions
diff --git a/scripts/setup-email.sh b/scripts/setup-email.sh
index 5d461691..39423c97 100755
--- a/scripts/setup-email.sh
+++ b/scripts/setup-email.sh
@@ -75,41 +75,49 @@ decrypt_password() {
fi
}
-# Decrypt Mail Passwords
-# Skip if destination already exists, install or decrypt if missing.
-echo "→ checking mail passwords..."
-if [[ ! -d "$ENCRYPTED_PASSWORDS_DIR" ]]; then
- echo " ✗ encrypted passwords directory not found: $ENCRYPTED_PASSWORDS_DIR"
- exit 1
+main() {
+ # Decrypt Mail Passwords
+ # Skip if destination already exists, install or decrypt if missing.
+ echo "→ checking mail passwords..."
+ if [[ ! -d "$ENCRYPTED_PASSWORDS_DIR" ]]; then
+ echo " ✗ encrypted passwords directory not found: $ENCRYPTED_PASSWORDS_DIR"
+ exit 1
+ fi
+ mkdir -p "$PASSWORD_DEST_DIR"
+ install_encrypted_password ".gmailpass.gpg"
+ decrypt_password ".cmailpass.gpg" ".cmailpass"
+ install_encrypted_password ".dmailpass.gpg"
+
+ # Check All Prerequisites
+ [[ -x "$MBSYNC" ]] || { echo "ERROR: mbsync not found. Install 'isync'."; exit 1; }
+ [[ -x "$MU" ]] || { echo "ERROR: mu not found. Install 'mu'."; exit 1; }
+ [[ -d "$MU4EDIR" ]] || { echo "ERROR: mu4e elisp not found at $MU4EDIR. Install 'mu'."; exit 1; }
+ [[ -f "$MBSYNCRC" ]] || { echo "ERROR: '~/.mbsyncrc' missing."; exit 1; }
+ [[ -x "$MSMTP" ]] || { echo "ERROR: msmtp not found. Install 'msmtp'."; exit 1; }
+ [[ -f "$MSMTPRC" ]] || { echo "ERROR: '~/.msmtprc' missing."; exit 1; }
+
+ # Ensure Mail Dirs Exist
+ mkdir -p "$GMAILDIR" "$CMAILDIR" "$DMAILDIR"
+
+ # Initial Sync
+ echo "→ syncing all mail with mbsync ..."
+ "$MBSYNC" -aV
+
+ # Init MU and Index Email
+ echo "→ initializing mu ..."
+ "$MU" init --maildir="$MAILROOT" \
+ --my-address="craigmartinjennings@gmail.com" \
+ --my-address="c@cjennings.net" \
+ --my-address="craig.jennings@deepsat.com"
+
+ echo "→ indexing mail ..."
+ "$MU" index
+
+ echo "✅ Mail setup complete."
+}
+
+# Run the setup when executed directly. Sourcing this file (for example from
+# a bats test) just defines the helper functions above.
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+ main "$@"
fi
-mkdir -p "$PASSWORD_DEST_DIR"
-install_encrypted_password ".gmailpass.gpg"
-decrypt_password ".cmailpass.gpg" ".cmailpass"
-install_encrypted_password ".dmailpass.gpg"
-
-# Check All Prerequisites
-[[ -x "$MBSYNC" ]] || { echo "ERROR: mbsync not found. Install 'isync'."; exit 1; }
-[[ -x "$MU" ]] || { echo "ERROR: mu not found. Install 'mu'."; exit 1; }
-[[ -d "$MU4EDIR" ]] || { echo "ERROR: mu4e elisp not found at $MU4EDIR. Install 'mu'."; exit 1; }
-[[ -f "$MBSYNCRC" ]] || { echo "ERROR: '~/.mbsyncrc' missing."; exit 1; }
-[[ -x "$MSMTP" ]] || { echo "ERROR: msmtp not found. Install 'msmtp'."; exit 1; }
-[[ -f "$MSMTPRC" ]] || { echo "ERROR: '~/.msmtprc' missing."; exit 1; }
-
-# Ensure Mail Dirs Exist
-mkdir -p "$GMAILDIR" "$CMAILDIR" "$DMAILDIR"
-
-# Initial Sync
-echo "→ syncing all mail with mbsync ..."
-"$MBSYNC" -aV
-
-# Init MU and Index Email
-echo "→ initializing mu ..."
-"$MU" init --maildir="$MAILROOT" \
- --my-address="craigmartinjennings@gmail.com" \
- --my-address="c@cjennings.net" \
- --my-address="craig.jennings@deepsat.com"
-
-echo "→ indexing mail ..."
-"$MU" index
-
-echo "✅ Mail setup complete."