GitRoot

craft your forge, build your project, grow your community freely
  1#!/usr/bin/env bash
  2
  3# SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
  4#
  5# SPDX-License-Identifier: EUPL-1.2
  6
  7SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  8
  9SERVER_PORT="4545"
 10SERVER_URL=${1:-"127.0.0.1:$SERVER_PORT"}
 11SERVER_DATA_DIR="/tmp/gitrootData"
 12
 13ROOT_REPO_NAME="root"
 14ROOT_REPO_URL="ssh://user@${SERVER_URL}/${ROOT_REPO_NAME}"
 15REPO1_NAME="repo1"
 16REPO1_URL="ssh://user@${SERVER_URL}/${REPO1_NAME}"
 17
 18SSH_KEY="${SCRIPT_DIR}/user1/ed25519"
 19SSH_KEY2="${SCRIPT_DIR}/user2/ed25519"
 20
 21report() {
 22    echo "$1" >> /tmp/mylog.txt
 23    echo -e "$1"
 24}
 25
 26quiet_git() {
 27    echo "🚀 git $@" >> /tmp/mylog.txt
 28    GIT_TRACE=false GIT_TRACE_PACKET=false git "$@" &>> /tmp/mylog.txt
 29}
 30
 31my_read() {
 32    tput sc
 33    read  -n 1 -p "$1"
 34    tput rc
 35    tput ed
 36}
 37
 38report ""
 39report " _______ __________________ _______  _______  _______ _________"
 40report "(  ____ \\__   __/\__   __/(  ____ )(  ___  )(  ___  )\__   __/"
 41report "| (    \/   ) (      ) (   | (    )|| (   ) || (   ) |   ) (   "
 42report "| |         | |      | |   | (____)|| |   | || |   | |   | |   "
 43report "| | ____    | |      | |   |     __)| |   | || |   | |   | |   "
 44report "| | \_  )   | |      | |   | (\ (   | |   | || |   | |   | |   "
 45report "| (___) |___) (___   | |   | ) \ \__| (___) || (___) |   | |   "
 46report "(_______)\_______/   )_(   |/   \__/(_______)(_______)   )_(   "
 47report ""
 48report " | 🏁 means start a new chapter"
 49report " | 👽 means a command will be launch"
 50report " | 🟢 means a command is successfull"
 51report " | 🛑 means a command has fail"
 52my_read "Press enter to start"
 53
 54##### clean
 55report "🏁 clean"
 56
 57cd /tmp
 58rm -rf ${SERVER_DATA_DIR}
 59rm -rf ${ROOT_REPO_NAME}
 60rm -rf ${REPO1_NAME}
 61rm -rf ${REPO2_NAME}
 62rm -rf ${REPO1_NAME}_2
 63rm -rf ${REPO2_NAME}_2
 64rm -f /tmp/mylog.txt
 65APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}') 
 66if [ -z "$APP" ]; then
 67    report " | 🟢 Gitroot not launched"
 68else 
 69    kill ${APP}
 70    report " | 🟢 Gitroot killed"
 71fi
 72ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[127.0.0.1]:$SERVER_PORT" &>> /tmp/mylog.txt
 73
 74##### init
 75report "🏁 before start configure the demo: "
 76read -p " | Name of the forge administrator: " NAME_ADMIN
 77NAME_ADMIN="${NAME_ADMIN:-admin}"
 78read -p " | Name of the owner project: " NAME_OWNER_PROJECT
 79NAME_OWNER_PROJECT="${NAME_OWNER_PROJECT:-owner}"
 80read -p " | Name of the project: " NAME_PROJECT
 81REPO1_NAME="${NAME_PROJECT:-project}"
 82REPO1_URL="ssh://user@${SERVER_URL}/${REPO1_NAME}"
 83read -p " | Name of the contributor: " NAME_CONTRIBUTOR
 84NAME_CONTRIBUTOR="${NAME_CONTRIBUTOR:-contributor}"
 85
 86##### launch gitroot
 87report "🏁 $NAME_ADMIN launch gitroot: "
 88report " | 👽 ./gitroot -data=\"${SERVER_DATA_DIR}\""
 89
 90cd ${SCRIPT_DIR}/../server
 91GIT_TRACE_PACKET=false go run . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
 92
 93sleep 3
 94
 95report " | 🟢 Gitroot launched"
 96
 97codium -n "${SERVER_DATA_DIR}"
 98
 99my_read "Press enter to clone root repo"
