protonmail-bridge/initproton
Michael Gibson 89cff04248
All checks were successful
continuous-integration/drone/tag Build is passing
Setup cleanup.
2020-08-19 12:06:45 -05:00

40 lines
No EOL
973 B
Bash
Executable file

#!/bin/bash
set -eufo pipefail
BRIDGE=/bin/protonmail-bridge
FIFO=/tmp/fifo
PRINT_INFO=${PRINT_INFO:-""}
#### INIT
PASS_FILE=${PASS_FILE:-}
if [ -n "$PASS_FILE" ]; then
PASS=$(cat $PASS_FILE)
fi
if ! [ -d .gnupg ]; then
echo -e "%no-protection\nKey-Type: RSA\nKey-Length: 4096\nName-Real: $EMAIL\nExpire-Date: 0\n%commit" \
| gpg --generate-key --batch
fi
if ! [ -d .password-store ]; then
pass init "$EMAIL"
fi
if ! [ -d ~/.cache/protonmail/bridge ]; then
COMMAND="login\n$EMAIL\n$PASSWORD"
MFA_CODE=${MFA_CODE:-}
if [ -n "$MFA_CODE" ]; then
COMMAND="$COMMAND\n$MFA_CODE"
fi
echo -e "$COMMAND" | $BRIDGE --cli
fi
if [ -n "$PRINT_INFO" ]; then
echo info | $BRIDGE --cli | egrep '(Username|Password)' | sort -ru
fi
ARGUMENTS="--noninteractive"
LOG_LEVEL=${LOG_LEVEL:-}
if [ -n "$LOG_LEVEL" ]; then
ARGUMENTS="${ARGUMENTS} --log-level ${LOG_LEVEL}"
fi
$BRIDGE $ARGUMENTS