2023-06-01 19:02:20 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# This script must be run as the same user running offlineimap, which is
|
|
|
|
# preferably a non-privileged user.
|
|
|
|
#
|
|
|
|
# This script should be daemonized (forked to bg) or used as the value of
|
|
|
|
# the ExecStart= directive in a systemd service file.
|
2023-06-02 04:27:56 +02:00
|
|
|
set -exo pipefail
|
2023-06-01 19:02:20 +02:00
|
|
|
|
|
|
|
# If "init" is supplied as arg $1, initialize the bridge.
|
|
|
|
if [[ "$1" == "init" ]]; then
|
|
|
|
|
|
|
|
# Initialize pass
|
|
|
|
gpg --generate-key --batch <<EOF
|
|
|
|
%no-protection
|
|
|
|
%echo Generating a basic OpenPGP key
|
|
|
|
Key-Type: RSA
|
|
|
|
Key-Length: 2048
|
|
|
|
Name-Real: pass-key
|
|
|
|
Expire-Date: 0
|
|
|
|
%commit
|
|
|
|
%echo done
|
|
|
|
EOF
|
|
|
|
pass init pass-key
|
|
|
|
|
|
|
|
# Kill other instance of protonmail-bridge as only one can be running at a
|
|
|
|
# time.
|
|
|
|
pkill protonmail-bridge || true
|
|
|
|
|
|
|
|
# Login
|
|
|
|
protonmail-bridge --cli "$@"
|
|
|
|
else
|
|
|
|
# Start protonmail-bridge in a fake tty, so it does not quit because of EOF.
|
|
|
|
rm -f /tmp/faketty
|
|
|
|
mkfifo /tmp/faketty
|
2023-06-02 04:27:56 +02:00
|
|
|
cat /tmp/faketty | protonmail-bridge --cli "$@"
|
2023-06-01 19:02:20 +02:00
|
|
|
fi
|