111 lines
2.8 KiB
Bash
Executable File
111 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
echo "Usage: $0 [gitea_pat] [org] [host]" >&2
|
|
echo "If gitea_pat is omitted, script tries git credential helper for host auth." >&2
|
|
}
|
|
|
|
TOKEN="${1:-}"
|
|
ORG="${2:-edut}"
|
|
HOST="${3:-git.workvsg.com}"
|
|
ROOT="/Users/vsg/Documents/VSG Codex"
|
|
AUTH_MODE=""
|
|
AUTH_USERNAME=""
|
|
AUTH_PASSWORD=""
|
|
|
|
init_auth() {
|
|
if [[ -n "$TOKEN" ]]; then
|
|
AUTH_MODE="token"
|
|
return
|
|
fi
|
|
|
|
local cred user pass
|
|
cred=$(printf 'protocol=https\nhost=%s\n\n' "$HOST" | git credential fill || true)
|
|
user=$(printf '%s\n' "$cred" | awk -F= '/^username=/{print $2}')
|
|
pass=$(printf '%s\n' "$cred" | awk -F= '/^password=/{print $2}')
|
|
if [[ -n "$user" && -n "$pass" ]]; then
|
|
AUTH_MODE="basic"
|
|
AUTH_USERNAME="$user"
|
|
AUTH_PASSWORD="$pass"
|
|
return
|
|
fi
|
|
|
|
usage
|
|
echo "No PAT provided and no git credentials found for ${HOST}." >&2
|
|
exit 1
|
|
}
|
|
|
|
curl_api() {
|
|
local method="$1"
|
|
local url="$2"
|
|
local data="${3:-}"
|
|
local -a cmd=(curl -sS -w "%{http_code}" -o /tmp/edut_api.out -X "$method")
|
|
if [[ "$AUTH_MODE" == "token" ]]; then
|
|
cmd+=(-H "Authorization: token ${TOKEN}")
|
|
else
|
|
cmd+=(-u "${AUTH_USERNAME}:${AUTH_PASSWORD}")
|
|
fi
|
|
if [[ -n "$data" ]]; then
|
|
cmd+=(-H 'Content-Type: application/json' -d "$data")
|
|
fi
|
|
cmd+=("$url")
|
|
"${cmd[@]}"
|
|
}
|
|
|
|
create_repo() {
|
|
local name="$1"
|
|
local private="$2"
|
|
local desc="$3"
|
|
|
|
local api="https://${HOST}/api/v1/repos/${ORG}/${name}"
|
|
local status
|
|
status=$(curl_api "GET" "$api")
|
|
|
|
if [[ "$status" == "200" ]]; then
|
|
echo "Repo ${ORG}/${name} already exists"
|
|
return
|
|
fi
|
|
if [[ "$status" != "404" ]]; then
|
|
echo "Repo check failed for ${ORG}/${name} (status=${status})" >&2
|
|
cat /tmp/edut_api.out >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
status=$(curl_api "POST" "https://${HOST}/api/v1/orgs/${ORG}/repos" "{\"name\":\"${name}\",\"private\":${private},\"description\":\"${desc}\"}")
|
|
if [[ "$status" != "201" && "$status" != "200" ]]; then
|
|
echo "Repo create failed for ${ORG}/${name} (status=${status})" >&2
|
|
cat /tmp/edut_api.out >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
echo "Created repo ${ORG}/${name}"
|
|
}
|
|
|
|
wire_and_push() {
|
|
local local_dir="$1"
|
|
local name="$2"
|
|
local remote_url="https://${HOST}/${ORG}/${name}.git"
|
|
|
|
cd "$local_dir"
|
|
if ! git remote | grep -q '^origin$'; then
|
|
git remote add origin "$remote_url"
|
|
else
|
|
git remote set-url origin "$remote_url"
|
|
fi
|
|
git push -u origin main
|
|
echo "Pushed ${local_dir} -> ${remote_url}"
|
|
}
|
|
|
|
init_auth
|
|
|
|
create_repo "launcher" "true" "EDUT free launcher shell and wallet onboarding app"
|
|
create_repo "governance" "true" "EDUT deterministic governance runtime"
|
|
create_repo "contracts" "false" "EDUT membership and entitlement contracts"
|
|
|
|
wire_and_push "${ROOT}/launcher" "launcher"
|
|
wire_and_push "${ROOT}/governance" "governance"
|
|
wire_and_push "${ROOT}/contracts" "contracts"
|
|
|
|
echo "Split repo publish complete"
|