Files
qbittorrent-performer-sorter/mount_isolation.sh
T

40 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status
set -e
SHARE="//truenas.local/isolation"
MOUNT_POINT="/mnt/isolation"
USERNAME="home"
PASSWORD="kifer"
# Ensure cifs-utils is installed (required for mounting SMB shares)
if ! dpkg -s cifs-utils >/dev/null 2>&1; then
echo "Installing required package 'cifs-utils'..."
sudo apt-get update && sudo apt-get install -y cifs-utils
fi
# Create target mount directory if it doesn't exist
if [ ! -d "$MOUNT_POINT" ]; then
echo "Creating mount directory $MOUNT_POINT..."
sudo mkdir -p "$MOUNT_POINT"
fi
# Check if already mounted
if mountpoint -q "$MOUNT_POINT"; then
echo "Directory is already mounted. Unmounting first..."
sudo umount "$MOUNT_POINT"
fi
echo "Mounting $SHARE to $MOUNT_POINT..."
# Mount temporarily. Using uid/gid configuration allows your local user to read/write to the share.
# Fetch the real calling user's UID and GID (when run under sudo, $SUDO_UID gives the original user)
CURRENT_UID="${SUDO_UID:-$(id -u)}"
CURRENT_GID="${SUDO_GID:-$(id -g)}"
sudo mount -t cifs "$SHARE" "$MOUNT_POINT" \
-o username="$USERNAME",password="$PASSWORD",uid="$CURRENT_UID",gid="$CURRENT_GID",file_mode=0777,dir_mode=0777,iocharset=utf8,noperm
echo "Successfully mounted $SHARE to $MOUNT_POINT."
echo "Note: This mount is temporary and will automatically unmount upon reboot."