-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·279 lines (227 loc) · 7.85 KB
/
bootstrap.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
set -euo pipefail
cache_dir=.cache
if [[ $* == *--no-cache* ]]; then
rm -rf $cache_dir
fi
if [[ ! -d $cache_dir ]]; then
mkdir $cache_dir
fi
cache_func_call() {
eval "
_inner_$(typeset -f "$1")
$1"'() {
local func_cache_file="$cache_dir/'"$1"'"
if [[ -f $func_cache_file ]]; then
echo >&2 "Ran previously, skipping..."
return 0
else
_inner_'"$1"' "$@"
inner_return_code=$?
touch $func_cache_file
return $inner_return_code # Added for completeness, but negated by set -e
fi
}'
}
update_apt() {
sudo apt update
} && cache_func_call update_apt
install_git() {
sudo apt install -y curl git
} && cache_func_call install_git
configure_git() {
read -p "Enter name for git global config and press [ENTER]: " git_config_name
read -p "Enter email for git global config and press [ENTER]: " git_config_email
git config --global user.name "$git_config_name"
git config --global user.email "$git_config_email"
# From https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
echo ""
echo "Generating SSH keypair"
private_key_filename="ed25519"
private_key_path="$HOME/.ssh/$private_key_filename"
ssh-keygen -t ed25519 -f $private_key_path -C "$git_config_email" || echo "ssh-keygen exited with code $?"
echo "IdentityFile ~/.ssh/$private_key_filename" >> $HOME/.ssh/config
chmod 600 $HOME/.ssh/config
echo ""
echo "Public key contents:"
cat "$private_key_path.pub"
echo ""
read -p "Add public key to Github, then press any button to test SSH connection" -n 1
# Will return with exit code 1 when successfully authenticated
while ssh -T git@github.com; [[ $? -ne 1 ]]; do
echo ""
echo "Connection failed, would you like to try again?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Attempting connection..."; break;;
No ) break;;
esac
done
if [[ $yn = "No" ]]; then
break
fi
done
echo ""
echo "SSH connection to Github was successful"
} && cache_func_call configure_git
install_docker() {
# From https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
sudo apt install -y \
ca-certificates \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.gpg # Added in case default umask doesn't provide read permissions
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
echo ""
echo "Verifying docker installation"
sudo service docker start
sudo docker run hello-world
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
# From https://docs.docker.com/engine/install/linux-postinstall/
sudo getent group docker || sudo groupadd docker
sudo usermod -aG docker $(whoami)
# allow nonroot access to docker and suppress errors about .docker directory not existing
docker_dotdir=/home/"$(whoami)"/.docker
sudo chown -R "$(whoami)":"$(whoami)" $docker_dotdir || echo "$docker_dotdir does not exist"
sudo chmod -R g+rwx $docker_dotdir || echo "$docker_dotdir does not exist"
} && cache_func_call install_docker
install_neovim() {
pushd /tmp
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
sudo chmod u+x nvim.appimage
sudo ./nvim.appimage --appimage-extract > /dev/null
sudo mv squashfs-root /
sudo ln -s /squashfs-root/AppRun /usr/bin/nvim
rm -f nvim.appimage
popd
} && cache_func_call install_neovim
install_zsh() {
sudo apt install -y zsh
zsh --version
sudo chsh -s $(which zsh) $(whoami)
} && cache_func_call install_zsh
install_ohmyzsh() {
# Force ohmyzsh to not switch shells during script execution
yes no | sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" || ohmyzsh_ret=$?
if [[ $ohmyzsh_ret -ne 141 ]]; then
exit $ohmyzsh_ret
fi
} && cache_func_call install_ohmyzsh
configure_ohmyzsh() {
cp .zshrc $HOME/.zshrc
} && cache_func_call configure_ohmyzsh
install_asdf() {
# git clone https://github.com/asdf-vm/asdf.git ~/.asdf
echo ". $HOME/.asdf/asdf.sh" | tee -a $HOME/.bashrc 1>/dev/null
source ~/.bashrc
} && cache_func_call install_asdf
install_asdf_python() {
asdf plugin-add python || echo ""
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev \
libxmlsec1-dev libffi-dev liblzma-dev
read -p "Enter python version and press [ENTER]: " asdf_python_version
asdf install python $asdf_python_version
asdf global python $asdf_python_version
} && cache_func_call install_asdf_python
install_asdf_nodejs() {
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git || echo ""
read -p "Enter Node.js version and press [ENTER]: " asdf_nodejs_version
asdf install nodejs $asdf_nodejs_version
asdf global nodejs $asdf_nodejs_version
} && cache_func_call install_asdf_nodejs
install_asdf_ruby() {
sudo apt install -y autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git || echo ""
read -p "Enter Ruby version and press [ENTER]: " asdf_ruby_version
asdf install ruby $asdf_ruby_version
asdf global ruby $asdf_ruby_version
} && cache_func_call install_asdf_ruby
# TODO: replace with recommended installation of rust (not through asdf)
install_asdf_rust() {
asdf plugin-add rust https://github.com/asdf-community/asdf-rust.git || echo ""
read -p "Enter Rust version and press [ENTER]: " asdf_rust_version
asdf install rust $asdf_rust_version
asdf global rust $asdf_rust_version
} && cache_func_call install_asdf_rust
install_thefuck_alias() {
pip install thefuck --user
} && cache_func_call install_thefuck_alias
install_kde_plasma() {
sudo apt install -y kde-plasma-desktop
} && cache_func_call install_kde_plasma
install_vscode() {
pushd /tmp
curl -Lo vscode.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64"
sudo dpkg -i vscode.deb
rm -rf vscode.deb
popd
} && cache_func_call install_vscode
install_neofetch() {
sudo apt install -y neofetch
[ -z "$(cat $HOME/.zshrc | grep 'neofetch' 2>&1)" ] && echo "neofetch" >> $HOME/.zshrc
} && cache_func_call install_neofetch
echo ""
echo "Lift yourself up by your bootstraps."
echo ""
echo "Updating apt."
update_apt
echo ""
echo "Installing git."
install_git
echo ""
echo "Configuring git."
configure_git
echo ""
echo "Installing docker."
install_docker
echo ""
echo "Installing neovim."
install_neovim
echo ""
echo "Installing zsh and setting as default shell (requires logout)."
install_zsh
echo ""
echo "Installing OhMyZsh."
install_ohmyzsh
echo ""
echo "Configuring OhMyZsh."
configure_ohmyzsh
echo ""
echo "Installing asdf package manager."
install_asdf
echo ""
echo "Installing python via asdf."
install_asdf_python
echo ""
echo "Installing Node.js via asdf."
install_asdf_nodejs
echo ""
echo "Installing Ruby via asdf."
install_asdf_ruby
echo ""
echo "Installing Rust via asdf."
install_asdf_rust
echo ""
echo "Installing thefuck alias."
install_thefuck_alias
echo ""
echo "Installing KDE Plasma."
install_kde_plasma
echo ""
echo "Installing VS Code"
install_vscode
echo ""
echo "Installing neofetch"
install_neofetch
# TODO: install lunarvim
echo ""
echo "Done bootstrapping. Please reboot."