Skip to content

Add mirror-clone.sh wrapper for sjtug/mirror-clone#200

Open
yaoge123 wants to merge 2 commits into
tuna:masterfrom
yaoge123:add-mirror-clone-sh
Open

Add mirror-clone.sh wrapper for sjtug/mirror-clone#200
yaoge123 wants to merge 2 commits into
tuna:masterfrom
yaoge123:add-mirror-clone-sh

Conversation

@yaoge123
Copy link
Copy Markdown
Contributor

@yaoge123 yaoge123 commented May 24, 2026

Summary

Add a generic shell wrapper for the sjtug/mirror-clone binary so multiple tunasync jobs can share one script.

Why

mirror-clone supports many source plugins (ghcup, crates.io, GitHub releases, …). Today each tunasync job using mirror-clone has to write its own short shell file, which is mostly boilerplate (resolve TUNASYNC_WORKING_DIR, set --target-type file, choose source). This wrapper centralises that boilerplate so each tunasync .conf only sets a few env vars.

Interface

Three layered environment variables:

Variable Required Purpose
TUNASYNC_MIRRORCLONE_OPTIONS No mirror-clone options that come before the source plugin name
TUNASYNC_MIRRORCLONE_SOURCE Yes source plugin name (e.g. ghcup, crates-io)
TUNASYNC_MIRRORCLONE_ARGS No plugin-specific arguments after the source plugin

The wrapper assumes the mirror-clone binary is mounted at /home/mirror-clone inside the container, matching the existing pattern of bind-mounting the binary into tunathu/tunasync-scripts:latest.

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.
Copilot AI review requested due to automatic review settings May 24, 2026 09:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a mirror-clone.sh wrapper script to run mirror-clone in a tunasync working directory, driven by environment variables.

Changes:

  • Introduces a bash entrypoint that validates TUNASYNC_MIRRORCLONE_SOURCE and runs mirror-clone via exec
  • Uses TUNASYNC_WORKING_DIR as the working directory and configures file buffer/base paths under it

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mirror-clone.sh
Comment on lines +14 to +15
[ ! -d "${TUNASYNC_WORKING_DIR}" ] && mkdir -p "${TUNASYNC_WORKING_DIR}"
cd "${TUNASYNC_WORKING_DIR}"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the convention used by other scripts in this repo (chef.sh/cvmfs.sh/termux.sh) — they all dereference TUNASYNC_WORKING_DIR directly and rely on the tunasync framework to set it. Keeping consistent with that.

Comment thread mirror-clone.sh
Comment on lines +21 to +23
$TUNASYNC_MIRRORCLONE_OPTIONS \
"$TUNASYNC_MIRRORCLONE_SOURCE" \
$TUNASYNC_MIRRORCLONE_ARGS
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unquoted expansion is intentional: it lets per-mirror configs pass multiple positional flags through TUNASYNC_MIRRORCLONE_OPTIONS / TUNASYNC_MIRRORCLONE_ARGS. Switching to bash arrays would change the public interface (existing tunasync mirror configs would have to be rewritten). Keeping current behavior.

Comment thread mirror-clone.sh Outdated
[ ! -d "${TUNASYNC_WORKING_DIR}" ] && mkdir -p "${TUNASYNC_WORKING_DIR}"
cd "${TUNASYNC_WORKING_DIR}"

exec /home/mirror-clone \
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed the convention from chef.sh/cvmfs.sh/bazel-apt.sh: now locates the binary as ${_here}/mirror-clone with optional MIRRORCLONE_BIN override. No more hard-coded /home/mirror-clone.

Comment thread mirror-clone.sh Outdated
@@ -0,0 +1,23 @@
#!/bin/bash

set -eu
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Switched from set -eu to set -euo 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'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants