-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·210 lines (183 loc) · 7.89 KB
/
setup.sh
File metadata and controls
executable file
·210 lines (183 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
#!/usr/bin/env bash
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get the directory where this script is located
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_DIR="$HOME/dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
echo -e "${BLUE}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Dotfiles Installation Script ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BLUE}Dotfiles location:${NC} $DOTFILES_DIR"
echo -e "${BLUE}Backup location:${NC} $BACKUP_DIR"
echo ""
# Function to create backup
create_backup() {
local file=$1
local backup_path="$BACKUP_DIR/$(dirname "$file")"
mkdir -p "$backup_path"
cp -P "$file" "$backup_path/"
echo -e "${GREEN} ✓ Backup created${NC}"
}
# Function to create symlink
create_symlink() {
local target=$1
local link=$2
# Create parent directory if it doesn't exist
mkdir -p "$(dirname "$link")"
# Remove existing file/link
rm -rf "$link"
# Create symlink
ln -s "$target" "$link"
echo -e "${GREEN} ✓ Symlink created${NC}"
}
# Function to process a file
process_file() {
local source=$1
local target=$2
local description=$3
echo ""
echo -e "${BLUE}Processing:${NC} $description"
echo -e " Source: $source"
echo -e " Target: $target"
# Check if target is already a symlink to our dotfiles
if [ -L "$target" ]; then
local link_target=$(readlink "$target")
if [ "$link_target" = "$source" ]; then
echo -e "${GREEN} ✓ Already linked correctly${NC}"
return
else
echo -e "${YELLOW} ⚠ Existing symlink points to: $link_target${NC}"
fi
elif [ -e "$target" ]; then
echo -e "${YELLOW} ⚠ File exists${NC}"
else
echo -e "${YELLOW} ⚠ File does not exist${NC}"
fi
# Prompt user
read -p "$(echo -e ${BLUE}Do you want to link this file? [y/N/s=skip]:${NC} )" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Backup existing file if it exists and is not a symlink to our repo
if [ -e "$target" ]; then
create_backup "$target"
fi
create_symlink "$source" "$target"
elif [[ $REPLY =~ ^[Ss]$ ]]; then
echo -e "${YELLOW} ⊘ Skipped${NC}"
else
echo -e "${YELLOW} ⊘ Skipped${NC}"
fi
}
# Files to symlink (source|target pairs)
FILES=(
"$DOTFILES_DIR/zsh/.zshrc|$HOME/.zshrc"
"$DOTFILES_DIR/zsh/themes/parrot.zsh-theme|$HOME/.oh-my-zsh/custom/themes/parrot.zsh-theme"
"$DOTFILES_DIR/claude/CLAUDE.md|$HOME/.claude/CLAUDE.md"
)
# Process each file
for entry in "${FILES[@]}"; do
IFS='|' read -r source target <<< "$entry"
description=$(basename "$target")
process_file "$source" "$target" "$description"
done
# Handle .zshrc.local specially
echo ""
echo -e "${BLUE}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ .zshrc.local Configuration ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════╝${NC}"
echo ""
if [ -f "$HOME/.zshrc.local" ]; then
echo -e "${GREEN}✓ .zshrc.local already exists${NC}"
echo -e " Location: $HOME/.zshrc.local"
else
echo -e "${YELLOW}⚠ .zshrc.local does not exist${NC}"
read -p "$(echo -e ${BLUE}Create .zshrc.local from template? [Y/n]:${NC} )" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo -e "${YELLOW} ⊘ Skipped${NC}"
else
cp "$DOTFILES_DIR/zsh/.zshrc.local.template" "$HOME/.zshrc.local"
echo -e "${GREEN} ✓ Created $HOME/.zshrc.local from template${NC}"
echo -e "${YELLOW} ⚠ Remember to uncomment and configure required settings (especially NVM)${NC}"
fi
fi
# Handle Syncthing .stignore
echo ""
echo -e "${BLUE}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Syncthing .stignore Configuration ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════╝${NC}"
echo ""
# Ask for sync folder location
read -p "$(echo -e ${BLUE}Enter your Syncthing work folder path [default: ~/work]:${NC} )" SYNC_FOLDER
SYNC_FOLDER=${SYNC_FOLDER:-$HOME/work}
# Expand tilde
SYNC_FOLDER="${SYNC_FOLDER/#\~/$HOME}"
if [ -d "$SYNC_FOLDER" ]; then
if [ -L "$SYNC_FOLDER/.stignore" ]; then
LINK_TARGET=$(readlink "$SYNC_FOLDER/.stignore")
if [ "$LINK_TARGET" = "$DOTFILES_DIR/syncthing/.stignore" ]; then
echo -e "${GREEN}✓ .stignore already linked correctly${NC}"
echo -e " Location: $SYNC_FOLDER/.stignore → $DOTFILES_DIR/syncthing/.stignore"
else
echo -e "${YELLOW}⚠ .stignore exists but points to: $LINK_TARGET${NC}"
read -p "$(echo -e ${BLUE}Update symlink? [Y/n]:${NC} )" -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
rm "$SYNC_FOLDER/.stignore"
ln -s "$DOTFILES_DIR/syncthing/.stignore" "$SYNC_FOLDER/.stignore"
echo -e "${GREEN} ✓ Updated symlink${NC}"
fi
fi
elif [ -f "$SYNC_FOLDER/.stignore" ]; then
echo -e "${YELLOW}⚠ .stignore file exists (not a symlink)${NC}"
read -p "$(echo -e ${BLUE}Replace with symlink? [y/N]:${NC} )" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -d "$BACKUP_DIR" ]; then
cp "$SYNC_FOLDER/.stignore" "$BACKUP_DIR/.stignore"
echo -e "${GREEN} ✓ Backed up existing .stignore${NC}"
fi
rm "$SYNC_FOLDER/.stignore"
ln -s "$DOTFILES_DIR/syncthing/.stignore" "$SYNC_FOLDER/.stignore"
echo -e "${GREEN} ✓ Created symlink${NC}"
else
echo -e "${YELLOW} ⊘ Skipped${NC}"
fi
else
echo -e "${YELLOW}⚠ .stignore does not exist${NC}"
read -p "$(echo -e ${BLUE}Create symlink? [Y/n]:${NC} )" -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
ln -s "$DOTFILES_DIR/syncthing/.stignore" "$SYNC_FOLDER/.stignore"
echo -e "${GREEN} ✓ Created symlink${NC}"
echo -e "${YELLOW} ⚠ Restart Syncthing or rescan folder for changes to take effect${NC}"
else
echo -e "${YELLOW} ⊘ Skipped${NC}"
fi
fi
else
echo -e "${YELLOW}⚠ Sync folder not found: $SYNC_FOLDER${NC}"
echo -e " Create the folder and run this script again, or manually create symlink:"
echo -e " ln -s $DOTFILES_DIR/syncthing/.stignore $SYNC_FOLDER/.stignore"
fi
# Summary
echo ""
echo -e "${BLUE}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Installation Complete ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════╝${NC}"
echo ""
if [ -d "$BACKUP_DIR" ]; then
echo -e "${GREEN}✓ Backups saved to:${NC} $BACKUP_DIR"
fi
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo -e " 1. Edit ~/.zshrc.local and uncomment required configurations"
echo -e " 2. Restart your shell or run: source ~/.zshrc"
echo -e " 3. If Syncthing is running, rescan folder or restart to apply .stignore"
echo ""