fix: 避免 remote_loader.sh 中重复定义 readonly 变量
## 问题描述
当脚本使用远程加载时,出现警告:
```
/tmp/tmp.xxx: line 10: REMOTE_BASE_URL: readonly variable
```
## 根本原因
`REMOTE_BASE_URL` 被重复定义为 readonly 变量:
1. 调用脚本中定义(如 oci/create_instance.sh:16):
```bash
readonly REMOTE_BASE_URL="..."
```
2. remote_loader.sh:10 中再次定义:
```bash
readonly REMOTE_BASE_URL="..."
```
Bash 不允许重新赋值 readonly 变量,即使值相同也会产生警告。
## 修复方案
在 remote_loader.sh 中添加检查,只有在变量未定义时才设置:
```bash
# 旧代码
readonly REMOTE_BASE_URL="..."
# 新代码
if [[ -z "${REMOTE_BASE_URL:-}" ]]; then
readonly REMOTE_BASE_URL="..."
fi
```
## 影响
- ✅ 消除警告信息
- ✅ 保持向后兼容
- ✅ 允许调用者自定义 REMOTE_BASE_URL
- ✅ 如果未定义则使用默认值
This commit is contained in:
@@ -6,8 +6,10 @@
|
||||
# 版本: 1.0.0
|
||||
# ============================================================================
|
||||
|
||||
# 远程仓库 URL 配置
|
||||
# 远程仓库 URL 配置(如果调用者未定义,则使用默认值)
|
||||
if [[ -z "${REMOTE_BASE_URL:-}" ]]; then
|
||||
readonly REMOTE_BASE_URL="${REMOTE_LIB_URL:-https://gitea.bcde.io/wangdefa/tools/raw/branch/main}"
|
||||
fi
|
||||
|
||||
# 临时目录用于存储下载的文件
|
||||
readonly REMOTE_TMP_DIR="$(mktemp -d)"
|
||||
|
||||
Reference in New Issue
Block a user