syncthing: add yncthing-resolve-conflicts script
This commit is contained in:
parent
a37e4720ca
commit
17789ce55d
3 changed files with 53 additions and 1 deletions
|
|
@ -1,10 +1,17 @@
|
||||||
{ config, lib, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.syncthing;
|
cfg = config.services.syncthing;
|
||||||
guiPort = 8384;
|
guiPort = 8384;
|
||||||
transferPort = 22000;
|
transferPort = 22000;
|
||||||
fqdn = "sync.local";
|
fqdn = "sync.local";
|
||||||
|
# TODO: look into https://github.com/dschrempf/syncthing-resolve-conflicts
|
||||||
|
syncthing-resolve-conflicts = pkgs.callPackage ./syncthing-resolve-conflicts.nix { };
|
||||||
|
|
||||||
user = "sid";
|
user = "sid";
|
||||||
dirs = [
|
dirs = [
|
||||||
|
|
@ -81,6 +88,10 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = [
|
||||||
|
syncthing-resolve-conflicts
|
||||||
|
];
|
||||||
|
|
||||||
sops.secrets."syncthing/gui-pw" = {
|
sops.secrets."syncthing/gui-pw" = {
|
||||||
owner = cfg.user;
|
owner = cfg.user;
|
||||||
group = cfg.group;
|
group = cfg.group;
|
||||||
|
|
|
||||||
13
modules/nixos/syncthing/syncthing-resolve-conflicts.nix
Normal file
13
modules/nixos/syncthing/syncthing-resolve-conflicts.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
writeShellApplication,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
name = "syncthing-resolve-conflicts";
|
||||||
|
text = builtins.readFile ./${name}.sh;
|
||||||
|
in
|
||||||
|
writeShellApplication {
|
||||||
|
inherit name text;
|
||||||
|
meta.mainProgram = name;
|
||||||
|
}
|
||||||
28
modules/nixos/syncthing/syncthing-resolve-conflicts.sh
Normal file
28
modules/nixos/syncthing/syncthing-resolve-conflicts.sh
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
DRY_RUN=true
|
||||||
|
|
||||||
|
if [[ "${1:-}" == "--apply" ]]; then
|
||||||
|
DRY_RUN=false
|
||||||
|
echo "--- RUNNING IN LIVE MODE: Files will be renamed ---"
|
||||||
|
else
|
||||||
|
echo "--- RUNNING IN DRY-RUN MODE: No changes will be made ---"
|
||||||
|
echo "--- Use 'syncthing-resolve-conflicts --apply' to perform the rename ---"
|
||||||
|
fi
|
||||||
|
|
||||||
|
find . -type f -name "*sync-conflict*" ! -name "*.db" -print0 | while IFS= read -r -d '' file; do
|
||||||
|
new=$(echo "$file" | sed -E 's/\.sync-conflict-[0-9]{8}-[0-9]{6}-[A-Z0-9]+//')
|
||||||
|
|
||||||
|
if [[ "$file" != "$new" ]]; then
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
echo "[DRY-RUN] Would rename: '$file' -> '$new'"
|
||||||
|
else
|
||||||
|
if [[ -f "$new" ]]; then
|
||||||
|
echo "[SKIP] Target already exists: '$new'"
|
||||||
|
else
|
||||||
|
echo "Renaming: '$file' -> '$new'"
|
||||||
|
mv "$file" "$new"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "--- Done ---"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue