[CI] pgitBot
·
2026-02-26
gen.sh
Shell
1#!/bin/sh
2set -e
3
4PGIT_CONFIG=../pgit.yml
5WWW_DIR=./pub
6REPOS_DIR=./repos
7INDEX_FILE="$WWW_DIR/index.html"
8
9ok() { printf "OK %s\n" "$*"; }
10wrn() { printf "WRN %s\n" "$*"; }
11err() { printf "ERR %s\n" "$*" >&2; }
12
13ok "Syncing repositories..."
14mkdir -p "$REPOS_DIR" "$WWW_DIR"
15# Corrected yq command to read the key as the label
16yq -r '.repos | to_entries[] | .value."clone-url" + " " + .key' "$PGIT_CONFIG" |
17while read -r url label; do
18 dir="$REPOS_DIR/$label"
19 if [ "$dir" = ".." ]; then
20 continue
21 fi
22 if [ -d "$dir/.git" ]; then
23 wrn "Updating: $label"
24 (cd "$dir" && git pull --ff-only)
25 else
26 ok "Cloning: $label"
27 git clone --depth=1 "$url" "$dir"
28 fi
29done
30
31ok "Running pgit..."
32go run ../pgit.go --config "$PGIT_CONFIG"
33
34ok "Generating index.html..."
35{
36 printf '%s\n' '<!DOCTYPE html><meta charset="utf-8"><title>xplshn git</title>'
37 printf '<style>
38 body{font-family:sans-serif;max-width:700px;margin:auto;background:#fff;color:#000}
39 h1{border-bottom:1px solid #ccc}
40 a{color:#06c;text-decoration:none}
41 a:hover{text-decoration:underline}
42 ul{list-style:none;padding:0}
43 li{margin:0.5em 0}
44 p{margin:0;font-size:0.9em;color:#555}
45 </style>'
46 printf '<h1>git.xplshn.com.ar</h1><ul>'
47 yq -r '.repos | to_entries[] | .key + "|" + .value.desc' "$PGIT_CONFIG" |
48 while IFS='|' read -r label desc; do
49 printf '<li><a href="./%s/">%s</a><p>%s</p></li>\n' "$label" "$label" "$desc"
50 done
51 printf '</ul>'
52} > "$INDEX_FILE"
53
54ok "All done."