-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
298 lines (260 loc) · 8.26 KB
/
setup
File metadata and controls
298 lines (260 loc) · 8.26 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
#!/bin/sh
DOTFILES="$(pwd)"
LOG_FILE="$DOTFILES/install.log"
COLOR_GRAY="\033[1;38;5;243m"
COLOR_BLUE="\033[1;34m"
COLOR_GREEN="\033[1;32m"
COLOR_RED="\033[1;31m"
COLOR_PURPLE="\033[1;35m"
COLOR_YELLOW="\033[1;33m"
COLOR_NONE="\033[0m"
newline=$'\n'
title() {
printf '%b\n' "${COLOR_PURPLE}$1${COLOR_NONE}"
}
error() {
printf '%b\n' "${COLOR_RED}ERROR: ${COLOR_NONE}$1"
}
success() {
printf '%b\n' "${COLOR_GREEN}SUCCESS: ${COLOR_NONE} $1"
}
warning() {
printf '%b\n' "${COLOR_YELLOW}WARNING: ${COLOR_NONE}$1"
}
info() {
printf '%b\n' "${COLOR_BLUE}INFO: ${COLOR_NONE}$1"
}
error_message() {
printf '%b\n' "${COLOR_RED}$1${COLOR_NONE}"
}
success_message() {
printf '%b\n' "${COLOR_GREEN}$1${COLOR_NONE}"
}
install() {
if [ "$(uname)" = "Darwin" ]; then
info "MacOS detected"
brew install $1 >> $LOG_FILE
elif [ "$(uname)" = "Linux" ]; then
info "Linux detected"
if [ -n "$2" ]; then
sudo apt install -y "$2" >> $LOG_FILE
else
sudo apt install -y "$1" >> $LOG_FILE
fi
fi
}
linux() {
if [ "$(uname)" = "Linux" ]; then
sudo apt install -y $1 >> $LOG_FILE
fi
}
mac() {
if [ "$(uname)" = "Darwin" ]; then
brew install $1 >> $LOG_FILE
fi
}
check_dependencies() {
local utils=(git curl pip python3 pipx zsh go rg fzf npm pnpm swaks)
local dir_utils=(nvm zplug)
title "Checking for installed apps"
for util in "${utils[@]}"; do
printf %s "Checking $util... "
if test "$(command -v "$util")"; then
success_message "Installed."
else
error_message "Not installed."
fi
done
for util in "${dir_utils[@]}"; do
printf %s "Checking $util... "
if [ -d "$HOME/.$util" ]; then
success_message "Installed."
else
error_message "Not installed."
fi
done
}
install_dependencies() {
title "Installing dependencies"
if test "$(command -v "git")"; then
success "Git is already installed."
else
warning "Git is not installed."
info "Installing Git..."
install git
success "Git installed."
fi
if test "$(command -v "curl")"; then
success "curl is already installed."
else
warning "curl is not installed."
info "Installing curl..."
install curl
success "curl installed."
fi
if [ -d "$HOME/.nvm" ]; then
success "nvm is already installed."
else
warning "nvm is not installed."
info "Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash >> $LOG_FILE 2>&1
info "nvm installed, setting it up..."
nvm ls-remote >> $LOG_FILE
nvm install --lts >> $LOG_FILE
nvm alias default 'lts/*' >> $LOG_FILE
success "nvm is installed and configured to use the latest LTS version."
fi
# Load nvm so npm is available in this script
if [ -s "$HOME/.nvm/nvm.sh" ]; then
. "$HOME/.nvm/nvm.sh"
fi
if test "$(command -v "npm")"; then
success "npm is already installed."
else
warning "npm is not installed (install nvm/node first)."
if [ -s "$HOME/.nvm/nvm.sh" ]; then
. "$HOME/.nvm/nvm.sh" && nvm install --lts >> $LOG_FILE 2>&1
success "npm installed via nvm."
else
info "Installing nodejs and npm..."
install npm
success "npm installed."
fi
fi
if test "$(command -v "pnpm")"; then
success "pnpm is already installed."
else
warning "pnpm is not installed."
info "Installing pnpm..."
npm install -g pnpm >> $LOG_FILE
success "pnpm installed."
fi
if test "$(command -v "python3")"; then
success "python is already installed."
else
warning "python is not installed."
info "Installing python..."
install python python3
success "python3 installed."
fi
if test "$(command -v "pip")"; then
success "pip is already installed."
else
warning "pip is not installed."
info "Installing pip..."
linux python3-pip
success "pip installed."
fi
if test "$(command -v "pipx")"; then
success "pipx is already installed."
else
warning "pipx is not installed."
info "Installing pipx..."
install pipx
pipx ensurepath
# sudo pipx ensurepath --global # optional to allow pipx actions with --global argument
success "pipx installed."
fi
if test "$(command -v "zsh")"; then
success "zsh is already installed."
else
warning "zsh is not installed."
info "Installing zsh..."
install zsh
success "zsh installed."
fi
if test "$(command -v "go")"; then
success "Go is already installed."
else
warning "Go is not installed."
info "Installing Go..."
install go golang-go
success "Go installed."
fi
if test "$(command -v "rg")"; then
success "ripgrep is already installed."
else
warning "ripgrep is not installed."
info "Installing ripgrep..."
install ripgrep
success "ripgrep installed."
fi
if test "$(command -v "fzf")"; then
success "fzf is already installed."
else
warning "fzf is not installed."
info "Installing fzf..."
install fzf
success "fzf installed."
fi
if [ -d "$HOME/.zplug" ]; then
success "zplug is already installed."
else
warning "zplug is not installed."
info "Installing zplug..."
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh >> $LOG_FILE 2>&1
success "zplug installed."
fi
if test $(command -v "swaks") ; then
success "swaks is already installed."
else
warning "swaks is not installed."
info "Installing swaks..."
install swaks >> $LOG_FILE
success "swaks installed."
fi
info "All logs are saved to $LOG_FILE"
}
backup_shell() {
title "Backing up Shell.."
BACKUP_DIR=$HOME/.dotfiles/backup
info "Creating backup directory at $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
info "Attempting to backup existing zsh config files"
[ -f ~/.zshrc ] && mv ~/.zshrc "$BACKUP_DIR/.zshrc.backup"
[ -f ~/.zshenv ] && mv ~/.zshenv "$BACKUP_DIR/.zshenv.backup"
[ -f ~/.zprofile ] && mv ~/.zprofile "$BACKUP_DIR/.zprofile.backup"
[ -f ~/.zlogin ] && mv ~/.zlogin "$BACKUP_DIR/.zlogin.backup"
success "Backup complete!"
}
setup_shell() {
title "Setting up Shell.."
SHELL_DIR="$DOTFILES/shell"
printf '%s\n' "export ZDOTDIR=~/.dotfiles" > ~/.zshenv
if [ -L "$HOME/.dotfiles" ]; then
if [ "$(readlink -f "$HOME/.dotfiles")" = "$(readlink -f "$SHELL_DIR")" ]; then
info "Symlink ~/.dotfiles already points to shell directory."
else
rm -f "$HOME/.dotfiles"
ln -s "$SHELL_DIR" "$HOME/.dotfiles"
info "Updated symlink ~/.dotfiles to point to shell directory."
fi
elif [ -e "$HOME/.dotfiles" ]; then
warning "~/.dotfiles already exists and is not a symlink. Remove it and run setup again, or run: ln -sf $SHELL_DIR ~/.dotfiles"
else
ln -s "$SHELL_DIR" "$HOME/.dotfiles"
info "Created symlink ~/.dotfiles -> $SHELL_DIR"
fi
# Set zsh as default shell if not already
ZSH_PATH="$(command -v zsh)"
CURRENT_SHELL="$(getent passwd "$(whoami)" | cut -d: -f7)"
if [ -n "$ZSH_PATH" ] && [ "$CURRENT_SHELL" != "$ZSH_PATH" ]; then
info "Setting zsh as default shell (you may be prompted for your password)..."
if chsh -s "$ZSH_PATH"; then
success "Default shell set to zsh. Open a new terminal for it to take effect."
else
warning "Could not set default shell. Run manually: chsh -s $(command -v zsh)"
fi
elif [ "$CURRENT_SHELL" = "$ZSH_PATH" ]; then
info "zsh is already your default shell."
fi
success "Setup complete!"
info "Open a new terminal to see your new prompt and theme."
}
remove_shell() {
title "Removing Shell.."
rm -rf ~/.zshenv
rm -rf ~/.zshrc
success "Removed shell configuration!"
}
"$@"