-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·281 lines (231 loc) · 7.89 KB
/
setup.sh
File metadata and controls
executable file
·281 lines (231 loc) · 7.89 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
#!/bin/bash
set -e
readonly NC='\033[0m'
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly BLUE='\033[0;34m'
readonly PURPLE='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly WHITE='\033[1;37m'
log_info() {
echo -e "${WHITE}$1${NC}"
}
log_success() {
echo -e "${GREEN}$1${NC}"
}
log_warning() {
echo -e "${YELLOW}$1${NC}"
}
log_error() {
echo -e "${RED}$1${NC}"
}
log_section() {
echo -e "\n${PURPLE}$1${NC}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
app_exists() {
[[ -d "/Applications/${1}.app" ]]
}
install_homebrew() {
log_section "Setting up Homebrew"
if command_exists brew; then
log_info "Homebrew already installed. Updating..."
brew update && brew upgrade
else
log_info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ -f "/opt/homebrew/bin/brew" ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -f "/usr/local/bin/brew" ]]; then
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
log_success "Homebrew setup complete"
}
install_applications() {
log_section "Installing macOS Applications"
if [[ ! -f "apps.txt" ]]; then
log_error "apps.txt file not found!"
return 1
fi
while IFS='=' read -r app brew_name || [[ -n "$app" ]]; do
[[ -z "$app" || "$app" =~ ^#.*$ ]] && continue
if app_exists "$app"; then
log_info "${app} is already installed"
else
log_info "Installing ${app}..."
if brew install --cask "$brew_name"; then
log_success "${app} installed successfully"
else
log_error "Failed to install ${app}"
fi
fi
done < apps.txt
}
install_developer_tools() {
log_section "Installing Developer Tools"
if [[ ! -f "tools.txt" ]]; then
log_error "tools.txt file not found!"
return 1
fi
while IFS='=' read -r name tool || [[ -n "$name" ]]; do
[[ -z "$name" || "$name" =~ ^#.*$ ]] && continue
if brew list "$tool" &>/dev/null; then
log_info "${name} is already installed"
else
log_info "Installing ${name}..."
if brew install "$tool"; then
log_success "${name} installed successfully"
else
log_error "Failed to install ${name}"
fi
fi
done < tools.txt
}
setup_zsh() {
log_section "Setting up Zsh and Oh My Zsh"
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
log_info "Installing Oh My Zsh..."
RUNZSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else
log_info "Oh My Zsh already installed"
fi
local plugin_dir="$HOME/.oh-my-zsh/custom/plugins"
mkdir -p "$plugin_dir"
if [[ -d "oh-my-zsh/plugins/zsh-autosuggestions" ]]; then
log_info "Installing zsh-autosuggestions plugin..."
ln -sf -R oh-my-zsh/plugins/zsh-autosuggestions "$plugin_dir/"
fi
if [[ -d "oh-my-zsh/plugins/zsh-syntax-highlighting" ]]; then
log_info "Installing zsh-syntax-highlighting plugin..."
ln -sf oh-my-zsh/plugins/zsh-syntax-highlighting "$plugin_dir/"
fi
log_success "Zsh setup complete"
}
setup_neovim() {
log_section "Setting up Neovim Configuration"
if ! command_exists nvim; then
log_info "Installing Neovim via Homebrew..."
brew install neovim
fi
local nvim_config_dir="$HOME/.config/nvim"
if [[ -d "$nvim_config_dir" ]]; then
local backup_dir="${nvim_config_dir}.backup.$(date +%Y%m%d_%H%M%S)"
log_warning "Backing up existing Neovim config to $backup_dir"
mv "$nvim_config_dir" "$backup_dir"
fi
log_info "Cloning Neovim configuration..."
mkdir -p "$HOME/.config"
if git clone https://github.com/coderste/neovim-config.git "$nvim_config_dir"; then
log_success "Neovim configuration cloned successfully"
else
log_error "Failed to clone Neovim configuration"
fi
}
copy_config_files() {
log_section "Copying configuration files"
local config_files=(".zprofile" ".zshrc" ".gitconfig" ".gitconfig-personal" ".gitignore" ".aliases")
for file in "${config_files[@]}"; do
if [[ -f "config/$file" ]]; then
log_info "Copying $file to home directory..."
cp "config/$file" "$HOME/"
else
log_warning "Config file $file not found, skipping..."
fi
done
if [[ -f "config/.aws" ]]; then
log_info "Copying AWS configuration..."
mkdir -p "$HOME/.aws"
cp "config/.aws" "$HOME/.aws/config"
fi
if [[ -d ".git-hooks" ]]; then
log_info "Copying git hooks..."
cp -R ".git-hooks" "$HOME/"
else
log_warning "Git hooks directory not found, skipping..."
fi
log_success "Configuration files copied"
}
authenticate_github() {
log_section "GitHub Authentication"
if command_exists gh; then
log_info "Authenticating with GitHub CLI..."
if gh auth status &>/dev/null; then
log_info "Already authenticated with GitHub"
else
log_info "Please authenticate with GitHub CLI..."
gh auth login
fi
else
log_warning "GitHub CLI not installed, skipping authentication"
fi
}
create_directories() {
log_section "Creating development directories"
local directories=("$HOME/code" "$HOME/code/work" "$HOME/code/personal")
for dir in "${directories[@]}"; do
if [[ ! -d "$dir" ]]; then
log_info "Creating directory: $dir"
mkdir -p "$dir"
else
log_info "Directory already exists: $dir"
fi
done
log_success "Development directories created"
}
print_manual_tasks() {
log_section "Manual Tasks Remaining"
echo -e "${YELLOW}The following tasks require manual completion:${NC}"
echo "• Install Dank Mono font manually (licensing restrictions)"
echo "• Enter licensing keys for Alfred"
echo "• Sign into VS Code with GitHub to sync settings"
echo "• Add Jira search to Firefox"
echo "• Test Neovim setup by running 'nvim' (plugins should auto-install on first run)"
echo ""
echo -e "${GREEN}Development environment setup complete!${NC}"
echo -e "${CYAN}Please restart your terminal or run 'source ~/.zshrc' to apply changes.${NC}"
echo -e "${CYAN}The 'vim' and 'vi' commands now point to Neovim.${NC}"
}
# Main execution
main() {
log_info "Starting Mac Development Environment Setup"
echo ""
if [[ "$OSTYPE" != "darwin"* ]]; then
log_error "This script is designed for macOS only!"
exit 1
fi
if [[ ! -f ".gitmodules" ]]; then
log_error "This script must be run from the root of the laptop-setup git repository!"
log_error "Make sure you cloned with: git clone --recurse-submodules https://github.com/coderste/laptop-setup.git"
exit 1
fi
log_info "Initializing git submodules..."
if git submodule update --init --recursive; then
log_success "Submodules initialized successfully"
else
log_error "Failed to initialize submodules"
exit 1
fi
local required_files=("apps.txt" "tools.txt")
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
log_error "Required file $file not found!"
exit 1
fi
done
install_homebrew
install_applications
install_developer_tools
setup_zsh
setup_neovim
copy_config_files
authenticate_github
create_directories
print_manual_tasks
}
main "$@"