- Standardize bash shebangs to `#!/usr/bin/env bash` for portability
- Remove `function` keyword from definitions, use `func-name() {` syntax
- Replace `[ ]` conditionals with `[[ ]]` for improved functionality
- Convert local variables to lowercase with `local` keyword
- Update arithmetic comparisons to use `(( ))` syntax
- Enhance `save-dotenv-to-keepass` script with entry existence check and attachment handling
- Fix function name typo in `save-pass-to-keepass`
- Improve CSS formatting and layout for documentation
- Clean up markdown formatting in library and patterns docs
54 lines
1.7 KiB
Bash
Executable File
54 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
save-dotenv-to-keepass() {
|
|
if [[ ! -f .env ]]; then
|
|
echo "No .env file found."
|
|
return 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
|
|
|
|
# Check if the entry already exists
|
|
if echo "$keepass_database_pass" | keepassxc-cli show \
|
|
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
|
--quiet \
|
|
"$KEEPASS_DATABASE_FILE" \
|
|
"$KEEPASS_ENTRY" >/dev/null 2>&1; then
|
|
|
|
echo "Entry '$KEEPASS_ENTRY' already exists."
|
|
|
|
# Try to remove existing .env attachment if it exists
|
|
echo "Removing existing .env attachment (if any)..."
|
|
echo "$keepass_database_pass" | keepassxc-cli attachment-rm \
|
|
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
|
--quiet \
|
|
"$KEEPASS_DATABASE_FILE" \
|
|
"$KEEPASS_ENTRY" \
|
|
".env" 2>/dev/null
|
|
|
|
else
|
|
echo "Creating new entry: $KEEPASS_ENTRY"
|
|
|
|
# Create the entry with a placeholder password (required)
|
|
echo "$keepass_database_pass" | keepassxc-cli add \
|
|
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
|
--quiet \
|
|
--password-prompt \
|
|
"$KEEPASS_DATABASE_FILE" \
|
|
"$KEEPASS_ENTRY" <<< ""
|
|
fi
|
|
|
|
# Attach the .env file
|
|
echo "Attaching .env file..."
|
|
echo "$keepass_database_pass" | keepassxc-cli attachment-import \
|
|
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
|
--quiet \
|
|
"$KEEPASS_DATABASE_FILE" \
|
|
"$KEEPASS_ENTRY" \
|
|
".env" \
|
|
".env"
|
|
|
|
echo "Successfully saved .env as an attachment to '$KEEPASS_ENTRY'."
|
|
} |