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.1.wasm'" >> .gitroot/plugins.yml
210echo "  crc32: null" >> .gitroot/plugins.yml
211echo "  name: ladybug" >> .gitroot/plugins.yml
212
213codium /tmp/${ROOT_REPO_NAME}/.gitroot/plugins.yml
214
215my_read "Press enter to commit and push"
216
217quiet_git add .
218quiet_git commit -m "init ladybug plugin"
219quiet_git push origin main
220
221report " | 🟢 ${ROOT_REPO_NAME} plugin ladybug installed"
222
223sleep 1
224quiet_git pull origin main
225
226my_read "Press enter to use in $REPO1_NAME"
227
228cd /tmp/${REPO1_NAME}
229report " | 👽 git pull in ${REPO1_NAME}"
230quiet_git pull
231codium /tmp/${REPO1_NAME}/.gitroot/plugins.yml
232
233my_read "Press enter to active in repo1"
234
235sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
236
237my_read "Press enter to commit"
238
239quiet_git add .
240quiet_git commit -m "init ladybug plugin"
241quiet_git push origin main
242report " | 🟢 ${REPO1_NAME} plugin ladybug activated"
243
244my_read "Press enter to create first issue"
245
246mkdir issues
247echo "# my Issue" >> issues/1.md
248echo "" >> issues/1.md
249echo "Beatiful issue" >> issues/1.md
250
251my_read "Press enter to commit first issue"
252
253quiet_git add .
254quiet_git commit -m "first issue in second repo"
255quiet_git push origin main
256report " | 👽 git push origin main"
257
258sleep 1
259
260quiet_git pull
261report " | 👽 git pull origin main"
262
263my_read "Press enter to install silo"
264
265cd /tmp/${ROOT_REPO_NAME}
266echo "- url: '${SCRIPT_DIR}/../plugins/silo/silo-0.0.1.wasm'" >> .gitroot/plugins.yml
267echo "  crc32: null" >> .gitroot/plugins.yml
268echo "  name: silo" >> .gitroot/plugins.yml
269quiet_git add .
270quiet_git commit -m "init silo plugin"
271quiet_git push origin main
272report " | 🟢 ${ROOT_REPO_NAME} plugin silo installed"
273sleep 1
274quiet_git pull origin main
275cd /tmp/${REPO1_NAME}
276report " | 👽 git pull in ${REPO1_NAME}"
277quiet_git pull
278
279sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
280quiet_git add .
281quiet_git commit -m "init silo plugin"
282quiet_git push origin main
283report " | 👽 git push origin main"
284
285sleep 1
286
287quiet_git pull
288report " | 👽 git pull origin main"
289report " | 🟢 ${REPO1_NAME} plugin silo activated"
290
291my_read "Press enter to create 50 issues"
292
293rm issues/1.md
294for (( i=0; i<=50; i++ ))
295do
296    echo "# my Issue $i" >> issues/$i.md
297    echo "" >> issues/$i.md
298    echo "Beatiful issue" >> issues/$i.md
299done
300quiet_git add .
301quiet_git commit -m "50 issues created"
302quiet_git push origin main
303report " | 🟢 ${REPO1_NAME} 50 issues created"
304
305my_read "Press enter to pull"
306quiet_git pull origin main
307
308my_read "Press enter randomise prio"
309for (( i=0; i<=50; i++ ))
310do
311    PRIO=$(shuf -i 0-50 -n 1)
312    sed -i -e "s/priority: 50/priority: $PRIO/g" issues/$i.md
313done
314quiet_git add .
315quiet_git commit -m "50 issues prio random"
316quiet_git push origin main
317
318sleep 1
319quiet_git pull origin main
320
321report " | 🟢 ${REPO1_NAME} 50 issues organized"
322codium /tmp/${REPO1_NAME}/boards/triage.md
323
324my_read "Press enter to install grafter"
325
326cd /tmp/${ROOT_REPO_NAME}
327echo "- url: '${SCRIPT_DIR}/../plugins/grafter/grafter-0.0.1.wasm'" >> .gitroot/plugins.yml
328echo "  crc32: null" >> .gitroot/plugins.yml
329echo "  name: grafter" >> .gitroot/plugins.yml
330quiet_git add .
331quiet_git commit -m "init grafter plugin"
332quiet_git push origin main
333report " | 🟢 ${ROOT_REPO_NAME} plugin grafter installed"
334sleep 1
335quiet_git pull origin main
336cd /tmp/${REPO1_NAME}
337report " | 👽 git pull in ${REPO1_NAME}"
338quiet_git pull
339
340sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
341quiet_git add .
342quiet_git commit -m "init grafter plugin"
343quiet_git push origin main
344
345my_read "Press enter to graft"
346
347report " | 👽 git checkout -b first_graft"
348quiet_git checkout -b first_graft
349echo "# My fabulous project" > README.md
350echo "" >> README.md
351echo "This is the most excyting project!" >> README.md
352codium /tmp/${REPO1_NAME}/README.md
353
354my_read "Press enter to send graft"
355quiet_git add .
356quiet_git commit -m "first graft"
357report " | 👽 git push origin first_graft"
358quiet_git push origin first_graft
359report " | 🟢 First graft created"
360
361sleep 1
362quiet_git pull origin first_graft
363codium /tmp/${REPO1_NAME}/grafts/first_graft.md
364
365my_read "Press enter to review graft"
366
367echo "" >> grafts/first_graft.md
368echo "---" >> grafts/first_graft.md
369echo "/review" >> grafts/first_graft.md
370
371quiet_git add .
372quiet_git commit -m "review first graft"
373report " | 👽 git push origin first_graft"
374quiet_git push origin first_graft
375report " | 🟢 First graft review"
376
377my_read "Press enter to make a comment in graft"
378
379quiet_git pull origin first_graft
380sed -i -e 's/excyting/exciting/g' README.md
381quiet_git add .
382quiet_git commit -m "review first graft"
383report " | 👽 git push origin first_graft"
384quiet_git push origin first_graft
385report " | 🟢 First graft review"
386
387sleep 1
388quiet_git pull origin first_graft
389
390my_read "Press enter to merge graft"
391
392echo "" >> grafts/first_graft.md
393echo "---" >> grafts/first_graft.md
394echo "/merge" >> grafts/first_graft.md
395
396my_read "Press enter to merge graft"
397
398quiet_git add .
399quiet_git commit -m "accept first graft"
400report " | 👽 git push origin first_graft"
401quiet_git push origin first_graft
402report " | 🟢 First graft merged"
403
404sleep 1
405quiet_git checkout main
406report " | 👽 git checkout main"
407quiet_git pull origin main
408report " | 👽 git pull origin main"
409codium /tmp/${REPO1_NAME}/README.md
410
411my_read "Press enter to install apex"
412
413cd /tmp/${ROOT_REPO_NAME}
414echo "- url: '${SCRIPT_DIR}/../plugins/apex/apex-0.0.1.wasm'" >> .gitroot/plugins.yml
415echo "  crc32: null" >> .gitroot/plugins.yml
416echo "  name: apex" >> .gitroot/plugins.yml
417quiet_git add .
418quiet_git commit -m "init apex plugin"
419quiet_git push origin main
420report " | 🟢 ${ROOT_REPO_NAME} plugin apex installed"
421sleep 1
422quiet_git pull origin main
423cd /tmp/${REPO1_NAME}
424report " | 👽 git pull in ${REPO1_NAME}"
425quiet_git pull
426
427sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
428quiet_git add .
429quiet_git commit -m "init apex plugin"
430quiet_git push origin main
431
432report " | 🟢 http://127.0.0.1:4546/${REPO1_NAME}/"
433
434my_read "Press enter to style"
435
436quiet_git pull origin main
437
438sed -i -e 's/active: true/active: false/g' .gitroot/plugins.yml
439
440quiet_git add .
441quiet_git commit -m "inactive all"
442quiet_git push origin main
443
444sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
445sed -i -e 's/style: simple.min.css/style: style.css/g' .gitroot/plugins.yml
446
447cp ${SCRIPT_DIR}/../server/resources/styles/simple.min.css style.css
448echo "body { background-color: 010409 }" >> style.css
449echo "body > header { background-color: 010409; text-align: left; padding: 0 1rem }" >> style.css
450echo "body > header h1 { font-size: 1rem }" >> style.css
451echo "header > nav  ul { place-content: normal }" >> style.css
452echo "header > nav  a { margin: 0 .5rem; border: 0 }" >> style.css
453
454quiet_git add .
455quiet_git commit -m "perso style"
456quiet_git push origin main
457
458my_read "Press enter to exit"