Skip to content

Instantly share code, notes, and snippets.

@lukele
Created January 19, 2022 15:18
Show Gist options
  • Save lukele/cd80903c8c60aab03cc71c7faa4224ed to your computer and use it in GitHub Desktop.
Save lukele/cd80903c8c60aab03cc71c7faa4224ed to your computer and use it in GitHub Desktop.
Automatically enable GPG Mail plugin
#!/bin/bash
BUNDLE_NAME="GPGMailLoader_6"
LOADER_BUNDLE="${BUNDLE_NAME:?}.mailbundle"
SIGNED_LOADER_BUNDLE="${BUNDLE_NAME}.signed.mailbundle"
BUNDLES_PATH="/Library/Mail/Bundles"
SIGNED_BUNDLES_PATH="/Library/Application Support/GPGTools/GPGMail"
ENABLED_BUNDLES_PATH="$HOME/Library/Application Support/Mail/Plug-ins/Bundles/${BUNDLE_PATH:?}"
LOADER_BUNDLE_PATH="${BUNDLES_PATH:?}/${LOADER_BUNDLE:?}"
ENABLED_LOADER_BUNDLE_PATH="${ENABLED_BUNDLES_PATH:?}/${LOADER_BUNDLE:?}"
SIGNED_LOADER_BUNDLE_PATH="${SIGNED_BUNDLES_PATH:?}/${SIGNED_LOADER_BUNDLE:?}"
function safe_copy {
local src="$1"
local dst="$2"
cp -R "${src:?}" "${src:?}.bak"
# In order to avoid code signing (stale in-memory cached signature), use mv instead of cp the file.
mv "${src:?}.bak" "${dst}/"
}
# Create the enabled bundles folder if necessary.
mkdir -p "${ENABLED_BUNDLES_PATH:?}"
# Install the latest loader version in /Library/Mail/Bundles
if [[ -e "${LOADER_BUNDLE_PATH:?}" ]]; then
rm -rf "${LOADER_BUNDLE_PATH:?}"
fi
safe_copy "${SIGNED_LOADER_BUNDLE_PATH:?}" "${BUNDLES_PATH:?}"
# Remove older *enabled* bundle loader versions.
if [[ -d "${ENABLED_LOADER_BUNDLE_PATH:?}" ]]; then
rm -rf "${ENABLED_LOADER_BUNDLE_PATH:?}"
fi
# Install the newest version of the GPG Mail loader bundle.
safe_copy "${SIGNED_LOADER_BUNDLE_PATH:?}" "${ENABLED_BUNDLES_PATH:?}/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment