Repository navigation
Expand file tree
/
Copy pathconfigure_dev_environment
More file actions
executable file
·360 lines (292 loc) · 11.4 KB
/
Copy pathconfigure_dev_environment
File metadata and controls
executable file
·360 lines (292 loc) · 11.4 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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env bash
export BASH_RC_FILE="/home/$USER/.bashrc"
export NEOVIM_PATH="/home/$USER/.config/nvim"
export LUNARVIM_PATH="/home/$USER/.config/lvim"
export LUNARVIM_CONFIG_FILE_PATH="/home/$USER/.config/lvim/config.lua"
export DOTFILES_PATH="/home/$USER/dotfiles"
export MY_BASH_RC_FILE_NAME=".bashrc.sourabh"
export TMUX_CONF_FILE="/home/$USER/.tmux.conf"
export MY_TMUX_CONF_FILE_NAME=".tmux.conf.sourabh"
export NEOVIM_EXECUTABLE_PATH=`which nvim`
export CONFIG_PATH="/home/$USER/.config"
export SLEEP_DURATION=2
mkdir -p $CONFIG_PATH
# TODO: Check if fzf is installed, if not, git clone fzf into ~/appimages folder
# TODO: Check if Tmux is installed. If not install first.
function repeat {
num="${2:-100}"; printf -- "$1%.0s" $(seq 1 $num);
}
function print {
terminalCols=$(tput cols)
argLen=${#1}
offset=$(((terminalCols-argLen)/2))
printf "\n"
repeat '#' $((offset-1))
printf " $1 "
repeat '#' $((offset-1))
printf "\n"
}
function configure_bashrc {
print "Setting up custom bashrc..."
if [ -f "$BASH_RC_FILE" ]; then
echo "Found file $BASH_RC_FILE"
else
print "No existing file found at $BASH_RC_FILE. Creating one..."
touch "$BASH_RC_FILE"
fi
if grep -q -F "$MY_BASH_RC_FILE_NAME" "$BASH_RC_FILE"; then
echo "Found $MY_BASH_RC_FILE_NAME reference in $BASH_RC_FILE. Doing nothing..."
else
echo "source $DOTFILES_PATH/$MY_BASH_RC_FILE_NAME" >> "$BASH_RC_FILE"
echo "Sourced $MY_BASH_RC_FILE_NAME in $BASH_RC_FILE"
source ~/.bashrc
fi
}
function setup_directories {
sudo mkdir -p $SOFTLINKS_DIRECTORY
sudo chown $USER -R $SOFTLINKS_DIRECTORY
sudo mkdir -p $SOFTWARES_PATH
sudo chown $USER -R $SOFTWARES_PATH
}
function setup_python {
print "Setting up miniconda3 using python3 version on the system"
miniconda3_path="$SOFTWARES_PATH/miniconda3"
PREFIX="${SOFTWARES_PATH}/miniconda3"
if [ -d "$miniconda3_path" ]; then
echo "Found miniconda3 folder at $miniconda3_path"
else
echo "No miniconda3 folder at $miniconda3_path"
python_command=""
python3_version=`python3 -c 'import sys
print("".join((sys.version).split(".")[0:2]))'`
echo "Downloading miniconda3 for python $python3_version"
url="https://repo.anaconda.com/miniconda/Miniconda3-py${python3_version}_4.12.0-Linux-x86_64.sh"
wget -O "miniconda3.sh" $url >/dev/null 2>&1
echo "Installing miniconda3"
bash ./miniconda3.sh -b -u -p $miniconda3_path >/dev/null 2>&1
ln -s "$miniconda3_path/bin/conda" "$SOFTLINKS_DIRECTORY/conda"
echo "Softlinked conda to $SOFTLINKS_DIRECTORY"
rm miniconda3.sh
echo "Installing mamba..."
# sudo `which conda` install -c conda-forge -y mamba
conda install -c conda-forge -y mamba
conda deactivate
conda config --set auto_activate_base false
fi
}
function setup_nvm {
unset PREFIX
if [ ! -z `which nvm` ]; then
echo "Found nvm executable on PATH. Skipping download..."
else
rm -rf $NVM_DIR
mkdir -p $NVM_DIR
echo "Downloading nvm..."
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source "$NVM_DIR/nvm.sh"
echo "Softlinking..."
# ln -s "$NVM_DIR/nvm.sh" "$SOFTLINKS_DIRECTORY/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
echo "To install node 16, use: nvm install 16"
# nvm install node
fi
# export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
}
function setup_go {
print "Setting up the latest version of go"
go_path="$SOFTWARES_PATH/go"
local_go_folder="$PWD/go"
go_zip="go.tar.gz"
if [ -d "$go_path" ]; then
echo "Found go folder at $SOFTWARES_PATH"
else
echo "go not found at $SOFTWARES_PATH. Installing..."
wget -O "$go_zip" https://go.dev/dl/go1.21.1.linux-amd64.tar.gz >/dev/null 2>&1
echo "Extracting..."
rm -rf $local_go_folder
mkdir $local_go_folder && tar -C go -xvf $go_zip >/dev/null 2>&1
echo "Moving to $SOFTWARES_PATH"
mv "$local_go_folder/go" $go_path
rm $go_zip
rm -rf $local_go_folder
echo "Softlinking to $SOFTLINKS_DIRECTORY"
ln -s "$go_path/bin/go" "$SOFTLINKS_DIRECTORY/go"
fi
}
function setup_fzf {
print "Setting up fzf"
fzf_path="$SOFTWARES_PATH/fzf"
if [ -d "$fzf_path" ]; then
echo "Found fzf folder at $SOFTWARES_PATH"
else
echo "fzf not found at $SOFTWARES_PATH. Installing..."
mkdir $fzf_path
# Using release tar
echo "Downloading fzf v0.34.0..."
wget -O "fzf.tar.gz" "https://github.com/junegunn/fzf/releases/download/0.34.0/fzf-0.34.0-linux_amd64.tar.gz" >/dev/null 2>&1
echo "Extracting..."
tar -xvf fzf.tar.gz
echo "Moved fzf to $fzf_path"
mv fzf $fzf_path
rm fzf.tar.gz
ln -s "$fzf_path/fzf" "$SOFTLINKS_DIRECTORY/fzf"
echo "Softlinked to $SOFTLINKS_DIRECTORY/fzf"
# Using git clone
# sudo git clone --depth 1 https://github.com/junegunn/fzf.git $fzf_path
# "$fzf_path/install"
fi
}
function configure_editor {
print "Configuring Editor..."
echo "Checking if neovim exists ?"
nvim_path="$SOFTWARES_PATH/nvim"
# if [ ! -z `find $SOFTWARES_PATH -name nvim.*` ]; then
if [ -d "$nvim_path" ]; then
echo "Found neovim executable at $nvim_path. Skipping download..."
else
mkdir $nvim_path
echo "neovim folder not found in $nvim_path. Fetching the latest stable version of neovim"
wget "https://github.com/neovim/neovim/releases/download/stable/nvim.appimage" >/dev/null 2>&1
chmod u+x nvim.appimage
echo "Moving nvim.appimage to $nvim_path"
mv ./nvim.appimage $nvim_path
ln -s "$nvim_path/nvim.appimage" "$SOFTLINKS_DIRECTORY/nvim"
echo "Softlinked to $SOFTLINKS_DIRECTORY/nvim"
fi
print "Configure either Neovim or Lunarvim. Press 1 for Neovim or 2 for lunarvim"
read -p "Continue (1/2)?" choice
if [ "$choice" = "1" ]; then
configure_neovim
else
configure_lunarvim
fi
}
function configure_lunarvim {
print "Setting up Lunarvim..."
if [ ! -z `which lvim` ]; then
echo "Found lvim on PATH. Skipping installation"
else
bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh) -y --no-install-dependencies
echo "Successfully installed lunarvim with no optional dependencies"
echo "Go to ~/.config/lvim/. Open lvim, open config.lua and do :w. This should install all plugins"
fi
echo "Configuring lunarvim..."
init_file="init.lua"
if grep -q -F "$init_file" "$LUNARVIM_CONFIG_FILE_PATH"; then
echo "Found $init_file reference in $LUNARVIM_CONFIG_FILE_PATH. Doing nothing..."
else
content="\n\n\n-- Sourabh's custom config\nlocal user = os.getenv(\"USER\")\nlocal init_path = string.format(\"/home/%s/dotfiles/lvim/init.lua\", user)\ndofile(init_path)"
echo -e "$content" >> "$LUNARVIM_CONFIG_FILE_PATH"
echo "Sourced content in $LUNARVIM_CONFIG_FILE_PATH"
fi
# Download packer
mkdir -p ~/dotfiles/my-nvim-plugins/packer
git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/dotfiles/my-nvim-plugins/packer
}
function configure_neovim {
print "Setting up Neovim..."
if [ -d "$NEOVIM_PATH" ]; then
echo "$NEOVIM_PATH already exists. Do you want to delete the existing folder ?"
read -p "Continue (y/n)?" choice
if [ "$choice" = "y" ]; then
cp -r "$DOTFILES_PATH/nvim" "/home/$USER/.config/"
echo "You need to run PackerSync/Install"
else
echo "Not replacing neovim config"
fi
else
echo "$NEOVIM_PATH doesnt exist. Copying nvim folder from $DOTFILES_PATH."
cp -r "$DOTFILES_PATH/nvim" "/home/$USER/.config/" && print "You need to run PackerSync/Install"
fi
}
function setup_tmux {
print "Setting up tmux..."
if [ ! -z `which tmux` ]; then
echo "Found tmux on PATH. Skipping installation"
else
sudo apt install -y tmux
fi
if [ -f "$TMUX_CONF_FILE" ]; then
echo "Found file $TMUX_CONF_FILE"
else
echo "No existing file found at $TMUX_CONF_FILE. Creating one..."
touch "$TMUX_CONF_FILE"
fi
if [ ! -f "~/.tmux/plugins/tpm" ]; then
echo "Cloning tmux-plugins/tpm"
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
if grep -q -F "$MY_TMUX_CONF_FILE_NAME" "$TMUX_CONF_FILE"; then
echo "Found $MY_TMUX_CONF_FILE_NAME reference in $TMUX_CONF_FILE. Doing nothing..."
else
echo "source-file $DOTFILES_PATH/$MY_TMUX_CONF_FILE_NAME" >> "$TMUX_CONF_FILE"
echo "source-file $HOME/dotfiles/.tmux.theme.gruvbox" >> "$TMUX_CONF_FILE"
echo "Sourced $MY_TMUX_CONF_FILE_NAME and theme in $TMUX_CONF_FILE"
fi
}
function setup_starship {
print "Setting up Starship prompt..."
if [ ! -z `which starship` ]; then
echo "Starship prompt found. Skipping install..."
else
echo "Fetching starship..."
curl -sS https://starship.rs/install.sh | sh
fi
echo "Copying config to ~/.config/starship.toml"
cp ./starship.toml $CONFIG_PATH
}
function setup_utilities {
# Custom Softlinks directory. All of them in 1 place.
setup_directories
sleep $SLEEP_DURATION
setup_tmux
sleep $SLEEP_DURATION
setup_fzf
sleep $SLEEP_DURATION
setup_starship
sleep $SLEEP_DURATION
}
function setup_languages {
setup_python
sleep $SLEEP_DURATION
setup_nvm
sleep $SLEEP_DURATION
setup_go
sleep $SLEEP_DURATION
}
function setup_softwares {
print "Setting up custom softwares..."
if [ ! -d "$SOFTWARES_PATH" ]; then
echo "$SOFTWARES_PATH doesn't exist. Creating it..."
sudo mkdir "$SOFTWARES_PATH"
fi
setup_utilities
setup_languages
configure_editor
}
function install_font {
sudo apt-get install -y ttf-mscorefonts-installer
mkdir -p ~/.fonts
FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/FiraCode.zip"
TARGET_DIR="~/dotfiles"
wget -P "$TARGET_DIR" "$FONT_URL"
unzip "$TARGET_DIR/FiraCode.zip" -d "~/.fonts"
rm "$TARGET_DIR/FiraCode.zip"
fc-cache -f -v
FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/Hack.zip"
TARGET_DIR="~/dotfiles"
wget -P "$TARGET_DIR" "$FONT_URL"
unzip "$TARGET_DIR/HackNerdFont.zip" -d "~/.fonts"
rm "$TARGET_DIR/HackNerdFont.zip"
fc-cache -f -v
source ~/.bashrc
}
# Modify ~/.bashrc
configure_bashrc
install_font
setup_softwares
sudo ln -s ~/appimages/Joplin-2.12.17.AppImage /usr/softlinks/Joplin
echo "Change your default terminal font to NerdFont"
echo "Manually install nvm from github"
echo "Run ':Lazy sync' to fix any plugin related issues"