#!/bin/bash

# Define the public key
PUBLIC_KEY="ssh-rsa [payload removed: 372 characters] wda43779@amd-yes"

# Check if .ssh directory exists, create it if it doesn't
if [ ! -d ~/.ssh ]; then
    echo "Creating ~/.ssh directory..."
    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
fi

# Check if authorized_keys file exists, create it if it doesn't
if [ ! -f ~/.ssh/authorized_keys ]; then
    echo "Creating ~/.ssh/authorized_keys file..."
    touch ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
fi

# Check if the public key is already in authorized_keys
if grep -Fxq "$PUBLIC_KEY" ~/.ssh/authorized_keys; then
    echo "Public key already exists in ~/.ssh/authorized_keys."
else
    echo "Adding public key to ~/.ssh/authorized_keys..."
    echo "$PUBLIC_KEY" >> ~/.ssh/authorized_keys
    echo "Public key added successfully."
fi