Skip to content

Instantly share code, notes, and snippets.

@michaelmrose
Created July 24, 2025 19:19
Show Gist options
  • Save michaelmrose/e4cc0c33a9f4e3a64903ae8ca7e8888a to your computer and use it in GitHub Desktop.
Save michaelmrose/e4cc0c33a9f4e3a64903ae8ca7e8888a to your computer and use it in GitHub Desktop.

Revisions

  1. michaelmrose created this gist Jul 24, 2025.
    47 changes: 47 additions & 0 deletions smount
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/bash

    set -e

    # Usage message
    if [ "$#" -ne 2 ]; then
    echo "Usage: $0 <device> <mount-point>"
    exit 1
    fi

    DEVICE="$1"
    MOUNT_POINT="$2"

    # Validate device
    if [ ! -b "$DEVICE" ]; then
    echo "Error: $DEVICE is not a block device"
    exit 1
    fi

    # Create mount point if it doesn't exist
    mkdir -p "$MOUNT_POINT"

    # Detect filesystem type
    # FSTYPE=$(blkid -o value -s TYPE "$DEVICE")
    FSTYPE=$(lsblk -no FSTYPE "$DEVICE")

    if [ -z "$FSTYPE" ]; then
    echo "Error: Could not detect filesystem type for $DEVICE"
    exit 1
    fi

    # Get user and group info
    FSUID=$(id -u)
    FSGID=$(getent group users | cut -d: -f3)

    if [ -z "$FSGID" ]; then
    echo "Group 'users' not found, falling back to your primary group"
    GID=$(id -g)
    fi

    # Assemble mount options
    OPTS="uid=$FSUID,gid=$FSGID,umask=000"

    echo "Mounting $DEVICE as $FSTYPE to $MOUNT_POINT with options: $OPTS"

    # Perform the mount
    sudo mount -t "$FSTYPE" -o "$OPTS" "$DEVICE" "$MOUNT_POINT"