#!/bin/bash RED="\e[0;31m" GREEN="\e[0;32m" YELLOW="\e[0;33m" ENDCOLOR="\e[0m" BOLDGREEN="\e[1;32m" BOLDRED="\e[1;31m" BOLDYELLOW="\e[1;33m" SSHKEYFILE=~/.ssh/github GIT_PACKAGE=$(which git) clear echo -e "${YELLOW}Checking if Git is installed" if [[ ! -z $GIT_PACKAGE ]]; then echo -e "${BOLDGREEN}Git is installed" else echo -e "${BOLDYELLOW}Installing Git" sudo apt update &>/dev/null sudo apt install git -y &>/dev/null if [[ ! -z $GIT_PACKAGE ]]; then echo -e "${BOLDGREEN}Git installed successfully" fi fi echo -e "${ENDCOLOR}-------------------------" echo -e "${YELLOW}Checking if SSH key for Github exists" if [ -f "$SSHKEYFILE" ]; then echo -e "${BOLDGREEN}SSH key for Github exists" else echo -e "${BOLDYELLOW}SSH key for Github does not exist. Generating...${ENDCOLOR}" ssh-keygen -t ed25519 -C "kristocopani@gmail.com" -f $SSHKEYFILE -q -N "" fi echo -e "${ENDCOLOR}-------------------------" echo -e "${YELLOW}Adding key to SSH agent" eval "$(ssh-agent -s)" &>/dev/null ssh-add $SSHKEYFILE &>/dev/null echo -e "${YELLOW}Add key to your Github account to proceed${ENDCOLOR}" SSHKEYVALUE=$(<$SSHKEYFILE.pub) echo -e "${ENDCOLOR}-------------------------" echo -e "${BOLDGREEN}This is your key:" echo -e "${BOLDGREEN}$SSHKEYVALUE" echo -e "${ENDCOLOR}-------------------------" echo "Checking if SSH key is added to Github. If it's not, add it and the script will continue automatically" while true; do output=$(ssh -o "StrictHostKeyChecking no" git@github.com 2>&1) if [[ $output =~ "Permission denied (publickey)" ]]; then sleep 5 # Adjust the sleep interval as needed else break fi done echo -e "${BOLDGREEN}SSH key successfully added to Github!" echo -e "${ENDCOLOR}-------------------------" echo -e "${YELLOW}Cloning Ansible repo${ENDCOLOR}" cd ~/ git clone git@github.com:kristocopani/ansible.git --quiet echo -e "${ENDCOLOR}-------------------------" echo -e "${GREEN}DONE!"