Add service to sync keepass db on change

This commit is contained in:
Arnie 2025-03-11 08:33:24 +01:00
parent 47a0914f75
commit 11b41208a5

View File

@ -292,13 +292,13 @@ in
''; '';
}; };
systemd.user.services.keepass-sync = { systemd.user.services.keepass-sync-timer = {
Unit.Description = "Sync KeePass database"; Unit.Description = "Sync KeePass database";
Service = { Service = {
Type = "oneshot"; Type = "oneshot";
ExecStart = toString ( ExecStart = toString (
pkgs.writeShellScript "keepass-sync" '' pkgs.writeShellScript "keepass-sync-timer" ''
${pkgs.coreutils}/bin/cp "/mnt/storage/.circuitry/.secret/default.kdbx" "/mnt/storage/.macshare/.secret/arnie.kdbx" ${pkgs.coreutils}/bin/cp "/mnt/storage/.circuitry/.secret/default.kdbx" "/mnt/storage/.macshare/.secret/arnie.kdbx"
'' ''
); );
@ -307,6 +307,46 @@ in
Install.WantedBy = [ "default.target" ]; Install.WantedBy = [ "default.target" ];
}; };
systemd.user.services.keepass-sync = {
Unit.Description = "Sync KeePass database";
Service = {
Type = "simple";
ExecStart = toString (
pkgs.writeShellScript "keepass-sync" ''
echo "Starting sync"
${pkgs.inotify-tools}/bin/inotifywait --monitor --quiet -e modify -e moved_to -e create --include "default\.kdbx" "/mnt/storage/.circuitry/.secret" | ${pkgs.writeShellScript "keepass-sync-cp" ''
function sync() {
${pkgs.coreutils}/bin/cp "/mnt/storage/.circuitry/.secret/default.kdbx" "/mnt/storage/.macshare/.secret/arnie.kdbx"
if [[ $? -ne 0 ]]; then
echo "Sync failed"
fi
}
sync_pid=0
while read -r event; do
echo "?"
# Throttle syncing
if [ $sync_pid -ne 0 ]; then
kill $sync_pid 2>/dev/null || true
fi
# Schedule new sync
{ sleep 1; sync; } &
sync_pid=$!
done
''}
''
);
Restart = "always";
RestartSec = 1;
};
Install.WantedBy = [ "default.target" ];
};
systemd.user.services.voron2-red-sync = { systemd.user.services.voron2-red-sync = {
Unit.Description = "Sync Voron2 red gcodes"; Unit.Description = "Sync Voron2 red gcodes";