-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-script.sh
76 lines (63 loc) · 2.3 KB
/
setup-script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#Script written by vikashgathala for macOS only. Linux version is similar and is coming soon.
# Function to check if the OS is macOS
check_os() {
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "This GitHub SSH script is only for macOS only right now and will be available for other OS in few days."
exit 1
fi
}
#Main script
main() {
echo "\n"
echo "\n"
#Check if Git is installed
git -v
echo "\n"
#Checks if host is macOS as this script works only for macOS right now.
check_os
#Just some info ;)
echo "Follow the easy instructions and get your SSH set up done quickly."
echo "\n"
echo "If you are familiar with Windows and PowerShell then you can help porting this script to Windows."
echo "\n"
echo "Linux script under development."
#Setup begins
#User email for github commit purposes
echo "Enter your email that is used in GitHub account:"
read email
git config --global user.email "$email"
echo "Updated email in git credentials."
#User name for github commit purposes
echo "Enter your GitHub username:"
read username
git config --global user.name "$username"
echo "Updated username in git credentials."
#Generating new ssh key
echo -e "\n\n" | ssh-keygen -t ed25519 -C "$email" -f ~/.ssh/id_ed25519 -N ""
#Copying the key to clipboard
pbcopy < ~/.ssh/id_ed25519.pub
#Prompting user to paste the key in GitHub and then proceed
echo "\n"
echo "Key has been copied to your clipboard."
echo "\n"
echo "Now navigate to [GitHub->Settings->SSH and GPG keys->New SSH key]."
echo "Enter any title and choose [Key type->Authentication Key] and paste the key, press [Add SSH key]."
echo "\n"
echo "After that, press [Enter] here in terminal to verify your setup."
read temp
# Adding GitHub to known hosts to skip confirmation prompt
ssh-keyscan github.com >> ~/.ssh/known_hosts
# Verification of the connection
ssh_output=$(ssh -T [email protected] 2>&1)
echo "\n"
echo "\n"
if echo "$ssh_output" | grep -q "successfully authenticated"; then
echo "SSH connection successful, exiting script."
else
echo "Unknown error, exiting script."
echo "SSH output: $ssh_output"
fi
echo "\n"
}
main