#!/bin/bash

# Function to log messages
logMessage() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> /data/log/SFKUSB.log
}

# Detect the USB mount point (assumes it's mounted at /media/ or a similar location)
USB_MOUNT=$(ls /media | grep -v "pre-hook.sh")

if [ -z "$USB_MOUNT" ]; then
    logMessage "No USB drive found."
    exit 1
fi

USB_MOUNT="/media/$USB_MOUNT"
logMessage "USB drive detected at $USB_MOUNT."

# Get the base directory path
# BASE_DIR="$USB_MOUNT/Driver Help File"
BASE_DIR="$USB_MOUNT/Driver Diagnostic File"

# Create the base directory on the USB drive
mkdir -p "$BASE_DIR"
if [ $? -eq 0 ]; then
    logMessage "Created base directory: $BASE_DIR."
else
    logMessage "Failed to create base directory: $BASE_DIR."
    exit 1
fi

# Create required subdirectories on USB
mkdir -p "$BASE_DIR/SFKVirtualBattery"
mkdir -p "$BASE_DIR/serial-starter"
mkdir -p "$BASE_DIR/start-gui"
mkdir -p "$BASE_DIR/dbus-systemcalc-py"
mkdir -p "$BASE_DIR/localsettings"
mkdir -p "$BASE_DIR/vrmlogger"
mkdir -p "$BASE_DIR/dbus-sfkdriver"
# New ones:
mkdir -p "$BASE_DIR/gui"
mkdir -p "$BASE_DIR/SFKsettinginstallation"
mkdir -p "$BASE_DIR/vedbusservice_SFKvb"

logMessage "Created additional subdirectories under $BASE_DIR."
