From 715644a3ed1e5672775689c534ee9c1e82e92025 Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Sun, 4 May 2025 13:33:32 +0000 Subject: [PATCH] =?UTF-8?q?ps2=5Fsamba.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ps2_samba.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ps2_samba.sh diff --git a/ps2_samba.sh b/ps2_samba.sh new file mode 100644 index 0000000..d23b700 --- /dev/null +++ b/ps2_samba.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +set -e + +# Get the current user (not root) +REALUSER=$(logname) +HOME_DIR=$(eval echo "~$REALUSER") +SHARE_DIR="$HOME_DIR/PS2SMB" + +# Ensure script is run as root +if [ "$(id -u)" -ne 0 ]; then + echo "Please run this script as root (e.g. with sudo)." + exit 1 +fi + +echo "[*] Checking if Samba is installed..." +if ! pacman -Q samba &>/dev/null; then + echo "[+] Samba not found. Installing..." + pacman -Sy --noconfirm samba +else + echo "[✓] Samba is already installed." +fi + +# Create PS2 user if it doesn't exist +if ! id "PS2" &>/dev/null; then + echo "[*] Creating user 'PS2'..." + useradd -M -s /usr/bin/nologin PS2 +else + echo "[✓] User 'PS2' already exists." +fi + +# Create the shared directory if it doesn't exist +echo "[*] Creating share directory at $SHARE_DIR..." +mkdir -p "$SHARE_DIR" +chown "$REALUSER:$REALUSER" "$SHARE_DIR" + +# Set ACLs so PS2 has full access +echo "[*] Setting ACLs for user 'PS2' on $SHARE_DIR..." +setfacl -R -m u:PS2:rwx "$SHARE_DIR" +setfacl -R -d -m u:PS2:rwx "$SHARE_DIR" + +# Backup original smb.conf +if [ -f /etc/samba/smb.conf ]; then + echo "[*] Backing up existing /etc/samba/smb.conf to /etc/samba/smb.conf.bak" + cp /etc/samba/smb.conf /etc/samba/smb.conf.bak +fi + +# Write the Samba config +echo "[*] Writing new Samba configuration..." +cat > /etc/samba/smb.conf <