Add service to sync keepass db on change
This commit is contained in:
parent
47a0914f75
commit
7e7a9707a3
@ -292,7 +292,7 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.user.services.keepass-sync = {
|
||||
systemd.user.services.keepass-sync-timer = {
|
||||
Unit.Description = "Sync KeePass database";
|
||||
|
||||
Service = {
|
||||
@ -307,6 +307,45 @@ 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 "/mnt/storage/.circuitry/.secret/default.kdbx" | ${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
|
||||
# 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