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/gitrootData"
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
44# if [[ -z "${NO_LAUNCH}" ]]; then
45 APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
46 if [ -z "$APP" ]; then
47 report "🟢 Gitroot not launched"
48 else
49 kill ${APP}
50 report "🟢 Gitroot killed"
51 fi
52
53 cp -rf ${SCRIPT_DIR}/../plugins/ladybug/ladybug-0.0.1.wasm ${SERVER_DATA_DIR}/data/plugins/ladybug/
54 cp -rf ${SCRIPT_DIR}/../plugins/silo/silo-0.0.1.wasm ${SERVER_DATA_DIR}/data/plugins/silo/
55 cp -rf ${SCRIPT_DIR}/../plugins/apex/apex-0.0.1.wasm ${SERVER_DATA_DIR}/data/plugins/apex/
56 cp -rf ${SCRIPT_DIR}/../plugins/grafter/grafter-0.0.1.wasm ${SERVER_DATA_DIR}/data/plugins/grafter/
57
58 ##### launch gitroot
59 report "🏁 launch gitroot"
60
61 cd ${SCRIPT_DIR}/../server
62 go run -race . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
63
64 sleep 1.3
65# fi
66
67rm -rf /tmp/gitroot
68
69if [[ -z "${NO_LAUNCH}" ]]; then
70 rm -rf ${SERVER_DATA_DIR}/repositories/gitroot
71 rm -rf ${SERVER_DATA_DIR}/data/web/gitroot
72 rm -rf ${SERVER_DATA_DIR}/data/cache/gitroot
73
74 cd /tmp/${ROOT_REPO_NAME}
75 quiet_git checkout main
76 quiet_git pull --rebase origin main
77
78 echo "" >> .gitroot/repositories.yml
79 echo "gitroot:" >> .gitroot/repositories.yml
80 echo " kind: fork" >> .gitroot/repositories.yml
81 echo " defaultbranch: main" >> .gitroot/repositories.yml
82 echo " forkurl: \"https://gitlab.com/gitroot/gitroot.git\"" >> .gitroot/repositories.yml
83
84 quiet_git add .
85 quiet_git commit -m "proxy gitroot"
86 quiet_git push origin main
87 report "🟢 gitroot repo added has proxy"
88
89 sleep 1
90fi
91
92cd /tmp
93quiet_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"
94
95cd gitroot
96quiet_git pull --rebase origin main
97.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
98
99cat ${SCRIPT_DIR}/proxy-ressources/all-plugins.yml > ./.gitroot/plugins.yml
100cp ${SCRIPT_DIR}/proxy-ressources/index.md ./index.md
101cp ${SCRIPT_DIR}/README.md .
102cp ${SCRIPT_DIR}/CONTRIBUTING.md .
103cp ${SCRIPT_DIR}/CHANGELOG.md .
104cp -r ${SCRIPT_DIR}/docs/ .
105
106quiet_git add .
107quiet_git commit -m "active and configure plugins"
108quiet_git push origin main
109report "🟢 active and configure plugins"
110
111sleep 0.01
112
113quiet_git pull --rebase origin main
114report "🟢 all is ok go to http://127.0.0.1:4546/gitroot/"