#!/usr/bin/env bash set -euo pipefail set -x export PATH="/usr/bin:/bin:/usr/local/bin" unset IFS unset PYTHONPATH unset PYTHONHOME unset HTTP_PROXY unset HTTPS_PROXY main() { local org_name local repo_name local course org_name=$(basename "$(dirname "$(pwd)")") repo_name=$(basename "$(pwd)") course=${repo_name%-*} if ! [[ "$course" =~ ^[a-zA-Z0-9_-]+$ ]]; then echo "FATAL: Invalid course name: $course" >&2 exit 1 fi local config_repo_path="/home/tt/.cache/$course-config" local grading_repo_path="/home/tt/.cache/$course-joj" local git_user="bot-$course" local git_email="bot-$course@focs.ji.sjtu.edu.cn" local git_server="ssh://git@focs.ji.sjtu.edu.cn:2222" if ! [ -d "$config_repo_path" ]; then git clone "$git_server/$course/$course-joj.git" "$config_repo_path" git -C "$config_repo_path" config user.name "$git_user" git -C "$config_repo_path" config user.email "$git_email" fi if ! [ -d "$grading_repo_path" ]; then git clone "$git_server/$course/$course-joj.git" "$grading_repo_path" git -C "$grading_repo_path" config user.name "$git_user" git -C "$grading_repo_path" config user.email "$git_email" git -C "$grading_repo_path" switch --orphan grading cat >"$grading_repo_path/Readme.md" <&2 exit 1 fi rsync -a "$config_repo_path/home/tt/.ssh/" "/home/tt/.ssh" rsync -a --delete "$config_repo_path/home/tt/.config/" "/home/tt/.config" joj3-forge convert "/home/tt/.config/joj" rsync -a --delete "/home/tt/.config/joj/" "$config_repo_path/home/tt/.config/joj" git -C "$config_repo_path" add home/tt/.config/joj if ! git -C "$config_repo_path" diff --staged --quiet; then commit_hash=$(git -C "$config_repo_path" rev-parse HEAD) git -C "$config_repo_path" commit -m "chore: $commit_hash trigger joj3-forge convert [skip ci]" git -C "$config_repo_path" push fi if [ -n "${TEAPOT_GITEA_TOKEN:-}" ]; then local teapot_config_dir="/home/tt/.config/teapot" mkdir -p "$teapot_config_dir" cat >"$teapot_config_dir/teapot.env" <&2 exit 1 fi else echo "FATAL: TEAPOT_GITEA_TOKEN not set, ask admin to set it" >&2 exit 1 fi } main "$@"