sync build tree from private myoffice

This commit is contained in:
myoffice-sync
2026-08-05 11:31:19 +00:00
parent 405abdfe69
commit afa4c42105
60 changed files with 249 additions and 2400 deletions
+130 -85
View File
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
# Sync full source from the private repo to the public Gitea repo (manual build + Proxmox scripts).
# Sync buildable source + Proxmox scripts to the public Gitea repo.
# Allowlist: .publishinclude | Skips: Docker, .gitignore, *.bat, tests, docs, CI, junk
#
# Usage:
# export GITEA_TOKEN='<token>'
# ./proxmox/sync-public.sh --gitea-url https://gitea.example.com --owner org --repo myoffice-public --push
#
# Copies tracked git files (plus generates public README.md). Skips private CI, secrets, build junk.
# ./proxmox/sync-public.sh --gitea-url https://gitea.example.com --owner org --repo myoffice_public --push
set -euo pipefail
@@ -19,6 +19,7 @@ branch="${BRANCH:-master}"
token="${GITEA_TOKEN:-}"
work_dir="${WORK_DIR:-}"
do_push=false
include_file="$repo_root/.publishinclude"
usage() {
echo "Usage: $0 --gitea-url URL --owner OWNER [--repo REPO] [--branch BRANCH] [--push]" >&2
@@ -27,73 +28,69 @@ usage() {
while [[ $# -gt 0 ]]; do
case "$1" in
--gitea-url)
gitea_url="$2"
shift 2
;;
--owner)
owner="$2"
shift 2
;;
--repo)
repo="$2"
shift 2
;;
--branch)
branch="$2"
shift 2
;;
--work-dir)
work_dir="$2"
shift 2
;;
--push)
do_push=true
shift
;;
-h | --help)
usage
;;
*)
echo "Unknown argument: $1" >&2
usage
;;
--gitea-url) gitea_url="$2"; shift 2 ;;
--owner) owner="$2"; shift 2 ;;
--repo) repo="$2"; shift 2 ;;
--branch) branch="$2"; shift 2 ;;
--work-dir) work_dir="$2"; shift 2 ;;
--push) do_push=true; shift ;;
-h|--help) usage ;;
*) echo "Unknown argument: $1" >&2; usage ;;
esac
done
if [[ -z "$gitea_url" || -z "$owner" ]]; then
usage
fi
[[ -n "$gitea_url" && -n "$owner" ]] || usage
[[ -f "$include_file" ]] || { echo "Missing $include_file" >&2; exit 1; }
gitea_url="${gitea_url%/}"
[[ -n "$work_dir" ]] || work_dir="${TMPDIR:-/tmp}/myoffice-public-sync"
if [[ -z "$work_dir" ]]; then
work_dir="${TMPDIR:-/tmp}/myoffice-public-sync"
fi
# Paths never published (private CI, secrets, local junk).
should_skip() {
# Relative path should not be copied into public tree.
should_skip_rel() {
local f="$1"
case "$f" in
.gitea | .gitea/*) return 0 ;;
_Published | _Published/*) return 0 ;;
myoffice-publish.tar.gz) return 0 ;;
Docker/data | Docker/data/*) return 0 ;;
.env | .env.* | env.local) return 0 ;;
*.user | *.suo) return 0 ;;
proxmox/README.public.md) return 0 ;; # baked into public README.md
*) return 1 ;;
esac
local base
base="$(basename "$f")"
# User / policy excludes
[[ "$f" == Docker || "$f" == Docker/* ]] && return 0
[[ "$base" == .gitignore ]] && return 0
[[ "$base" == *.bat ]] && return 0
# Not required to build or install CT
[[ "$f" == MyOffice.Tests || "$f" == MyOffice.Tests/* ]] && return 0
[[ "$f" == docs || "$f" == docs/* ]] && return 0
[[ "$f" == .gitea || "$f" == .gitea/* ]] && return 0
[[ "$base" == .dockerignore ]] && return 0
[[ "$base" == gulpfile.js ]] && return 0
[[ "$base" == build.ps1 ]] && return 0
[[ "$base" == linux_deploy.sh ]] && return 0
[[ "$f" == proxmox/README.public.md ]] && return 0
# Build junk / secrets / Docker-only appsettings
[[ "$base" == node_modules || "$f" == */node_modules/* ]] && return 0
[[ "$base" == bin || "$f" == */bin/* ]] && return 0
[[ "$base" == obj || "$f" == */obj/* ]] && return 0
[[ "$base" == .angular || "$f" == */.angular/* ]] && return 0
[[ "$base" == _Published || "$f" == _Published/* ]] && return 0
[[ "$base" == myoffice-publish.tar.gz ]] && return 0
[[ "$base" == .env || "$base" == env.local || "$base" == .env.* ]] && return 0
[[ "$base" == appsettings.Docker.json ]] && return 0
[[ "$base" == appsettings.shared.Docker.json ]] && return 0
[[ "$base" == environment.docker.ts ]] && return 0
[[ "$base" == *.user || "$base" == *.suo ]] && return 0
# SPA unit-test harness (not used by ng build --configuration proxmox)
[[ "$base" == karma.conf.js ]] && return 0
[[ "$base" == *.spec.ts ]] && return 0
return 1
}
if [[ -n "$token" ]]; then
host_part="${gitea_url#https://}"
host_part="${host_part#http://}"
if [[ "$gitea_url" == http://* ]]; then
scheme=http
else
scheme=https
fi
scheme=https
[[ "$gitea_url" == http://* ]] && scheme=http
remote="${scheme}://oauth2:${token}@${host_part}/${owner}/${repo}.git"
else
remote="${gitea_url}/${owner}/${repo}.git"
@@ -101,16 +98,14 @@ else
fi
echo "-----------------------------------------------"
echo "Sync full source -> $owner/$repo ($branch)"
echo "Sync allowlist (.publishinclude) -> $owner/$repo ($branch)"
echo "WorkDir: $work_dir"
echo "-----------------------------------------------"
rm -rf "$work_dir"
mkdir -p "$work_dir"
if git clone --depth 1 --branch "$branch" "$remote" "$work_dir" 2>/dev/null; then
:
else
if ! git clone --depth 1 --branch "$branch" "$remote" "$work_dir" 2>/dev/null; then
echo "Clone failed or empty repo — initializing new git repo..."
git -C "$work_dir" init -b "$branch" 2>/dev/null || {
git -C "$work_dir" init
@@ -124,29 +119,66 @@ find "$work_dir" -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
copied=0
skipped=0
while IFS= read -r -d '' f; do
if should_skip "$f"; then
skipped=$((skipped + 1))
continue
fi
src="$repo_root/$f"
if [[ ! -e "$src" ]]; then
continue
fi
dest="$work_dir/$f"
mkdir -p "$(dirname "$dest")"
cp -a "$src" "$dest"
copied=$((copied + 1))
done < <(git -C "$repo_root" ls-files -z)
echo "Copied $copied tracked files (skipped $skipped)."
copy_tracked_under() {
local prefix="$1" # '' for file, or 'Dir/'
while IFS= read -r -d '' f; do
if [[ -n "$prefix" ]]; then
[[ "$f" == "$prefix"* ]] || continue
else
[[ "$f" == "$2" ]] || continue
fi
if should_skip_rel "$f"; then
skipped=$((skipped + 1))
continue
fi
src="$repo_root/$f"
[[ -e "$src" ]] || continue
dest="$work_dir/$f"
mkdir -p "$(dirname "$dest")"
cp -a "$src" "$dest"
copied=$((copied + 1))
done < <(git -C "$repo_root" ls-files -z)
}
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line%%#*}"
line="$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
[[ -z "$line" ]] && continue
src="$repo_root/$line"
if [[ "$line" == */ ]]; then
dir="${line%/}"
if [[ ! -d "$repo_root/$dir" ]]; then
echo "Skip missing dir: $dir"
continue
fi
copy_tracked_under "${dir}/"
echo "Synced $dir/"
else
if [[ ! -e "$src" ]]; then
echo "Skip missing file: $line"
continue
fi
if should_skip_rel "$line"; then
skipped=$((skipped + 1))
echo "Skip excluded: $line"
continue
fi
# Only copy if tracked (or exists — LICENSE etc.)
dest="$work_dir/$line"
mkdir -p "$(dirname "$dest")"
cp -a "$src" "$dest"
copied=$((copied + 1))
echo "Synced $line"
fi
done < "$include_file"
echo "Copied $copied files (skipped $skipped)."
repo_raw_base="${gitea_url}/${owner}/${repo}/raw/branch/${branch}"
readme_template="$script_dir/README.public.md"
if [[ ! -f "$readme_template" ]]; then
echo "Missing $readme_template" >&2
exit 1
fi
[[ -f "$readme_template" ]] || { echo "Missing $readme_template" >&2; exit 1; }
sed \
-e "s|__GITEA_URL__|${gitea_url}|g" \
-e "s|__GITEA_OWNER__|${owner}|g" \
@@ -156,15 +188,28 @@ sed \
"$readme_template" >"$work_dir/README.md"
echo "Wrote public README.md"
# Drop private-only docs that confuse public consumers (optional keep docs/)
# Keep docs/ — useful for auth notes.
# Public consumers need a minimal .gitignore so git status stays clean after npm/dotnet restore
cat >"$work_dir/.gitignore" <<'EOF'
**/bin/
**/obj/
**/node_modules/
**/.angular/
_Published/
myoffice-publish.tar.gz
*.user
.env
env.local
MyOffice.SPA/src/environments/environment.ts
MyOffice.Shared/appsettings.shared.Development.json
MyOffice.Shared/appsettings.shared.Production.json
EOF
git -C "$work_dir" add -A
if [[ -z "$(git -C "$work_dir" status --porcelain)" ]]; then
echo "No changes to commit."
else
git -C "$work_dir" -c user.email='myoffice-sync@local' -c user.name='myoffice-sync' \
commit -m "sync full source from private myoffice"
commit -m "sync build tree from private myoffice"
echo "Committed public snapshot."
fi