#!/bin/bash # setup: # sudo apt install libsecret-tools # secret-tool store --label="KeePass safe" keepass safe function start(){ success=1 cntr=0 # this loop helped making the re-opening of the database after a screen unlock more reliable while [ $success -gt 0 ]; do pwd=$(secret-tool lookup keepass safe) success=$? if [ $success -gt 0 ]; then sleep 5 fi let cntr++ if [ $cntr -gt 12 ]; then notify-send 'Keepass Autolaunch' 'Could not get the Masterkey from the Gnome Keechain, starting Keepass with locked DB' break fi done echo $pwd | keepassxc --pw-stdin ~/path/to/keepass_file.kdbx >/dev/null 2>/dev/null & } start # register dbus-monitor script to unlock keepass after unlocking a gnome session gdbus monitor -y -d org.freedesktop.login1 | while read x; do if echo "$x" | grep -q "'LockedHint': "; then killall keepassxc start fi done >/dev/null 2>/dev/null &