-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
242 lines (209 loc) · 6.04 KB
/
setup
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
#!/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() {
echo "${COLOR_PURPLE}$1${COLOR_NONE}"
}
error() {
echo "${COLOR_RED}ERROR: ${COLOR_NONE}$1"
}
success() {
echo "${COLOR_GREEN}SUCCESS: ${COLOR_NONE} $1"
}
warning() {
echo "${COLOR_YELLOW}WARNING: ${COLOR_NONE}$1"
}
info() {
echo "${COLOR_BLUE}INFO: ${COLOR_NONE}$1"
}
error_message() {
echo "${COLOR_RED}$1${COLOR_NONE}"
}
success_message() {
echo "${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 "$2" >> $LOG_FILE
else
sudo apt install "$1" >> $LOG_FILE
fi
fi
}
linux() {
if [ "$(uname)" = "Linux" ]; then
sudo apt install $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 rg fzf 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 >> $LOG_FILE | bash >> $LOG_FILE
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
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 "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 >> $LOG_FILE | zsh >> $LOG_FILE
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"
mv ~/.zshrc "$BACKUP_DIR/.zshrc.backup"
mv ~/.zshenv "$BACKUP_DIR/.zshenv.backup"
mv ~/.zprofile "$BACKUP_DIR/.zprofile.backup"
mv ~/.zlogin "$BACKUP_DIR/.zlogin.backup"
success "Backup complete!"
}
setup_shell() {
title "Setting up Shell.."
touch ~/.zshenv
echo "export ZDOTDIR=~/.dotfiles/shell" >> ~/.zshenv
ln -s $DOTFILES/shell ~/.dotfiles
info "Created symlink to $(pwd) at ~/.dotfiles"
success "Setup complete!"
}
remove_shell() {
title "Removing Shell.."
rm -rf ~/.zshenv
rm -rf ~/.zshrc
success "Removed shell configuration!"
}
"$@"