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