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
7trap 'catch $LINENO' ERR
8
9EXPECTED_ERROR=0
10
11catch() {
12 if [[ $EXPECTED_ERROR == 0 ]]; then
13 echo "🛑 unexpected error line $1"
14 exit 1
15 fi
16 report "🟢 expected err line $1"
17}
18
19ROOT_REPO_NAME="root"
20REPO1_NAME="repo1"
21REPO2_NAME="repo2"
22
23SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
24
25SERVER_PORT="4545"
26SERVER_DATA_DIR="/tmp/gitrootDataProxy"
27
28SSH_KEY="${SCRIPT_DIR}/user1/ed25519"
29
30quiet_git() {
31 echo "🚀 git $@" >> /tmp/mylog.txt
32 GIT_TRACE=false GIT_TRACE_PACKET=false git "$@" &>> /tmp/mylog.txt
33}
34
35real_quiet_git() {
36 git "$@" &>> /dev/null
37}
38
39report() {
40 echo "$1" >> /tmp/mylog.txt
41 echo "$1"
42}
43
44APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
45if [ -z "$APP" ]; then
46 report "🟢 Gitroot not launched"
47else
48 kill ${APP}
49 report "🟢 Gitroot killed"
50fi
51ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[127.0.0.1]:$SERVER_PORT"
52
53rm -rf ${SERVER_DATA_DIR}
54rm -rf /tmp/gitroot
55echo "" > /tmp/mylog.txt
56
57##### launch gitroot
58report "🏁 launch gitroot"
59
60cd ${SCRIPT_DIR}/../server
61go run -race . -data="${SERVER_DATA_DIR}" -remote="https://gitlab.com/gitroot/gitroot.git" &>> /tmp/mylog.txt &
62
63sleep 1.3
64
65cd /tmp
66quiet_git clone --quiet -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" "ssh://user@127.0.0.1:4545/" gitroot
67
68cd gitroot
69quiet_git pull --rebase origin main
70.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
71
72cat ${SCRIPT_DIR}/proxy-ressources/all-plugins.yml > ./.gitroot/plugins.yml
73cp ${SCRIPT_DIR}/proxy-ressources/index.md ./index.md
74cp ${SCRIPT_DIR}/../../README.md .
75cp ${SCRIPT_DIR}/../../CONTRIBUTING.md .
76cp ${SCRIPT_DIR}/../../CHANGELOG.md .
77cp -r ${SCRIPT_DIR}/../../doc/ .
78
79quiet_git add .
80quiet_git commit -m "active and configure plugins"
81quiet_git push origin main
82report "🟢 active and configure plugins"
83
84sleep 30
85quiet_git pull --rebase origin main
86report "🟢 rebase done"
87
88APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
89kill ${APP}
90report "🟢 Gitroot killed"
91
92cd ${SCRIPT_DIR}/../server
93go run -race . -data="${SERVER_DATA_DIR}" -remote="https://gitlab.com/gitroot/gitroot.git" &>> /tmp/mylog.txt &
94report "🟢 Gitroot launched"
95sleep 1.3
96
97cd /tmp/gitroot
98
99
100quiet_git pull --rebase origin main
101quiet_git checkout -b firstGraft
102echo "// TODO better main" >> doc/index.md
103quiet_git add .
104quiet_git commit -m "better main"
105quiet_git push origin firstGraft
106
107report "🟢 all is ok go to http://127.0.0.1:4546"