Skip to content

Commit 18bc138

Browse files
committed
feat(docs): improve install.sh with safe update logic
1 parent 27a43f1 commit 18bc138

2 files changed

Lines changed: 70 additions & 21 deletions

File tree

docs/install.sh

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,51 @@ trap 'rm -rf "$TEMP_DIR"' EXIT
6060
git clone --depth 1 -q "$REPO_URL" "$TEMP_DIR" || error "Failed to clone template repository."
6161

6262
# --- Discovery ---
63+
# Files that are ALWAYS updated (Core Framework)
6364
CORE_FILES=("GEMINI.md")
65+
# Files that are ONLY created if missing (Scaffolding)
6466
SCAFFOLD_FILES=("README.md" "TASKS.md" "CHANGELOG.md" "makefile")
67+
# Directories that are ensured
6568
CONTENT_DIRS=("journal" "plans" "research" "drafts")
69+
# Files within .gemini/ that are PROTECTED (Never overwritten)
70+
PROTECTED_GEMINI_FILES=("settings.json" "style-guide.md")
6671

6772
WILL_CREATE=()
6873
WILL_UPDATE=()
74+
WILL_PROTECT=()
6975

70-
# 1. Core Framework Check
71-
if [[ -d ".gemini" ]]; then
72-
WILL_UPDATE+=(".gemini/ (core framework)")
73-
else
76+
# 1. .gemini Directory Logic
77+
if [[ ! -d ".gemini" ]]; then
7478
WILL_CREATE+=(".gemini/ (core framework)")
79+
else
80+
# Check for protected files
81+
for f in "${PROTECTED_GEMINI_FILES[@]}"; do
82+
if [[ -f ".gemini/$f" ]]; then
83+
WILL_PROTECT+=(".gemini/$f (user configuration)")
84+
fi
85+
done
86+
WILL_UPDATE+=(".gemini/ (hooks, scripts, core commands)")
7587
fi
7688

89+
# 2. Core Files Logic (GEMINI.md)
7790
for f in "${CORE_FILES[@]}"; do
7891
if [[ -e "$f" ]]; then
79-
WILL_UPDATE+=("$f (core framework)")
92+
WILL_UPDATE+=("$f (will preserve 'Project Notes' section if possible)")
8093
else
8194
WILL_CREATE+=("$f (core framework)")
8295
fi
8396
done
8497

85-
# 2. Project Scaffolding Check
98+
# 3. Project Scaffolding Check
8699
for f in "${SCAFFOLD_FILES[@]}"; do
87100
if [[ ! -e "$f" ]]; then
88101
WILL_CREATE+=("$f (new scaffolding)")
102+
else
103+
WILL_PROTECT+=("$f (existing project file)")
89104
fi
90105
done
91106

