Add service to sync keepass db on change
This commit is contained in:
parent
47a0914f75
commit
11b41208a5
@ -292,13 +292,13 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.user.services.keepass-sync = {
|
||||
systemd.user.services.keepass-sync-timer = {
|
||||
Unit.Description = "Sync KeePass database";
|
||||
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
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"
|
||||
''
|
||||
);
|
||||
@ -307,6 +307,46 @@ in
|
||||
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 = {
|
||||
Unit.Description = "Sync Voron2 red gcodes";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user