#!/bin/bash

# # Variables
# DB_PATH="/home/greg/Nextcloud2/Backups/keepass.kdbx"
# ENTRY_NAME="logseq"
# VAULT_LOCATION="/home/greg/.cryfs/logseq"
# MOUNT_POINT="/home/greg/cryfs/logseq"  # Change this to your CryFS mount point
# 
# # Retrieve the password from the KeePassXC database
# CREDENTIALS=$(keepassxc-cli show -s "$DB_PATH" "$ENTRY_NAME")
# PASSWORD=$(echo "$CREDENTIALS" | grep 'Password:' | cut -d ' ' -f 2)
# 
# # Check if the password was retrieved successfully
# if [ $? -ne 0 ]; then
#     echo "Failed to retrieve the password from the database."
#     exit 1
# fi
# 
# # Unlock the CryFS volume
# cryfs "$VAULT_LOCATION" "$MOUNT_POINT" <<< "$PASSWORD"
# 
# # Check if the CryFS command was successful
# if [ $? -eq 0 ]; then
#     echo "CryFS volume unlocked successfully."
#     logseq
#     cryfs-unmount "$MOUNT_POINT"
# else
#     echo "Failed to unlock the CryFS volume."
#     exit 1
# fi

#!/bin/bash

# Variables
DB_PATH="/home/greg/Nextcloud2/Backups/keepass.kdbx"
ENTRY_NAME="logseq"
VAULT_LOCATION="/home/greg/.cryfs/logseq"
MOUNT_POINT="/home/greg/cryfs/logseq"  # Change this to your CryFS mount point

# Retrieve the password from the KeePassXC database using zenity
KEEPASS_PASSWORD=$(zenity --password --title="Cumseq" --text="Enter the password for the KeePass database:")

# Check if the user canceled the dialog
if [ $? -ne 0 ]; then
    notify-send "Password retrieval canceled."
    exit 1
fi

CREDENTIALS=$(keepassxc-cli show -s "$DB_PATH" "$ENTRY_NAME" <<< "$KEEPASS_PASSWORD")

if [ $? -ne 0 ]; then
    notify-send "KeePassXC error" "Was the master password correct?"
    exit 1
fi

PASSWORD=$(echo "$CREDENTIALS" | grep 'Password:' | cut -d ' ' -f 2)

# Unlock the CryFS volume
cryfs "$VAULT_LOCATION" "$MOUNT_POINT" <<< "$PASSWORD"

# Check if the CryFS command was successful
if [ $? -eq 0 ]; then
    notify-send "Success" "CryFS volume unlocked successfully."
    logseq
    cryfs-unmount "$MOUNT_POINT"
    noity-send "Loseq session finished" "CryFS volume will now be unmounted."
    exit 0
else
    notify-send "Error" "Failed to unlock the CryFS volume."
    exit 1
fi

