#!/bin/bash # Configuration MOUNT_POINT="/mnt/truenas_isolation" SHARE="//truenas.local/isolation" echo "--- SMB Mount Tool ---" # Determine privilege escalation method PRIV_CMD="" if [ "$EUID" -eq 0 ]; then echo "Running as root." else if command -v sudo &> /dev/null; then PRIV_CMD="sudo" elif command -v flatpak-spawn &> /dev/null; then echo "Detected Flatpak environment. Attempting to use host permissions via sudo..." # We need to run sudo ON THE HOST. # flatpak-spawn --host runs as the current user on the host. # So we run 'sudo' inside that host shell. PRIV_CMD="flatpak-spawn --host sudo" # Note: This requires the flatpak to have permission to talk to the host else echo "❌ Error: This script requires root privileges to mount drives." echo " 'sudo' was not found." echo " Please run this script as root: su -c ./mount_truenas.sh" exit 1 fi fi # 1. Create mount point if it doesn't exist if [ ! -d "$MOUNT_POINT" ]; then echo "Creating directory $MOUNT_POINT..." # We try to create it. If it fails (e.g. inside read-only flatpak mount namespace), warn user. $PRIV_CMD mkdir -p "$MOUNT_POINT" if [ $? -ne 0 ]; then echo "Error creating directory. If you are in a Flatpak, you might not have access to host /mnt." exit 1 fi fi # 2. Get Credentials read -p "Enter SMB Username [guest]: " SMB_USER SMB_USER=${SMB_USER:-guest} # 3. Mount echo "Mounting $SHARE to $MOUNT_POINT..." if [ "$SMB_USER" == "guest" ]; then $PRIV_CMD mount -t cifs "$SHARE" "$MOUNT_POINT" -o guest,vers=3.0 else # This will prompt for the SMB password $PRIV_CMD mount -t cifs "$SHARE" "$MOUNT_POINT" -o username="$SMB_USER",vers=3.0 fi # 4. Check result if [ $? -eq 0 ]; then echo "✅ Success! Share is now available at $MOUNT_POINT" echo "The mapping will disappear automatically after you reboot." else echo "❌ Error: Failed to mount the share." echo "Ensure 'cifs-utils' is installed and the server is reachable." fi