Files
scripts/shell/mount_ssd.sh
2025-09-18 11:35:56 +02:00

41 lines
1021 B
Bash
Executable File

#!/bin/bash
# Configuration
SSD_LABEL="Pass500" # Replace this with the label of your SSD
MOUNT_POINT="$HOME/ExternalSSD" # Directory to mount the SSD
# Check if the SSD is connected
SSD_DEVICE=$(lsblk -l -o LABEL,NAME | grep "$SSD_LABEL" | awk '{print $2}')
if [ -z "$SSD_DEVICE" ]; then
echo "The external SSD ($SSD_LABEL) is not connected."
exit 1
fi
SSD_DEVICE="/dev/$SSD_DEVICE"
# Check if the directory exists; if not, create it
if [ ! -d "$MOUNT_POINT" ]; then
mkdir -p "$MOUNT_POINT"
echo "Created mount point at $MOUNT_POINT."
fi
# Mount the SSD
sudo mount "$SSD_DEVICE" "$MOUNT_POINT"
if [ $? -ne 0 ]; then
echo "Failed to mount $SSD_DEVICE to $MOUNT_POINT."
exit 1
fi
# Change ownership to the current user
sudo chown -R "$(id -u):$(id -g)" "$MOUNT_POINT"
if [ $? -ne 0 ]; then
echo "Failed to set ownership for $MOUNT_POINT."
exit 1
fi
echo "Successfully mounted $SSD_LABEL at $MOUNT_POINT."
# Change to the mounted directory and open a shell
cd "$MOUNT_POINT" || exit
exec $SHELL