Files
git.taskfile.build/bin/save-pass-to-keepass
T

36 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
save-pass-to-keepass() {
if [[ -z "$1" ]]; then
echo "\$1 (password) is empty."
exit 1
fi
if [[ -z "$2" ]]; then
echo "\$2 (entry path) is empty."
exit 1
fi
local password="$1"
local keepass_entry="$2"
if [[ ! -f "$KEEPASS_DATABASE_FILE" ]]; then
echo "Keepass database file not found: $KEEPASS_DATABASE_FILE"
exit 1
fi
if [[ ! -f "$KEEPASS_DATABASE_KEY_FILE" ]]; then
echo "Keepass database key file not found: $KEEPASS_DATABASE_KEY_FILE"
exit 1
fi
# Prompt for KeePass database password silently
read -s -p "Enter password to unlock $KEEPASS_DATABASE_FILE: " keepass_database_pass
echo # Add a newline after password input
echo "Saving password to keepass entry: $keepass_entry"
echo "$keepass_database_pass" | keepassxc-cli add \
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
--password-prompt \
"$KEEPASS_DATABASE_FILE" \
"$keepass_entry" <<< "$password"
}