From da6877af61d5e9bed1a1ec9361c40ab4e377c7fd Mon Sep 17 00:00:00 2001 From: Mattia Mascarello Date: Wed, 14 Jan 2026 01:48:38 +0100 Subject: [PATCH] First commit --- lightdm_add.conf | 3 +++ notice.py | 31 +++++++++++++++++++++++++++++++ prepare-guest-home.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lightdm_add.conf create mode 100755 notice.py create mode 100644 prepare-guest-home.sh diff --git a/lightdm_add.conf b/lightdm_add.conf new file mode 100644 index 0000000..b32a168 --- /dev/null +++ b/lightdm_add.conf @@ -0,0 +1,3 @@ +[Seat:*] +session-setup-script=/usr/local/sbin/prepare-guest-home.sh +session-cleanup-script=/usr/local/sbin/prepare-guest-home.sh diff --git a/notice.py b/notice.py new file mode 100755 index 0000000..c0fd5cd --- /dev/null +++ b/notice.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# To put in home directory autoexec +import sys +from PyQt5.QtWidgets import QApplication, QMessageBox +from PyQt5.QtCore import Qt + +# Create a Qt application +app = QApplication(sys.argv) + +# Create a message box +msg = QMessageBox() +msg.setIcon(QMessageBox.Information) + +msg.setWindowTitle("Welcome into the guest account!") +msg.setText("Welcome!\nThis is an ephemeral session.\n\nAll the changes made will be reverted at logout.\nPlease save your work elsewhere.\n\nFor more information, contact the administrator.") +msg.setStandardButtons(QMessageBox.Ok) + + + + +# Set the window flags to remove all buttons (minimize, maximize, close) +msg.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) + +# Disable resizing by setting a fixed size +msg.setFixedSize(400, 200) + +# Make the window modal (optional, to block interaction with other windows) +msg.setWindowModality(Qt.ApplicationModal) + +# Show the message box in the center of the screen +msg.exec_() diff --git a/prepare-guest-home.sh b/prepare-guest-home.sh new file mode 100644 index 0000000..06fc23e --- /dev/null +++ b/prepare-guest-home.sh @@ -0,0 +1,34 @@ +set -euo pipefail + +if [ "$USER" != "guest" ]; then + exit 0 +fi + +GUEST_HOME="/home/guest" +SKELETON="/home/guest-freeze" + +# Validate guest home directory: check if it's a symlink +if [ -L "$GUEST_HOME" ]; then + echo "Home directory is a symlink. Removing it and restoring as a directory." + rm -f "$GUEST_HOME" # Remove the symlink + + # Recreate the home directory as a proper directory + mkdir -p "$GUEST_HOME" +fi + +# Validate guest home directory exists and is not a symlink +if [ ! -d "$GUEST_HOME" ]; then + echo "Unsafe guest home or home directory creation failed." + exit 1 +fi + +# Remove contents safely (if any) while ignoring "file not found" errors +find "$GUEST_HOME" -mindepth 1 -xdev -exec rm -rf -- {} + 2>/dev/null || true + +# Restore skeleton safely +rsync -a --safe-links --no-devices --no-specials \ + "$SKELETON"/ "$GUEST_HOME"/ + +# Fix ownership and permissions +chown -R guest:guest "$GUEST_HOME" +chmod 700 "$GUEST_HOME"