#!/bin/bash

# Check if running in WSL
if grep -q "microsoft" /proc/version || grep -q "Microsoft" /proc/version; then
    echo "This script cannot be run in a WSL environment. Aborting."
    exit 1
fi


UUID="5AFD-8706"
MOUNT_POINT="/media/aaden/SWISSBIT"
NEW_ENTRY="UUID=$UUID $MOUNT_POINT vfat defaults,nofail 0 2"

# Ensure the directory exists
sudo mkdir -p "$MOUNT_POINT"

# Backup the current /etc/fstab
sudo cp /etc/fstab /etc/fstab.backup

# Check if the UUID already exists in /etc/fstab
if grep -q "UUID=$UUID" /etc/fstab; then
    # If it exists, replace the line
    sudo sed -i "s|.*UUID=$UUID.*|$NEW_ENTRY|" /etc/fstab
else
    # If it doesn't exist, add the new entry
    echo "$NEW_ENTRY" | sudo tee -a /etc/fstab > /dev/null
fi

# Confirm the changes with mount -a
sudo mount -a

echo "END AUTO CONFIG"
