-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·124 lines (98 loc) · 2.95 KB
/
install.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
name=
email=
function ensure_identity {
if [[ -z "$name" ]]; then read -p 'Full Name: ' name; fi
if [[ -z "$email" ]]; then read -p 'Email: ' email; fi
}
# homebrew
if test ! $(which brew); then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
brew bundle
# git
rm -f ~/.gitconfig
ln -s ${BASEDIR}/gitconfig ~/.gitconfig
if [ ! -f ~/.gitconfig.local ]; then
ensure_identity
git config -f ~/.gitconfig.local user.name "$name"
git config -f ~/.gitconfig.local user.email "$email"
fi
# ssh
if [[ ! -f ~/.ssh/id_rsa ]]; then
ensure_identity
# Generate SSH key.
ssh-keygen -t rsa -b 4096 -C "$email"
# Start ssh-agent
eval "$(ssh-agent -s)"
# Add the SSH private key
ssh-add -K ~/.ssh/id_rsa
echo "Would you like to add the SSH key to Github?"
select yn in "Yes" "No"; do
case $yn in
Yes ) cat ~/.ssh/id_rsa.pub | pbcopy; echo "Key copied to clipboard. Opening Github settings..."; sleep 2; open https://github.com/settings/ssh/new; break;;
No ) break;;
esac
done
fi
# gpg
if [[ -z "$(gpg --list-secret-keys)" ]]; then
ensure_identity
cat >/tmp/gpg_key_settings <<EOF
Key-Type: default
Key-Length: 4096
Subkey-Type: default
Subkey-Length: 4096
Name-Real: $name
Name-Email: $email
Expire-Date: 2y
EOF
# Generate GPG key.
gpg --batch --gen-key /tmp/gpg_key_settings
rm /tmp/gpg_key_settings
key=$(gpg --list-keys | grep '^pub ' -A1 | tail -n1 | awk '{ print $1 }')
echo "Added key $key."
echo "Would you like to add another identity or email address to the key?"
select yn in "Yes" "No"; do
case $yn in
Yes ) gpg --edit-key $key adduid; break;;
No ) break;;
esac
done
echo "Would you like to add the GPG key to Github?"
select yn in "Yes" "No"; do
case $yn in
Yes ) gpg --armor --export $key | pbcopy; echo "Key copied to clipboard. Opening Github settings..."; sleep 2; open https://github.com/settings/gpg/new; break;;
No ) break;;
esac
done
# Link the config.
rm -f ~/.gnupg/gpg.conf
ln -s ${BASEDIR}/gnupg/gpg.conf ~/.gnupg/gpg.conf
# Check to see if GPG Agent is running. If not, start it.
if [[ -f "~/.gnupg/.gpg-agent-info" && -n "$(pgrep gpg-agent)" ]]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else
eval $(eval $(gpg-agent --daemon))
fi
# Restart gpg-agent to take new config into effect.
gpg-connect-agent reloadagent /bye
# Setup Git to Sign Commits.
git config -f ~/.gitconfig.local user.signingkey $key
fi
# vim
rm -f ~/.vim
ln -s ${BASEDIR}/vim/ ~/.vim
# bash
rm -f ~/.bash_profile
ln -s ${BASEDIR}/bash_profile ~/.bash_profile
if [ -z $(grep "/opt/homebrew/bin/bash" "/etc/shells") ]; then
sudo sh -c 'echo "/opt/homebrew/bin/bash" >> /etc/shells'
sudo chsh -s /opt/homebrew/bin/bash
chsh -s /opt/homebrew/bin/bash
fi
# .macos settings
./.macos