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