#!/bin/bash

# Variables
REMOTE_NAME="gdrive"  # Name of your rclone remote for Google Drive
MOUNT_POINT="/mnt/gdrive"  # Mount point

# Create the mount point if it doesn't exist
if [ ! -d "$MOUNT_POINT" ]; then
    echo "Creating mount point at $MOUNT_POINT..."
    sudo mkdir -p "$MOUNT_POINT"
fi

# Check if rclone is installed
if ! command -v rclone &> /dev/null; then
    echo "rclone is not installed. Installing it now..."
    curl https://rclone.org/install.sh | sudo bash
fi

# Mount the Google Drive folder
echo "Mounting Google Drive to $MOUNT_POINT..."
rclone mount "$REMOTE_NAME": "$MOUNT_POINT" --daemon --vfs-cache-mode minimal --allow-other

# Check if the mount was successful
if mount | grep "$MOUNT_POINT" > /dev/null; then
    echo "Google Drive successfully mounted to $MOUNT_POINT."
else
    echo "Failed to mount Google Drive. Please check your rclone configuration."
    exit 1
fi