forked from davidnemec/bitwarden-to-keepass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·47 lines (36 loc) · 1.12 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Check that the database password is set
if [ -z "$DATABASE_PASSWORD" ]; then
echo "DATABASE_PASSWORD is not set"
echo -n "Keepass DB password [input is hidden] "
read -r -s DATABASE_PASSWORD
echo
fi
# If BITWARDEN_URL is not empty, set a custom Bitwarden instance
if [ "$BITWARDEN_URL" ]; then
echo "Connecting to Bitwarden instance at $BITWARDEN_URL"
bw config server "$BITWARDEN_URL"
fi
BW_SESSION="$(bw login --raw)"
export BW_SESSION
if [ -z "$BW_SESSION" ]; then
echo "Failed to log in to Bitwarden"
exit 1
fi
# Set environment variables for the script
BW_PATH="$(which bw)"
export BW_PATH
if [ -z "$DATABASE_NAME" ]; then
DATABASE_NAME="bitwarden.kdbx"
fi
DATABASE_PATH="/exports/$DATABASE_NAME"
export DATABASE_PATH
export DATABASE_PASSWORD
# Convert the Bitwarden data to a KeePass file
bw sync || { echo "Failed to sync Bitwarden data"; exit 1; }
echo "Generating KeePass file $DATABASE_PATH"
python3 bitwarden-to-keepass.py || { echo "Failed to convert to KeePass"; exit 1; }
bw lock
# Log out of Bitwarden
bw logout
echo "KeePass file $DATABASE_PATH generated successfully"