#!/bin/bash

set -e

if [ "$EUID" -eq 0 ]; then
    echo "This script should not be run as root. Please run it as a normal user."
    exit 1
fi

if [ -z "$1" ]; then
    echo "Usage: $0 <new-hostname>"
    exit 1
fi

NEW_HOSTNAME="$1"

if ! sudo -v; then
    echo "Sudo access required. Exiting."
    exit 1
fi

mkdir ~/projects
# /bin/bash ./scripts/linux-setup_sudoers.sh

/bin/bash ./scripts/linux-change_hostname.sh "$NEW_HOSTNAME"

echo ""
echo "Installing docker..."
/bin/bash ./scripts/linux-setup_docker.sh

echo ""
echo "Creating internal SSH keys..."
/bin/bash ./scripts/setup_ssh_keys.sh --comment "${USER}@${NEW_HOSTNAME}"

echo ""
echo "Installing packages..."
python3 ./manage.py install linux-vm

echo ""
echo "Linking config..."
python3 ./manage.py link linux-vm --force

echo ""
echo "Updating git remote origin url..."
git remote set-url origin git@gitea.tomastm.com:tomas.mirchev/dotfiles.git

echo ""
echo "Setup complete. Follow the next steps to finalize your environment:"

echo ""
echo "Update your git repository SSH key. Your public key is:"
echo "   $(cat ~/.ssh/id_ed25519.pub)"

echo ""
echo "Start you development with \`dev -i <image> <container_name>\`"
echo "Example: \`dev -i node mybox\`"
echo "You will need to authenticate first: \`docker login registry.tomastm.com\`"
