From 014c9040044741b0a409d1b9608f5016d5175ea4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= <jbb@kaidan.im>
Date: Wed, 8 Feb 2023 21:10:19 +0100
Subject: [PATCH] Add fuclean script

This script deleted all the empty directories of students who have not
submitted anything (for example because there practice partners
submitted the assignment). Excluding those on the whiteboard web
interface does not help here, since then they are not part of the grade
table.
---
 fuclean.sh | 21 +++++++++++++++++++++
 install.sh |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100755 fuclean.sh

diff --git a/fuclean.sh b/fuclean.sh
new file mode 100755
index 0000000..41c0d6e
--- /dev/null
+++ b/fuclean.sh
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+if [ ! -f 'grades.csv' ] && [ ! -f 'grades.xls' ]; then
+    printf "Execute within the directory containing 'grades.csv'\n" >&2
+    exit 1
+fi
+
+# Delete comments.txts so we can more easily delete empty directories.
+# Otherwise they would still contain this one empty file.
+find . -type f -name "comments.txt" -exec rm {} \;
+
+# Delete all empty directories in the directory containing grades.csv
+find . -type d -empty -delete
+
+# Re-create the (now deleted) feedback attachment directories and comments.txts for the student directories that are left.
+for dir in *; do
+	if [ -d "${dir}" ]; then
+		mkdir "${dir}/Feedback Attachment(s)"
+		touch "${dir}/comments.txt"
+	fi
+done
diff --git a/install.sh b/install.sh
index 2b6c8af..4df6257 100755
--- a/install.sh
+++ b/install.sh
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-scripts="fixpdf.sh fucopy.sh fufixpdf.sh fuzip.sh fuxournalexport.sh fixtimes.sh"
+scripts="fixpdf.sh fucopy.sh fufixpdf.sh fuzip.sh fuxournalexport.sh fixtimes.sh fuclean.sh"
 
 destdir="${DESTDIR:=$HOME/.local/bin}"
 mkdir -p "$destdir"
-- 
GitLab