From 99d7bd64db25014a626a5acc3692cf8e3e221a36 Mon Sep 17 00:00:00 2001 From: Raphael Dannecker Date: Wed, 4 Dec 2024 12:08:28 +0100 Subject: [PATCH] Exam users uid always changes, therefore their home directory must be deleted --- roles/lmn_localhome/files/rmexam.service | 6 ++++++ roles/lmn_localhome/files/rmexam.timer | 8 ++++++++ roles/lmn_localhome/tasks/main.yml | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 roles/lmn_localhome/files/rmexam.service create mode 100644 roles/lmn_localhome/files/rmexam.timer diff --git a/roles/lmn_localhome/files/rmexam.service b/roles/lmn_localhome/files/rmexam.service new file mode 100644 index 0000000..81509a6 --- /dev/null +++ b/roles/lmn_localhome/files/rmexam.service @@ -0,0 +1,6 @@ +[Unit] +Description=Remove -exam homes older than 12h + +[Service] +Type=simple +ExecStart=find /home/ -maxdepth 1 -mindepth 1 -name '*-exam' -type d -cmin +720 -exec rm -rf {} \; diff --git a/roles/lmn_localhome/files/rmexam.timer b/roles/lmn_localhome/files/rmexam.timer new file mode 100644 index 0000000..7fba65d --- /dev/null +++ b/roles/lmn_localhome/files/rmexam.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run rmexam after boot + +[Timer] +OnBootSec=0min + +[Install] +WantedBy=timers.target diff --git a/roles/lmn_localhome/tasks/main.yml b/roles/lmn_localhome/tasks/main.yml index 1f8b499..e6407a6 100644 --- a/roles/lmn_localhome/tasks/main.yml +++ b/roles/lmn_localhome/tasks/main.yml @@ -33,3 +33,19 @@ dest: /etc/profile.d/lmn-logout.sh content: | [[ "${UID}" -gt 10000 ]] && ! findmnt "/lmn/media/${USER}/home" > /dev/null && exit 0 + +- name: Provide rmexam services and timers for some scripts + copy: + src: "{{ item }}" + dest: "/etc/systemd/system/{{ item }}" + mode: 0644 + loop: + - rmexam.service + - rmexam.timer + when: "'teacherlaptop' not in group_names" + +- name: Enable rmexam.timer + systemd: + name: rmexam.timer + enabled: true + when: "'teacherlaptop' not in group_names"