-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·211 lines (183 loc) · 6.82 KB
/
setup.sh
File metadata and controls
executable file
·211 lines (183 loc) · 6.82 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
#!/usr/bin/env bash
# Environment Setup Script
# Manages configuration files and symlinks for consistent environment across machines
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
ENV_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BACKUP_DIR="$HOME/.config-backups/$(date +%Y%m%d-%H%M%S)"
echo -e "${GREEN}=== Environment Setup Script ===${NC}"
echo "Setting up configuration from: $ENV_DIR"
# Create backup directory
mkdir -p "$BACKUP_DIR"
echo -e "${YELLOW}Backup directory: $BACKUP_DIR${NC}"
# Function to create symlink with backup
create_symlink() {
local source="$1"
local target="$2"
if [ -L "$target" ]; then
# Already a symlink
local current_source=$(readlink "$target")
if [ "$current_source" = "$source" ]; then
echo -e "${GREEN}✓${NC} $target already linked correctly"
return
else
echo -e "${YELLOW}!${NC} $target is linked to $current_source"
mv "$target" "$BACKUP_DIR/$(basename "$target").link"
fi
elif [ -e "$target" ]; then
# File exists, backup
echo -e "${YELLOW}→${NC} Backing up existing $target"
mv "$target" "$BACKUP_DIR/$(basename "$target")"
fi
echo -e "${GREEN}+${NC} Creating symlink: $target -> $source"
ln -s "$source" "$target"
}
echo -e "\n${GREEN}Setting up shell configurations...${NC}"
# Shell dotfiles
SHELL_FILES=(
".bashrc"
".bash_profile"
".bash_logout"
".profile"
".zshrc"
".gitconfig"
".gitignore_global"
".npmrc"
".mcp.json"
".gitignore.home:.gitignore" # source:target format for different names
)
for file in "${SHELL_FILES[@]}"; do
if [[ "$file" == *":"* ]]; then
# Handle different source and target names
source_name="${file%%:*}"
target_name="${file##*:}"
else
source_name="$file"
target_name="$file"
fi
source_path="$ENV_DIR/shell_dotfiles/$source_name"
target_path="$HOME/$target_name"
if [ -f "$source_path" ]; then
create_symlink "$source_path" "$target_path"
else
echo -e "${RED}✗${NC} Source not found: $source_path"
fi
done
# Claude Code configuration
echo -e "\n${GREEN}Setting up Claude Code configuration...${NC}"
mkdir -p "$HOME/.claude"
if [ -d "$ENV_DIR/claude" ]; then
create_symlink "$ENV_DIR/claude" "$HOME/.claude/rules"
fi
# Platform-specific setup
echo -e "\n${GREEN}Detecting platform...${NC}"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if grep -q Microsoft /proc/version 2>/dev/null; then
echo "Platform: WSL2"
# WSL-specific configurations
if [ -f "$ENV_DIR/shell_dotfiles/.bash_profile.wsl" ]; then
echo -e "${YELLOW}→${NC} Found WSL-specific bash_profile"
fi
if [ -f "$ENV_DIR/shell_dotfiles/.zshrc.wsl" ]; then
echo -e "${YELLOW}→${NC} Found WSL-specific zshrc"
fi
else
echo "Platform: Linux"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Platform: macOS"
# macOS-specific configurations
if [ -f "$ENV_DIR/shell_dotfiles/.bash_profile.mac" ]; then
echo -e "${YELLOW}→${NC} Found macOS-specific bash_profile"
fi
if [ -f "$ENV_DIR/shell_dotfiles/.zshrc.mac" ]; then
echo -e "${YELLOW}→${NC} Found macOS-specific zshrc"
fi
fi
# Bash-it setup
echo -e "\n${GREEN}Setting up Bash-it...${NC}"
if [ ! -d "$HOME/.bash-it" ]; then
echo -e "${YELLOW}→${NC} Installing Bash-it framework"
git clone --depth=1 https://github.com/Bash-it/bash-it.git "$HOME/.bash-it"
# Install custom vtheme
if [ -f "$ENV_DIR/bash-it-theme/vtheme.theme.bash" ]; then
echo -e "${GREEN}+${NC} Installing custom vtheme"
mkdir -p "$HOME/.bash-it/themes/vtheme"
cp "$ENV_DIR/bash-it-theme/vtheme.theme.bash" "$HOME/.bash-it/themes/vtheme/vtheme.theme.bash"
fi
# Run the install script in silent mode
echo -e "${YELLOW}→${NC} Configuring Bash-it (silent mode)"
$HOME/.bash-it/install.sh --silent
# Enable useful plugins
echo -e "${YELLOW}→${NC} Enabling default plugins"
source "$HOME/.bash-it/bash_it.sh"
bash-it enable plugin git base alias-completion
bash-it enable alias git general
bash-it enable completion git bash-it system
else
echo -e "${GREEN}✓${NC} Bash-it already installed"
# Ensure vtheme is installed/updated
if [ -f "$ENV_DIR/bash-it-theme/vtheme.theme.bash" ]; then
mkdir -p "$HOME/.bash-it/themes/vtheme"
cp "$ENV_DIR/bash-it-theme/vtheme.theme.bash" "$HOME/.bash-it/themes/vtheme/vtheme.theme.bash"
echo -e "${GREEN}✓${NC} vtheme updated"
fi
fi
# SSH configuration
echo -e "\n${GREEN}SSH Configuration${NC}"
if [ -f "$ENV_DIR/ssh/config.template" ]; then
if [ ! -f "$HOME/.ssh/config" ]; then
echo -e "${YELLOW}!${NC} No SSH config found. Template available at:"
echo " $ENV_DIR/ssh/config.template"
echo " Copy and customize it to ~/.ssh/config"
else
echo -e "${GREEN}✓${NC} SSH config exists. Template available for reference at:"
echo " $ENV_DIR/ssh/config.template"
fi
fi
# Git configuration
echo -e "\n${GREEN}Checking Git configuration...${NC}"
if command -v git &> /dev/null; then
# Check if global gitignore is configured
current_excludes=$(git config --global core.excludesfile || echo "")
expected_excludes="$HOME/.gitignore_global"
if [ "$current_excludes" != "$expected_excludes" ]; then
echo -e "${YELLOW}→${NC} Setting global git excludes file"
git config --global core.excludesfile "$expected_excludes"
else
echo -e "${GREEN}✓${NC} Git global excludes configured correctly"
fi
fi
# Development tools setup (optional)
echo -e "\n${GREEN}Development Tools${NC}"
if [ -f "$ENV_DIR/pre-commit-config/install-dev-tools.sh" ]; then
echo "Development tools installer available. Run to install:"
echo " $ENV_DIR/pre-commit-config/install-dev-tools.sh"
fi
# Final summary
echo -e "\n${GREEN}=== Setup Complete ===${NC}"
echo "Configuration files have been linked from $ENV_DIR"
if [ "$(ls -A "$BACKUP_DIR" 2>/dev/null)" ]; then
echo -e "${YELLOW}Backups saved to: $BACKUP_DIR${NC}"
else
# Remove empty backup directory
rmdir "$BACKUP_DIR" 2>/dev/null || true
fi
echo -e "\n${YELLOW}Next steps:${NC}"
echo "1. Review and customize SSH config if needed"
echo "2. Source your shell configuration:"
echo " source ~/.bashrc # for bash"
echo " source ~/.zshrc # for zsh"
echo "3. Consider running the development tools installer"
# Check for shell_dotfiles bootstrap scripts
if [ -d "$ENV_DIR/shell_dotfiles/setup" ]; then
echo -e "\n${YELLOW}Additional setup scripts available:${NC}"
ls -1 "$ENV_DIR/shell_dotfiles/setup/"*.sh 2>/dev/null | while read script; do
echo " $(basename "$script")"
done
fi