-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·209 lines (179 loc) · 7.67 KB
/
install.sh
File metadata and controls
executable file
·209 lines (179 loc) · 7.67 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
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HOME_DIR="$HOME"
echo "=== Installing environment from $SCRIPT_DIR ==="
# =============================================================================
# 1. Symlink dotfiles (.tmux.conf, .vimrc)
# =============================================================================
for config in ".tmux.conf" ".vimrc"; do
src="$SCRIPT_DIR/$config"
dst="$HOME_DIR/$config"
if [ -e "$dst" ] || [ -L "$dst" ]; then
if [ -L "$dst" ] && [ "$(readlink "$dst")" = "$src" ]; then
echo " $config: already linked"
continue
fi
mv "$dst" "${dst}.old"
echo " $config: backed up existing to ${config}.old"
fi
ln -s "$src" "$dst"
echo " $config: linked"
done
# =============================================================================
# 2. Ghostty config (macOS only)
# =============================================================================
if [[ "$OSTYPE" == "darwin"* ]]; then
ghostty_src="$SCRIPT_DIR/ghostty/config"
ghostty_dst="$HOME_DIR/.config/ghostty/config"
if [ -f "$ghostty_src" ]; then
mkdir -p "$(dirname "$ghostty_dst")"
if [ -L "$ghostty_dst" ] && [ "$(readlink "$ghostty_dst")" = "$ghostty_src" ]; then
echo " ghostty/config: already linked"
else
[ -e "$ghostty_dst" ] && mv "$ghostty_dst" "${ghostty_dst}.old"
ln -s "$ghostty_src" "$ghostty_dst"
echo " ghostty/config: linked"
fi
fi
fi
# =============================================================================
# 3. Set up ~/.bashrc to source environment/.bashrc
# =============================================================================
SOURCE_LINE="source $SCRIPT_DIR/.bashrc"
if [ -f "$HOME_DIR/.bashrc.user" ]; then
TARGET_RC="$HOME_DIR/.bashrc.user"
else
TARGET_RC="$HOME_DIR/.bashrc"
fi
# Check for both absolute path and ~ version
TILDE_LINE="source ~/environment/.bashrc"
if [ -f "$TARGET_RC" ] && (grep -qF "$SOURCE_LINE" "$TARGET_RC" 2>/dev/null || grep -qF "$TILDE_LINE" "$TARGET_RC" 2>/dev/null); then
echo " .bashrc: source line already present"
else
echo "$SOURCE_LINE" >> "$TARGET_RC"
echo " .bashrc: added source line to $TARGET_RC"
fi
# =============================================================================
# 4. Set up ~/.claude/ directory
# =============================================================================
mkdir -p "$HOME_DIR/.claude/rules"
# Skills: symlink ~/.claude/skills -> environment's .claude/skills/
# This replaces per-skill symlinks — all skills in environment/.claude/skills/ auto-propagate
SKILLS_LINK="$HOME_DIR/.claude/skills"
SKILLS_TARGET="../environment/.claude/skills"
if [ -L "$SKILLS_LINK" ] && [ "$(readlink "$SKILLS_LINK")" = "$SKILLS_TARGET" ]; then
echo " skills: already linked"
else
# Clean up old per-skill symlinks or directory
if [ -d "$SKILLS_LINK" ] && [ ! -L "$SKILLS_LINK" ]; then
find "$SKILLS_LINK" -maxdepth 1 -type l -delete
rmdir "$SKILLS_LINK" 2>/dev/null || true
fi
[ -L "$SKILLS_LINK" ] && rm "$SKILLS_LINK"
ln -s "$SKILLS_TARGET" "$SKILLS_LINK"
echo " skills: linked to $SKILLS_TARGET"
fi
# =============================================================================
# 5. Generate ~/.claude/CLAUDE.md (base layer + machine context)
# =============================================================================
CLAUDE_MD="$HOME_DIR/.claude/CLAUDE.md"
# Remove old symlink if exists (migration from previous setup)
if [ -L "$CLAUDE_MD" ]; then
rm "$CLAUDE_MD"
echo " CLAUDE.md: removed old symlink"
fi
# Write base layer
{
echo "<!-- BEGIN environment/CLAUDE.md -->"
cat "$SCRIPT_DIR/CLAUDE.md"
echo ""
echo "<!-- END environment/CLAUDE.md -->"
} > "$CLAUDE_MD"
echo " CLAUDE.md: wrote base layer"
# Detect machine context
if [[ "$OSTYPE" == "darwin"* ]]; then
MACHINE_CONTEXT="local"
HOSTNAME_VAL="$(scutil --get LocalHostName 2>/dev/null || hostname -s)"
else
MACHINE_CONTEXT="remote"
HOSTNAME_VAL="$(hostname -s)"
fi
# Check known local hostnames
case "$HOSTNAME_VAL" in
nimoca|icoca) MACHINE_CONTEXT="local" ;;
esac
{
echo ""
echo "<!-- BEGIN machine-context -->"
echo "## Machine Context"
echo ""
echo "This machine (**${HOSTNAME_VAL}**) is a **${MACHINE_CONTEXT}** machine."
if [ "$MACHINE_CONTEXT" = "local" ]; then
echo "This is a macOS development laptop. Most heavy workloads (training, GPU jobs) cannot run here."
echo "To run things on the cluster, SSH into the appropriate login node (\`ssh gb200\`, \`ssh b200\`, etc.)."
else
echo "This is a cluster login node. You can run commands here directly."
echo "Use \`srun\`/\`sbatch\` for GPU workloads; the login node is for lightweight tasks, compilation, and job submission."
fi
echo "<!-- END machine-context -->"
} >> "$CLAUDE_MD"
echo " CLAUDE.md: added machine context ($MACHINE_CONTEXT, $HOSTNAME_VAL)"
# =============================================================================
# 6. Symlink ~/.claude/settings.json
# =============================================================================
SETTINGS_SRC="$SCRIPT_DIR/claude_settings.json"
SETTINGS_DST="$HOME_DIR/.claude/settings.json"
if [ -f "$SETTINGS_SRC" ]; then
REL_SETTINGS="$(python3 -c "import os; print(os.path.relpath('$SETTINGS_SRC', '$(dirname "$SETTINGS_DST")'))")"
if [ -L "$SETTINGS_DST" ] && [ "$(readlink "$SETTINGS_DST")" = "$REL_SETTINGS" ]; then
echo " settings.json: already linked"
else
[ -e "$SETTINGS_DST" ] && mv "$SETTINGS_DST" "${SETTINGS_DST}.old"
ln -s "$REL_SETTINGS" "$SETTINGS_DST"
echo " settings.json: linked"
fi
fi
# =============================================================================
# 7. Set up global gitignore (core.excludesFile) and hooks (core.hooksPath)
# =============================================================================
# Global gitignore
GITIGNORE_SRC="$SCRIPT_DIR/gitignore_global"
if [ -f "$GITIGNORE_SRC" ]; then
CURRENT="$(git config --global core.excludesFile 2>/dev/null || echo "")"
if [ "$CURRENT" = "$GITIGNORE_SRC" ]; then
echo " core.excludesFile: already configured"
else
[ -n "$CURRENT" ] && echo " WARNING: overwriting existing core.excludesFile=$CURRENT"
git config --global core.excludesFile "$GITIGNORE_SRC"
echo " core.excludesFile: set -> $GITIGNORE_SRC"
fi
fi
# Git template directory (provides post-checkout hook for new repos/clones)
TEMPLATE_SRC="$SCRIPT_DIR/git-template"
if [ -d "$TEMPLATE_SRC" ]; then
CURRENT="$(git config --global init.templateDir 2>/dev/null || echo "")"
if [ "$CURRENT" = "$TEMPLATE_SRC" ]; then
echo " init.templateDir: already configured"
else
[ -n "$CURRENT" ] && echo " WARNING: overwriting existing init.templateDir=$CURRENT"
git config --global init.templateDir "$TEMPLATE_SRC"
echo " init.templateDir: set -> $TEMPLATE_SRC"
fi
fi
# Clean up old core.hooksPath if it was set by a previous install
OLD_HOOKS="$(git config --global core.hooksPath 2>/dev/null || echo "")"
if [ -n "$OLD_HOOKS" ]; then
git config --global --unset core.hooksPath
echo " core.hooksPath: removed (migrated to init.templateDir)"
fi
# =============================================================================
# 8. Note about bash_profile
# =============================================================================
if [ ! -f "$HOME_DIR/.bash_profile" ]; then
echo ""
echo " NOTE: No ~/.bash_profile found."
echo " See $SCRIPT_DIR/bash_profile.template for a reference."
fi
echo ""
echo "=== Environment installed. ==="