#!/bin/bash

# Check if the script is being run as root
if [ "$(id -u)" -ne 0 ]; then
    echo "This script must be run as root."
    exit 1
fi

# Set variables
URL="https://www.dlee.org/teamtalk/tt/tt.tgz"
TEMP_DIR="/tmp/tt_download"
DEST_DIR="/usr/local/bin"

# Create a temporary directory for the download
mkdir -p $TEMP_DIR >/dev/null 2>&1

# Navigate to the temporary directory
cd $TEMP_DIR >/dev/null 2>&1

# Download the file
echo "Downloading tt..."
wget $URL -O tt.tgz >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "Failed to download tt."
    exit 1
fi

# Extract the file to the destination directory
echo "Extracting tt..."
tar -xzf tt.tgz -C $DEST_DIR >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "Failed to extract tt."
    exit 1
fi

# Clean up temporary files
echo "Cleaning up temporary files..."
rm -rf $TEMP_DIR >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "Failed to clean up temporary files"
    exit 1
fi

# Print success message
echo "tt is installed. To use, run \"tt <your_command>\" as root."