100
101report " | 👽 git clone ${ROOT_REPO_URL}"
102
103cd /tmp
104quiet_git clone -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" ${ROOT_REPO_URL}
105cd ${ROOT_REPO_NAME}
106
107my_read "Press enter to open /tmp/${ROOT_REPO_NAME}"
108
109codium -n "/tmp/${ROOT_REPO_NAME}"
110
111my_read "Press enter to configure"
112
113report " | 👽 .gitroot/init.sh"
114
115.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email $NAME_ADMIN@gitroot.dev --name $NAME_ADMIN >> /tmp/mylog.txt
116
117my_read "Press enter to commit user"
118
119quiet_git add .
120quiet_git commit -m "init user"
121report " | 🟢 ${ROOT_REPO_NAME} commit user"
122
123my_read "Press enter to create $REPO1_NAME repo"
124
125printf "${REPO1_NAME}:\n  defaultbranch: main" >> .gitroot/repositories.yml
126
127codium "/tmp/${ROOT_REPO_NAME}/.gitroot/repositories.yml"
128
129my_read "Press enter to commit first repo"
130
131quiet_git add .
132quiet_git commit -m "create first repo"
133quiet_git push origin main
134report " | 🟢 ${ROOT_REPO_NAME} push $REPO1_NAME repo"
135
136report "🏁 $NAME_OWNER_PROJECT use $REPO1_NAME"
137
138my_read "Press enter to clone first $REPO1_NAME"
139
140cd /tmp
141GIT_SSH_COMMAND="ssh -i ${SSH_KEY} -o IdentitiesOnly=yes" quiet_git clone "${REPO1_URL}"
142cd ${REPO1_NAME}
143.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email $NAME_OWNER_PROJECT@gitroot.dev --name $NAME_OWNER_PROJECT >> /tmp/mylog.txt
144
145report " | 👽 git clone ${REPO1_URL}"
146report " | 🟢 ${REPO1_NAME} clone"
147report " | 👽 .gitroot/init.sh"
148report " | 🟢 ${REPO1_NAME} init"
149report " | 👽 git commit -am \"init user\" && git push"
150quiet_git add .
151quiet_git commit -m "init user"
152quiet_git push
153report " | 🟢 ${REPO1_NAME} push user"
154
155codium -n "/tmp/${REPO1_NAME}"
156
157my_read "Press enter to add $NAME_CONTRIBUTOR"
158
159report "🏁 $NAME_CONTRIBUTOR want to use $REPO1_NAME"
160report " | 👽 git clone ${REPO1_URL} ${REPO1_NAME}_2"
161
162cd /tmp
163GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone "${REPO1_URL}" ${REPO1_NAME}_2
164
165report " | 🟢 ${REPO1_NAME}_2 clone"
166
167cd ${REPO1_NAME}_2
168.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email $NAME_CONTRIBUTOR@gitroot.dev --name $NAME_CONTRIBUTOR >> /tmp/mylog.txt
169
170report " | 👽 .gitroot/init.sh \$SSH_KEY2"
171codium -n "/tmp/${REPO1_NAME}_2"
172
173my_read "Press enter to modif and commit"
174
175echo "hello" > README.md
176
177quiet_git add .
178quiet_git commit -m "modif $NAME_CONTRIBUTOR"
179report " | 🟢 ${REPO1_NAME}_2 commit $NAME_CONTRIBUTOR"
180
181my_read "⚠ Press enter to push ⚠"
182
183report " | 👽 git push origin main"
184
185tput sc
186git push origin main
187report " | 🛑 ${REPO1_NAME}_2 push $NAME_CONTRIBUTOR on main"
188read  -n 1 -p "??"
189tput rc
190tput ed
191report " | 👽 git reset --soft HEAD^1"
192report " | 👽 git checkout -b init_user2"
193report " | 👽 git commit -am \"init $NAME_CONTRIBUTOR\""
194report " | 👽 git push origin init_user2"
195
196quiet_git reset --soft HEAD^1
197quiet_git checkout -b init_user2
198quiet_git add .
199quiet_git commit -m "init $NAME_CONTRIBUTOR"
200quiet_git push origin init_user2
201
202report " | 🟢 ${REPO1_NAME}_2 push $NAME_CONTRIBUTOR on init_user2"
203
204my_read "Press enter continue..."
205
206report "🏁 $NAME_ADMIN install plugin"
207
208cd /tmp/${ROOT_REPO_NAME}
209echo "- url: '${SCRIPT_DIR}/../plugins/ladybug/ladybug-0.0.2.wasm'" >> .gitroot/plugins.yml
210
211codium /tmp/${ROOT_REPO_NAME}/.gitroot/plugins.yml
212
213my_read "Press enter to commit and push"
214
215quiet_git add .
216quiet_git commit -m "init ladybug plugin"
217quiet_git push origin main
218
219report " | 🟢 ${ROOT_REPO_NAME} plugin ladybug installed"
220
221sleep 1
222quiet_git pull origin main
223
224my_read "Press enter to use in $REPO1_NAME"
225
226cd /tmp/${REPO1_NAME}
227report " | 👽 git pull in ${REPO1_NAME}"
228quiet_git pull
229codium /tmp/${REPO1_NAME}/.gitroot/plugins.yml
230
231my_read "Press enter to active in repo1"
232
233sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
234
235my_read "Press enter to commit"
236
237quiet_git add .
238quiet_git commit -m "init ladybug plugin"
239quiet_git push origin main
240report " | 🟢 ${REPO1_NAME} plugin ladybug activated"
241
242my_read "Press enter to create first issue"
243
244mkdir issues
245echo "# my Issue" >> issues/1.md
246echo "" >> issues/1.md
247echo "Beatiful issue" >> issues/1.md
248
249my_read "Press enter to commit first issue"
250
251quiet_git add .
252quiet_git commit -m "first issue in second repo"
253quiet_git push origin main
254report " | 👽 git push origin main"
255
256sleep 1
257
258quiet_git pull
259report " | 👽 git pull origin main"
260
261my_read "Press enter to install silo"
262
263cd /tmp/${ROOT_REPO_NAME}
264echo "- url: '${SCRIPT_DIR}/../plugins/silo/silo-0.0.2.wasm'" >> .gitroot/plugins.yml
265quiet_git add .
266quiet_git commit -m "init silo plugin"
267quiet_git push origin main
268report " | 🟢 ${ROOT_REPO_NAME} plugin silo installed"
269sleep 1
270quiet_git pull origin main
271cd /tmp/${REPO1_NAME}
272report " | 👽 git pull in ${REPO1_NAME}"
273quiet_git pull
274
275sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
276quiet_git add .
277quiet_git commit -m "init silo plugin"
278quiet_git push origin main
279report " | 👽 git push origin main"
280
281sleep 1
282
283quiet_git pull
284report " | 👽 git pull origin main"
285report " | 🟢 ${REPO1_NAME} plugin silo activated"
286
287my_read "Press enter to create 50 issues"
288
289rm issues/1.md
290for (( i=0; i<=50; i++ ))
291do
292    echo "# my Issue $i" >> issues/$i.md
293    echo "" >> issues/$i.md
294    echo "Beatiful issue" >> issues/$i.md
295done
296quiet_git add .
297quiet_git commit -m "50 issues created"
298quiet_git push origin main
299report " | 🟢 ${REPO1_NAME} 50 issues created"
300
301my_read "Press enter to pull"
302quiet_git pull origin main
303
304my_read "Press enter randomise prio"
305for (( i=0; i<=50; i++ ))
306do
307    PRIO=$(shuf -i 0-50 -n 1)
308    sed -i -e "s/priority: 50/priority: $PRIO/g" issues/$i.md
309done
310quiet_git add .
311quiet_git commit -m "50 issues prio random"
312quiet_git push origin main
313
314sleep 1
315quiet_git pull origin main
316
317report " | 🟢 ${REPO1_NAME} 50 issues organized"
318codium /tmp/${REPO1_NAME}/boards/triage.md
319
320my_read "Press enter to install grafter"
321
322cd /tmp/${ROOT_REPO_NAME}
323echo "- url: '${SCRIPT_DIR}/../plugins/grafter/grafter-0.0.2.wasm'" >> .gitroot/plugins.yml
324quiet_git add .
325quiet_git commit -m "init grafter plugin"
326quiet_git push origin main
327report " | 🟢 ${ROOT_REPO_NAME} plugin grafter installed"
328sleep 1
329quiet_git pull origin main
330cd /tmp/${REPO1_NAME}
331report " | 👽 git pull in ${REPO1_NAME}"
332quiet_git pull
333
334sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
335quiet_git add .
336quiet_git commit -m "init grafter plugin"
337quiet_git push origin main
338
339my_read "Press enter to graft"
340
341report " | 👽 git checkout -b first_graft"
342quiet_git checkout -b first_graft
343echo "# My fabulous project" > README.md
344echo "" >> README.md
345echo "This is the most excyting project!" >> README.md
346codium /tmp/${REPO1_NAME}/README.md
347
348my_read "Press enter to send graft"
349quiet_git add .
350quiet_git commit -m "first graft"
351report " | 👽 git push origin first_graft"
352quiet_git push origin first_graft
353report " | 🟢 First graft created"
354
355sleep 1
356quiet_git pull origin first_graft
357codium /tmp/${REPO1_NAME}/grafts/first_graft.md
358
359my_read "Press enter to review graft"
360
361echo "" >> grafts/first_graft.md
362echo "---" >> grafts/first_graft.md
363echo "/review" >> grafts/first_graft.md
364
365quiet_git add .
366quiet_git commit -m "review first graft"
367report " | 👽 git push origin first_graft"
368quiet_git push origin first_graft
369report " | 🟢 First graft review"
370
371my_read "Press enter to make a comment in graft"
372
373quiet_git pull origin first_graft
374sed -i -e 's/excyting/exciting/g' README.md
375quiet_git add .
376quiet_git commit -m "review first graft"
377report " | 👽 git push origin first_graft"
378quiet_git push origin first_graft
379report " | 🟢 First graft review"
380
381sleep 1
382quiet_git pull origin first_graft
383
384my_read "Press enter to merge graft"
385
386echo "" >> grafts/first_graft.md
387echo "---" >> grafts/first_graft.md
388echo "/merge" >> grafts/first_graft.md
389
390my_read "Press enter to merge graft"
391
392quiet_git add .
393quiet_git commit -m "accept first graft"
394report " | 👽 git push origin first_graft"
395quiet_git push origin first_graft
396report " | 🟢 First graft merged"
397
398sleep 1
399quiet_git checkout main
400report " | 👽 git checkout main"
401quiet_git pull origin main
402report " | 👽 git pull origin main"
403codium /tmp/${REPO1_NAME}/README.md
404
405my_read "Press enter to install apex"
406
407cd /tmp/${ROOT_REPO_NAME}
408echo "- url: '${SCRIPT_DIR}/../plugins/apex/apex-0.0.2.wasm'" >> .gitroot/plugins.yml
409quiet_git add .
410quiet_git commit -m "init apex plugin"
411quiet_git push origin main
412report " | 🟢 ${ROOT_REPO_NAME} plugin apex installed"
413sleep 1
414quiet_git pull origin main
415cd /tmp/${REPO1_NAME}
416report " | 👽 git pull in ${REPO1_NAME}"
417quiet_git pull
418
419sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
420quiet_git add .
421quiet_git commit -m "init apex plugin"
422quiet_git push origin main
423
424report " | 🟢 http://127.0.0.1:4546/${REPO1_NAME}/"
425
426my_read "Press enter to style"
427
428quiet_git pull origin main
429
430sed -i -e 's/active: true/active: false/g' .gitroot/plugins.yml
431
432quiet_git add .
433quiet_git commit -m "inactive all"
434quiet_git push origin main
435
436sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
437sed -i -e 's/style: simple.min.css/style: style.css/g' .gitroot/plugins.yml
438
439cp ${SCRIPT_DIR}/../server/resources/styles/simple.min.css style.css
440echo "body { background-color: 010409 }" >> style.css
441echo "body > header { background-color: 010409; text-align: left; padding: 0 1rem }" >> style.css
442echo "body > header h1 { font-size: 1rem }" >> style.css
443echo "header > nav  ul { place-content: normal }" >> style.css
444echo "header > nav  a { margin: 0 .5rem; border: 0 }" >> style.css
445
446quiet_git add .
447quiet_git commit -m "perso style"
448quiet_git push origin main
449
450my_read "Press enter to exit"