From 9d4ccfa5f7073bac72461314441621808562860f Mon Sep 17 00:00:00 2001 From: Ge Yao Date: Sun, 24 May 2026 17:19:07 +0800 Subject: [PATCH 1/2] Add mirror-clone.sh wrapper for sjtug/mirror-clone Wrap sjtug/mirror-clone binary so multiple tunasync jobs can share one script. The wrapper exposes three layered environment variables: - TUNASYNC_MIRRORCLONE_OPTIONS: mirror-clone options before source - TUNASYNC_MIRRORCLONE_SOURCE: required source plugin name - TUNASYNC_MIRRORCLONE_ARGS: plugin-specific arguments This pattern is used by NJU mirror to drive ghcup, crates.io and other mirror-clone-based jobs from a single shared script. --- mirror-clone.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 mirror-clone.sh diff --git a/mirror-clone.sh b/mirror-clone.sh new file mode 100755 index 0000000..6e8b427 --- /dev/null +++ b/mirror-clone.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +TUNASYNC_MIRRORCLONE_OPTIONS=${TUNASYNC_MIRRORCLONE_OPTIONS:-} +TUNASYNC_MIRRORCLONE_SOURCE=${TUNASYNC_MIRRORCLONE_SOURCE:-} +TUNASYNC_MIRRORCLONE_ARGS=${TUNASYNC_MIRRORCLONE_ARGS:-} + +if [ -z "$TUNASYNC_MIRRORCLONE_SOURCE" ]; then + echo "Error: TUNASYNC_MIRRORCLONE_SOURCE is not set" >&2 + exit 1 +fi + +[ ! -d "${TUNASYNC_WORKING_DIR}" ] && mkdir -p "${TUNASYNC_WORKING_DIR}" +cd "${TUNASYNC_WORKING_DIR}" + +exec /home/mirror-clone \ + --target-type file \ + --file-buffer-path "${TUNASYNC_WORKING_DIR}/.tmp" \ + --file-base-path "${TUNASYNC_WORKING_DIR}" \ + $TUNASYNC_MIRRORCLONE_OPTIONS \ + "$TUNASYNC_MIRRORCLONE_SOURCE" \ + $TUNASYNC_MIRRORCLONE_ARGS From 59eedd5a50db145290b00a736f010d8ac7fd3036 Mon Sep 17 00:00:00 2001 From: Ge Yao Date: Sun, 24 May 2026 17:36:59 +0800 Subject: [PATCH 2/2] mirror-clone.sh: use _here-based binary lookup, add pipefail Follow the convention used by chef.sh/cvmfs.sh/bazel-apt.sh: locate the helper binary relative to the script directory (${_here}/mirror-clone) with an optional MIRRORCLONE_BIN override, instead of a hard-coded /home/mirror-clone path. Also switch from 'set -eu' to 'set -euo pipefail'. --- mirror-clone.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mirror-clone.sh b/mirror-clone.sh index 6e8b427..fce3684 100755 --- a/mirror-clone.sh +++ b/mirror-clone.sh @@ -1,6 +1,9 @@ #!/bin/bash -set -eu +set -euo pipefail + +_here=$(dirname "$(realpath "$0")") +mirror_clone="${MIRRORCLONE_BIN:-${_here}/mirror-clone}" TUNASYNC_MIRRORCLONE_OPTIONS=${TUNASYNC_MIRRORCLONE_OPTIONS:-} TUNASYNC_MIRRORCLONE_SOURCE=${TUNASYNC_MIRRORCLONE_SOURCE:-} @@ -14,7 +17,7 @@ fi [ ! -d "${TUNASYNC_WORKING_DIR}" ] && mkdir -p "${TUNASYNC_WORKING_DIR}" cd "${TUNASYNC_WORKING_DIR}" -exec /home/mirror-clone \ +exec "$mirror_clone" \ --target-type file \ --file-buffer-path "${TUNASYNC_WORKING_DIR}/.tmp" \ --file-base-path "${TUNASYNC_WORKING_DIR}" \