92-
# 3. Content Directories Check
107+
# 4. Content Directories Check
93108
for d in "${CONTENT_DIRS[@]}"; do
94109
if [[ ! -d "$d" ]]; then
95110
WILL_CREATE+=("$d/ (new content directory)")
@@ -104,10 +119,15 @@ if [[ ${#WILL_CREATE[@]} -gt 0 ]]; then
104119
fi
105120

106121
if [[ ${#WILL_UPDATE[@]} -gt 0 ]]; then
107-
echo -e "\033[1;34mExisting files/folders to update (core framework):\033[0m"
122+
echo -e "\033[1;34mExisting files to update:\033[0m"
108123
for f in "${WILL_UPDATE[@]}"; do echo " ~ $f"; done
109124
fi
110125

126+
if [[ ${#WILL_PROTECT[@]} -gt 0 ]]; then
127+
echo -e "\033[1;35mFiles to preserve (will NOT be modified):\033[0m"
128+
for f in "${WILL_PROTECT[@]}"; do echo " # $f"; done
129+
fi
130+
111131
echo ""
112132
confirm "Do you want to proceed with these changes?"
113133

@@ -119,13 +139,40 @@ fi
119139

120140
echo "🛠️ Applying changes..."
121141

122-
# 1. Update .gemini (non-destructive for user files)
142+
# 1. Update .gemini (Surgical Update)
123143
mkdir -p .gemini
124-
cp -r "$TEMP_DIR/.gemini/." .gemini/
144+
# Copy subdirectories one by one, preserving protected files
145+
for subdir in agents commands hooks scripts; do
146+
if [[ -d "$TEMP_DIR/.gemini/$subdir" ]]; then
147+
mkdir -p ".gemini/$subdir"
148+
cp -r "$TEMP_DIR/.gemini/$subdir/." ".gemini/$subdir/"
149+
fi
150+
done
125151

126-
# 2. Update Core Files (Always)
152+
# Restore protected files if they existed in temp (preventing accidental overwrite if cp -r was used)
153+
for f in "${PROTECTED_GEMINI_FILES[@]}"; do
154+
if [[ -f "$TEMP_DIR/.gemini/$f" && ! -f ".gemini/$f" ]]; then
155+
cp "$TEMP_DIR/.gemini/$f" ".gemini/$f"
156+
fi
157+
done
158+
159+
# 2. Update Core Files with preservation
127160
for f in "${CORE_FILES[@]}"; do
128-
cp "$TEMP_DIR/$f" .
161+
if [[ "$f" == "GEMINI.md" && -f "GEMINI.md" ]]; then
162+
# Try to preserve the section after "## Project Notes"
163+
# We take the header and core mandates from TEMP, and append the user's notes
164+
NOTES_START=$(grep -n "## Project Notes" GEMINI.md | cut -d: -f1 || echo "")
165+
if [[ -n "$NOTES_START" ]]; then
166+
TEMP_CORE=$(sed "/## Project Notes/q" "$TEMP_DIR/GEMINI.md")
167+
USER_NOTES=$(sed "1,$NOTES_START d" GEMINI.md)
168+
echo "$TEMP_CORE" > GEMINI.md
169+
echo "$USER_NOTES" >> GEMINI.md
170+
else
171+
cp "$TEMP_DIR/$f" .
172+
fi
173+
else
174+
cp "$TEMP_DIR/$f" .
175+
fi
129176
done
130177

131178
# 3. Create Scaffolding Files (Only if missing)
@@ -144,21 +191,22 @@ for d in "${CONTENT_DIRS[@]}"; do
144191
done
145192

146193
# 5. Journal Entry
147-
TODAY=$(date +%Y-%m-%d)
148-
mkdir -p journal
149-
JOURNAL_FILE="journal/$TODAY.md"
150-
if [[ ! -f "$JOURNAL_FILE" ]]; then
151-
echo "# $TODAY" > "$JOURNAL_FILE"
152-
fi
153-
154194
if $IS_UPDATE; then
155-
echo -e "\n## Gemini CLI Update\n- Updated framework to version $VERSION." >> "$JOURNAL_FILE"
195+
MSG="Updated Gemini CLI framework to version $VERSION."
156196
COMMIT_MSG="chore: update Gemini CLI framework to v$VERSION"
157197
else
158-
echo -e "\n## Gemini CLI Integration\n- Integrated Gemini CLI framework v$VERSION." >> "$JOURNAL_FILE"
198+
MSG="Integrated Gemini CLI framework version $VERSION."
159199
COMMIT_MSG="feat: integrate Gemini CLI framework v$VERSION"
160200
fi
161201

202+
# Use the project's journal script if it exists
203+
if [[ -f ".gemini/scripts/journal.py" ]]; then
204+
python3 .gemini/scripts/journal.py "$MSG"
205+
else
206+
TODAY=$(date +%Y-%m-%d)
207+
echo -e "\n## Gemini CLI Integration\n- $MSG" >> "journal/$TODAY.md"
208+
fi
209+
162210
# --- Post-Install ---
163211
git add .
164212
git commit -m "$COMMIT_MSG" -q

journal/2026-03-20.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
[2026-03-20T08:35:07] - Testing the pre-commit hook by modifying README.md
77
[2026-03-20T08:37:07] - feat(hooks): add pre-commit hook installation check to welcome script
88
[2026-03-20T08:38:31] - chore(release): version 0.16.0
9+
[2026-03-20T08:41:47] - feat(docs): improve install.sh with safe update logic and preservation of user notes

0 commit comments

Comments
 (0)