46 lines
1.4 KiB
Bash
46 lines
1.4 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
# 用法: ./scripts/bundle_install_retry.sh <gemfile_path> <bundle_path>
|
|||
|
|
# 例如: ./scripts/bundle_install_retry.sh android/Gemfile vendor/bundle_android
|
|||
|
|
|
|||
|
|
GEMFILE_PATH="$1"
|
|||
|
|
BUNDLE_PATH="$2"
|
|||
|
|
|
|||
|
|
if [ -z "$GEMFILE_PATH" ] || [ -z "$BUNDLE_PATH" ]; then
|
|||
|
|
echo "用法: $0 <gemfile_path> <bundle_path>"
|
|||
|
|
exit 1
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
try_count=0
|
|||
|
|
max_try=3
|
|||
|
|
success=0
|
|||
|
|
|
|||
|
|
# 先用阿里云镜像
|
|||
|
|
bundle config mirror.https://rubygems.org https://mirrors.aliyun.com/rubygems/
|
|||
|
|
while [ $try_count -lt $max_try ]; do
|
|||
|
|
echo "[INFO] 第$((try_count+1))次尝试使用阿里云镜像 bundle install..."
|
|||
|
|
bundle config set --local path "$BUNDLE_PATH"
|
|||
|
|
bundle install --gemfile "$GEMFILE_PATH"
|
|||
|
|
if [ $? -eq 0 ]; then
|
|||
|
|
echo "[SUCCESS] 使用阿里云镜像 bundle install 成功"
|
|||
|
|
success=1
|
|||
|
|
break
|
|||
|
|
fi
|
|||
|
|
try_count=$((try_count+1))
|
|||
|
|
sleep 2
|
|||
|
|
echo "[WARN] 阿里云镜像 bundle install 第$try_count 次失败,准备重试..."
|
|||
|
|
done
|
|||
|
|
|
|||
|
|
if [ $success -eq 0 ]; then
|
|||
|
|
echo "[ERROR] 阿里云镜像 bundle install 失败$max_try次,切换为官方源重试..."
|
|||
|
|
bundle config mirror.https://rubygems.org https://rubygems.org
|
|||
|
|
bundle config set --local path "$BUNDLE_PATH"
|
|||
|
|
bundle install --gemfile "$GEMFILE_PATH"
|
|||
|
|
if [ $? -eq 0 ]; then
|
|||
|
|
echo "[SUCCESS] 官方源 bundle install 成功"
|
|||
|
|
exit 0
|
|||
|
|
else
|
|||
|
|
echo "[FATAL] 官方源 bundle install 依然失败,请检查网络或Gemfile配置。"
|
|||
|
|
exit 2
|
|||
|
|
fi
|
|||
|
|
fi
|
|||
|
|
exit 0
|