#!/bin/sh

# POSIX-compliant script for mounting a remote directory using sshfs over Tor

# Check for required commands
if ! command -v sshfs &> /dev/null; then
    echo "Error: sshfs command not found. Please install sshfs and try again."
    exit 1
fi
if ! command -v torify &> /dev/null; then
    echo "Error: torify command not found. Please install tor and try again."
    exit 1
fi

# Get player key
if [ -z "$MUD_PLAYER" ]; then
    echo "Error: MUD_PLAYER environment variable not set."
    exit 1
fi
player_key="$HOME/.ssh/$MUD_PLAYER"

# Get tor address and remote directory
read -p "Enter the Tor address of the remote server (e.g. onion.example.com): " tor_address
read -p "Enter the remote directory to mount (e.g. /mnt/remote): " remote_dir

# Strip or add trailing slashes as required by sshfs
remote_dir="${remote_dir%/}/"

# Mount the remote directory using sshfs over tor
torify sshfs -o IdentityFile="$player_key" "$tor_address:$remote_dir" "$remote_dir"