使用chatgpt gemini配置的几个软件源脚本,现在分享一下:
这是alpine的脚本,我的配置是基于飞牛的:
#!/bin/bash
set -euo pipefail
# 📁 镜像根路径
MIRROR_DIR="/vol2/1000/maqafnos/mirror/alpine"
LOG_FILE="/home/maqa588/log/alpine-mirror-sync.log"
LOCK_FILE="/tmp/alpine-mirror-sync.lock"
# 🧩 同步版本与架构
VERSIONS="v3.22"
ARCHS="x86_64 aarch64"
REPOS="main community"
# 🌐 USTC Alpine 镜像路径
REMOTE="rsync://rsync.mirrors.ustc.edu.cn/alpine"
# ⚙️ rsync 参数(包含限速 50 MiB/s = 51200 KB/s)
RSYNC_OPTS="-a --update --hard-links --delete --delete-after \
--delay-updates --timeout=600 --bwlimit=51200"
log() {
echo "$(date '+%F %T') - $*" | tee -a "${LOG_FILE}"
}
run_rsync() {
local src="$1" dst="$2"
log "同步 ${src} → ${dst}"
rsync ${RSYNC_OPTS} "${src}" "${dst}"
}
main() {
exec 200>"${LOCK_FILE}"
flock -n 200 || { log "已有同步任务运行中,退出"; exit 1; }
for version in ${VERSIONS}; do
for arch in ${ARCHS}; do
for repo in ${REPOS}; do
SRC="${REMOTE}/${version}/${repo}/${arch}/"
DST="${MIRROR_DIR}/${version}/${repo}/${arch}/"
mkdir -p "${DST}"
run_rsync "${SRC}" "${DST}"
done
done
done
log "=== Alpine ${VERSION} (${ARCHS}) 镜像同步完成 ==="
}
main
这是debian:
#!/bin/bash
set -euo pipefail
BASE_DIR="/vol2/1000/maqafnos/mirror"
TARGET="bookworm"
SEC_DIR="bookworm-security"
DISTS="bookworm,bookworm-updates,bookworm-backports"
ARCH="arm64,amd64,i386"
COMP="main,contrib,non-free,non-free-firmware"
SERVER="rsync.mirrors.ustc.edu.cn"
RATE_LIMIT_KBS="6400"
KEYRING="$HOME/.gnupg/pubring.kbx"
RSYNC_OPTS="-aIL --partial --bwlimit=${RATE_LIMIT_KBS}"
log() { echo "[$(date '+%F %T')] $*"; }
sync_main() {
mkdir -p "${BASE_DIR}/${TARGET}"
log "同步 ${DISTS} → ${TARGET}/"
debmirror \
--host="${SERVER}" --root="/debian" \
--method=rsync --dist="${DISTS}" \
--section="${COMP}" --arch="${ARCH}" \
--nocleanup --i18n \
--verbose --progress \
--rsync-options="${RSYNC_OPTS}" \
--keyring="${KEYRING}" \
"${BASE_DIR}/${TARGET}"
}
sync_security() {
mkdir -p "${BASE_DIR}/${SEC_DIR}"
log "同步 ${SEC_DIR}/"
debmirror \
--host="${SERVER}" --root="/debian-security" \
--method=rsync --dist="${SEC_DIR}" \
--section="${COMP}" --arch="${ARCH}" \
--nocleanup --i18n \
--verbose --progress \
--rsync-options="${RSYNC_OPTS}" \
--keyring="${KEYRING}" \
"${BASE_DIR}/${SEC_DIR}"
}
sync_main
sync_security
log "✅ 全部同步完成"