#!/usr/bin/env bash set -euo pipefail # Check for sudo/root if [ "$EUID" -ne 0 ]; then echo "This script must be run with sudo or as root." exit 1 fi # Determine the real user’s home (so we don't install config into /root) if [ -n "${SUDO_USER-}" ] && [ "${SUDO_USER}" != "root" ]; then USERNAME="${SUDO_USER}" else USERNAME="$(id -un)" fi USER_HOME="$(getent passwd "$USERNAME" | cut -d: -f6)" echo "Installing tmate for user: $USERNAME (home: $USER_HOME)" # Update package list and install tmate apt-get update apt-get install -y tmate # Prepare config file path CONFIG="$USER_HOME/.tmate.conf" # Backup existing config if present if [ -f "$CONFIG" ]; then BACKUP="$CONFIG.bak.$(date +'%Y%m%d%H%M%S')" echo "Backing up existing $CONFIG → $BACKUP" cp "$CONFIG" "$BACKUP" fi # Write new config cat << 'EOF' > "$CONFIG" set -g tmate-server-host borohov.net set -g tmate-server-port 2223 set -g tmate-server-rsa-fingerprint SHA256:F5t1Hh8y7S7e6k/Td6htGUTcB4IDtYfMcN+UPYscLv0 set -g tmate-server-ed25519-fingerprint SHA256:oJ8kl6VOJrHQLyPTNUQrrcPA7OyzuYzkwSCr9uZdHpQ EOF # Ensure ownership and permissions chown "$USERNAME":"$USERNAME" "$CONFIG" chmod 600 "$CONFIG" echo "✅ tmate installed and configuration written to $CONFIG" echo "Start your first session with 'tmate'"