summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaa <kaa@disroot.org>2024-08-10 01:41:58 -0700
committerkaa <kaa@disroot.org>2024-08-10 01:41:58 -0700
commit1d1e425b07bbb7ae04f9c7db269c359ebcdab246 (patch)
treea23e7b7e604abf236da7b6aae3e876b0edc84bf4
Public release.HEADmaster
-rwxr-xr-xcheck.rc22
-rwxr-xr-xdedup.rc3
-rwxr-xr-xdel.rc8
3 files changed, 33 insertions, 0 deletions
diff --git a/check.rc b/check.rc
new file mode 100755
index 0000000..099bce7
--- /dev/null
+++ b/check.rc
@@ -0,0 +1,22 @@
+#!/usr/local/plan9/bin/rc
+
+fn sum {
+ find . -type f | while (file = `{read}) {
+ if (test -f $"file ) {
+ sha256 $"file
+ }
+ }
+}
+
+previous = ''
+sum | sed -E -e 's/(.*) = (.*)/\2 \1/' -e 's/SHA256 .//' -e 's/.$//' | sort | \
+ tee sum | while (line = `{read}) {
+#cat sum | while (line = `{read}) {
+ sum = `{echo $line | sed -E -e 's/([^ ]*) (.*)/\1/'}
+ file = `{echo $line | sed -E -e 's/([^ ]*) (.*)/\2/'}
+ if (~ $sum $previous) {
+ echo $"file is a duplicate.
+ }
+
+ previous = $sum
+}
diff --git a/dedup.rc b/dedup.rc
new file mode 100755
index 0000000..3077b63
--- /dev/null
+++ b/dedup.rc
@@ -0,0 +1,3 @@
+#!/usr/local/plan9/bin/rc
+
+./check.rc | ./del.rc
diff --git a/del.rc b/del.rc
new file mode 100755
index 0000000..6d05801
--- /dev/null
+++ b/del.rc
@@ -0,0 +1,8 @@
+#!/usr/local/plan9/bin/rc
+
+sed -e 's/ is a duplicate.$//' | while (file = `{read}) {
+ if (test -f $"file) {
+ echo rm $"file >> /mnt/mem/log
+ rm $"file
+ }
+}