-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-setup.sh
More file actions
executable file
·61 lines (47 loc) · 1.84 KB
/
git-setup.sh
File metadata and controls
executable file
·61 lines (47 loc) · 1.84 KB
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
#!/bin/bash
# Script to configure Git and set up an SSH key for GitHub
# Author: Troels Lund
# Load variables from the .env file
if [ -f .env ]; then
source .env
else
echo ".env file not found!"
exit 1
fi
# Configure Git
echo "Configuring Git..."
git config --global user.name $GIT_USER_NAME
git config --global user.email $GIT_USER_EMAIL
## Set up SSH key for GitHub
# ask if the user wants to set up an SSH key for GitHub
read -p "Do you want to set up an SSH key for GitHub? (y/n): " response
# Handle the user's response
case "$response" in
y | Y | yes | YES | Yes)
echo "Setting up SSH key for GitHub..."
# create a new SSH key for GitHub
echo "Generating a new SSH key for GitHub..."
# Generating a new SSH key
# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key
ssh-keygen -t ed25519 -C $1 -f ~/.ssh/id_ed25519
# Adding your SSH key to the ssh-agent
# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
eval "$(ssh-agent -s)"
touch ~/.ssh/config
echo "Host *\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/id_ed25519" | tee ~/.ssh/config
ssh-add -K ~/.ssh/id_ed25519
# Adding your SSH key to your GitHub account
# https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
pbcopy <~/.ssh/id_ed25519.pub
echo "ssh key is in clipboard paste that into GitHub"
# wait for user to add the SSH key to GitHub
read -p "Press enter to continue after adding the SSH key to GitHub..."
;;
n | N | no | NO | No)
echo "Skipping SSH key setup for GitHub."
exit 0
;;
*)
echo "Invalid input. Please enter y or n."
;;
esac