ps2_samba_arch/ps2_samba.sh

67 lines
1.5 KiB
Bash

#!/bin/bash
set -e
# Get the real 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 the shared directory if it doesn't exist
echo "[*] Creating share directory at $SHARE_DIR..."
mkdir -p "$SHARE_DIR"
chown "$REALUSER:$REALUSER" "$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 <<EOF
[global]
workgroup = WORKGROUP
server string = Arch SMB Server
security = user
map to guest = Bad User
name resolve order = bcast host
server min protocol = LANMAN1
client min protocol = NT1
client max protocol = NT1
ntlm auth = yes
lanman auth = yes
client lanman auth = yes
client plaintext auth = yes
log level = 3
[PS2SMB]
path = $SHARE_DIR
browseable = yes
read only = no
guest ok = yes
force user = $REALUSER
EOF
# Enable and start Samba
echo "[*] Enabling and starting Samba service..."
systemctl enable smb --now
echo "[✓] Done. Samba is running and sharing $SHARE_DIR as user $REALUSER"