Use protonmailbridge-configure for both initialization and later configuration.

This commit is contained in:
Stephen Chin
2026-03-08 18:30:30 -07:00
committed by GitHub
parent 46e0107392
commit fb687c5d22

View File

@@ -122,52 +122,53 @@ systemctl daemon-reload
msg_ok "Created Services" msg_ok "Created Services"
msg_info "Creating Helper Commands" msg_info "Creating Helper Commands"
cat <<'EOF' > /usr/local/bin/protonmailbridge-init
cat <<'EOF' > /usr/local/bin/protonmailbridge-configure
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
BRIDGE_USER="protonbridge" BRIDGE_USER="protonbridge"
BRIDGE_HOME="/home/${BRIDGE_USER}" BRIDGE_HOME="/home/${BRIDGE_USER}"
GNUPG_HOME="${BRIDGE_HOME}/.gnupg"
MARKER="${BRIDGE_HOME}/.protonmailbridge-initialized" MARKER="${BRIDGE_HOME}/.protonmailbridge-initialized"
if [[ -f "$MARKER" ]]; then FIRST_TIME=0
echo "Already initialized." if [[ ! -f "${MARKER}" ]]; then
echo "To start services:" FIRST_TIME=1
echo " systemctl enable --now protonmail-bridge.service"
echo " systemctl enable --now protonmail-bridge-imap.socket protonmail-bridge-smtp.socket"
exit 0
fi fi
# Stop sockets/proxies/bridge daemon if they were manually started # Stop sockets/proxies/bridge daemon if they were manually started
systemctl stop protonmail-bridge-imap.socket protonmail-bridge-smtp.socket 2>/dev/null || true systemctl stop protonmail-bridge-imap.socket protonmail-bridge-smtp.socket 2>/dev/null || true
systemctl stop protonmail-bridge-imap-proxy.service protonmail-bridge-smtp-proxy.service protonmail-bridge.service 2>/dev/null || true systemctl stop protonmail-bridge-imap-proxy.service protonmail-bridge-smtp-proxy.service protonmail-bridge.service 2>/dev/null || true
echo "Initializing pass keychain for ${BRIDGE_USER} (required by Proton Mail Bridge on Linux)." if [[ "${FIRST_TIME}" == "1" ]]; then
echo "First-time setup: initializing pass keychain for ${BRIDGE_USER} (required by Proton Mail Bridge on Linux)."
install -d -m 0700 -o "${BRIDGE_USER}" -g "${BRIDGE_USER}" "${BRIDGE_HOME}/.gnupg" install -d -m 0700 -o "${BRIDGE_USER}" -g "${BRIDGE_USER}" "${GNUPG_HOME}"
FPR="$(runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${BRIDGE_HOME}/.gnupg" \ FPR="$(runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${GNUPG_HOME}" \
gpg --list-secret-keys --with-colons 2>/dev/null | awk -F: '$1=="fpr"{print $10; exit}')"
if [[ -z "${FPR}" ]]; then
runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${BRIDGE_HOME}/.gnupg" \
gpg --batch --pinentry-mode loopback --passphrase '' \
--quick-gen-key 'ProtonMail Bridge' default default never
FPR="$(runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${BRIDGE_HOME}/.gnupg" \
gpg --list-secret-keys --with-colons 2>/dev/null | awk -F: '$1=="fpr"{print $10; exit}')" gpg --list-secret-keys --with-colons 2>/dev/null | awk -F: '$1=="fpr"{print $10; exit}')"
fi
if [[ -z "${FPR}" ]]; then if [[ -z "${FPR}" ]]; then
echo "Failed to detect a GPG key fingerprint for ${BRIDGE_USER}." >&2 runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${GNUPG_HOME}" \
exit 1 gpg --batch --pinentry-mode loopback --passphrase '' \
fi --quick-gen-key 'ProtonMail Bridge' default default never
runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${BRIDGE_HOME}/.gnupg" \ FPR="$(runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${GNUPG_HOME}" \
pass init "${FPR}" gpg --list-secret-keys --with-colons 2>/dev/null | awk -F: '$1=="fpr"{print $10; exit}')"
fi
if [[ -z "${FPR}" ]]; then
echo "Failed to detect a GPG key fingerprint for ${BRIDGE_USER}." >&2
exit 1
fi
runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" GNUPGHOME="${GNUPG_HOME}" \
pass init "${FPR}"
fi
echo echo
echo "Starting Proton Mail Bridge CLI for one-time login." echo "Starting Proton Mail Bridge CLI."
echo "Run: login" echo "Run: login"
echo "Run: info" echo "Run: info"
echo "Run: exit" echo "Run: exit"
@@ -176,42 +177,21 @@ echo
runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" \ runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" \
protonmail-bridge -c protonmail-bridge -c
touch "${MARKER}" if [[ "${FIRST_TIME}" == "1" ]]; then
chown "${BRIDGE_USER}:${BRIDGE_USER}" "${MARKER}" touch "${MARKER}"
chmod 0644 "${MARKER}" chown "${BRIDGE_USER}:${BRIDGE_USER}" "${MARKER}"
chmod 0644 "${MARKER}"
systemctl daemon-reload
systemctl enable -q --now protonmail-bridge.service
systemctl enable -q --now protonmail-bridge-imap.socket protonmail-bridge-smtp.socket
echo "Initialization complete. Services enabled and started."
EOF
chmod +x /usr/local/bin/protonmailbridge-init
ln -sf /usr/local/bin/protonmailbridge-init /usr/bin/protonmailbridge-init
cat <<'EOF' > /usr/local/bin/protonmailbridge-configure
#!/usr/bin/env bash
set -euo pipefail
BRIDGE_USER="protonbridge"
BRIDGE_HOME="/home/${BRIDGE_USER}"
MARKER="${BRIDGE_HOME}/.protonmailbridge-initialized"
if [[ ! -f "${MARKER}" ]]; then
echo "Not initialized yet. Run:"
echo " protonmailbridge-init"
exit 1
fi fi
systemctl stop protonmail-bridge-imap.socket protonmail-bridge-smtp.socket 2>/dev/null || true
systemctl stop protonmail-bridge-imap-proxy.service protonmail-bridge-smtp-proxy.service protonmail-bridge.service 2>/dev/null || true
runuser -u "${BRIDGE_USER}" -- env HOME="${BRIDGE_HOME}" \
protonmail-bridge -c
systemctl daemon-reload systemctl daemon-reload
systemctl enable -q --now protonmail-bridge.service systemctl enable -q --now protonmail-bridge.service
systemctl enable -q --now protonmail-bridge-imap.socket protonmail-bridge-smtp.socket systemctl enable -q --now protonmail-bridge-imap.socket protonmail-bridge-smtp.socket
if [[ "${FIRST_TIME}" == "1" ]]; then
echo "Initialization complete. Services enabled and started."
else
echo "Configuration complete. Services enabled and started."
fi
EOF EOF
chmod +x /usr/local/bin/protonmailbridge-configure chmod +x /usr/local/bin/protonmailbridge-configure
ln -sf /usr/local/bin/protonmailbridge-configure /usr/bin/protonmailbridge-configure ln -sf /usr/local/bin/protonmailbridge-configure /usr/bin/protonmailbridge-configure