Skip to content

Instantly share code, notes, and snippets.

@OnCloud125252
Created December 16, 2024 16:06
Show Gist options
  • Save OnCloud125252/0d13676b04fc3b2a365b8b78707acc4d to your computer and use it in GitHub Desktop.
Save OnCloud125252/0d13676b04fc3b2a365b8b78707acc4d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Colors
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Symbols
CHECKMARK='\xE2\x9C\x94'
ROCKET='\xF0\x9F\x9A\x80'
CROSSMARK='\xE2\x9C\x98'
HOURGLASS='\xE2\x8C\x9B'
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if GitHub username argument is provided
if [ -z "$1" ]; then
echo -e "${RED}$CROSSMARK Error: No GitHub username provided.${NC}"
echo "Usage: $0 <githubUserName>"
exit 1
fi
GITHUB_USERNAME=$1
# Check if wget is installed
if ! command_exists "wget"; then
echo -e "${RED}$CROSSMARK Error: wget is not installed. Please install it first.${NC}"
exit 1
fi
# Download the public keys from GitHub and append to authorized_keys
PUBLIC_KEYS_URL="https://github.com/$GITHUB_USERNAME.keys"
if wget --quiet --spider "$PUBLIC_KEYS_URL"; then
echo -e "${YELLOW}$HOURGLASS Downloading public keys from GitHub...${NC}"
if wget -qO- "$PUBLIC_KEYS_URL" >> ~/.ssh/authorized_keys; then
echo -e "${GREEN}$CHECKMARK Successfully added public keys to authorized_keys.${NC}"
else
echo -e "${RED}$CROSSMARK Failed to add public keys to authorized_keys.${NC}"
exit 1
fi
else
echo -e "${RED}$CROSSMARK Error: Unable to download public keys from GitHub. Please check the username and try again.${NC}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment