websoft9/scripts/githubclone.sh

33 lines
759 B
Bash
Raw Normal View History

#!/bin/bash
2023-04-17 04:00:19 +00:00
# 获取外部参数
USERNAME="$1"
REPO="$2"
2023-04-17 04:00:19 +00:00
# 生成仓库 URL
REPO_URL="https://github.com/$USERNAME/$REPO.git"
2023-04-17 04:00:19 +00:00
# 加速地址列表
MIRRORS=(
"https://github.com"
"https://github.com.cnpmjs.org"
"https://hub.fastgit.org"
"https://gitclone.com"
"https://gh.api.99988866.xyz"
"https://github.zhlh6.cn"
"https://toolwa.com/github"
)
for mirror in "${MIRRORS[@]}"; do
# 生成加速后的 URL
mirror_url="${REPO_URL/https:\/\/github.com/$mirror}"
# 尝试克隆仓库
for i in {1..3}; do
echo "Trying to clone from $mirror_url (attempt $i)"
2023-04-17 04:09:13 +00:00
if git clone --depth=1 "$mirror_url"; then
2023-04-17 04:00:19 +00:00
echo "Successfully cloned from $mirror_url"
exit 0
fi
done
done