commit 286a8dd832713e90a453283e956192fd24991f09
parent ee17ea290a03842fe090f9dd9b822ab3d5421494
Author: breadcat <breadcat@users.noreply.github.com>
Date: Fri, 31 Jul 2026 15:52:24 +0100
Don't create backups and inform user if file was altered
Diffstat:
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/scripts/startpage-sort.nix b/scripts/startpage-sort.nix
@@ -3,9 +3,10 @@
set -euo pipefail
source_file="$HOME/vault/src/startpage/index.html"
- backup="''${source_file}.bak"
+ tmp_file="$(mktemp)"
+ trap 'rm -f "$tmp_file"' EXIT
- cp "$source_file" "$backup"
+ before_sum="$(sha256sum "$source_file" | cut -d" " -f1)"
awk '
function ci_cmp(i1, v1, i2, v2, a, b) {
@@ -70,7 +71,18 @@
{
print
}
- ' "$backup" > "$source_file"
+ ' "$source_file" > "$tmp_file"
+
+ mv "$tmp_file" "$source_file"
+ trap - EXIT
+
+ after_sum="$(sha256sum "$source_file" | cut -d" " -f1)"
+
+ if [ "$before_sum" != "$after_sum" ]; then
+ echo "startpage index.html was reordered"
+ else
+ echo "startpage index.html already sorted, no changes made"
+ fi
'';
in {
environment.systemPackages = [startpage-sort];