2
2
# -*- coding: utf-8 -*-
3
3
4
4
# Axvisor Bootstrap Script
5
- # 此脚本用于创建 Python 虚拟环境并安装 task.py 所需的依赖
5
+ # This script creates a Python virtual environment and installs task.py dependencies
6
6
7
- set -e # 遇到错误时退出
7
+ set -e # Exit on error
8
8
9
- # 颜色输出
9
+ # Colored output
10
10
RED=' \033[0;31m'
11
11
GREEN=' \033[0;32m'
12
12
YELLOW=' \033[1;33m'
13
13
BLUE=' \033[0;34m'
14
14
NC=' \033[0m' # No Color
15
15
16
- # 输出函数
16
+ # Output helpers
17
17
info () { echo -e " ${BLUE} ℹ${NC} $1 " ; }
18
18
success () { echo -e " ${GREEN} ✓${NC} $1 " ; }
19
19
warning () { echo -e " ${YELLOW} ⚠${NC} $1 " ; }
20
20
error () { echo -e " ${RED} ✗${NC} $1 " ; }
21
21
22
- # 获取项目根目录
22
+ # Get project root directory
23
23
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
24
24
PROJECT_ROOT=" $( cd " $SCRIPT_DIR /.." && pwd) "
25
25
cd " $PROJECT_ROOT "
26
26
27
- # 检查是否已经在虚拟环境中
27
+ # If already inside a virtual environment, just update deps
28
28
if [[ -n " $VIRTUAL_ENV " ]]; then
29
- info " 检测到已在虚拟环境中 : $VIRTUAL_ENV "
29
+ info " Detected active virtual environment : $VIRTUAL_ENV "
30
30
31
- # 检查 requirements.txt 文件是否存在
31
+ # Ensure requirements.txt exists
32
32
if [[ ! -f " scripts/requirements.txt" ]]; then
33
- error " scripts/requirements.txt 文件未找到 "
33
+ error " scripts/requirements.txt not found "
34
34
exit 1
35
35
fi
36
36
37
- # 安装/更新依赖
38
- info " 更新 Python 依赖 ..."
37
+ # Install / update dependencies
38
+ info " Updating Python dependencies ..."
39
39
pip install -q -r scripts/requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
40
- success " 依赖更新完成 "
40
+ success " Dependencies updated "
41
41
exit 0
42
42
fi
43
43
44
- # 虚拟环境和标记文件
44
+ # Virtual environment and marker file
45
45
VENV_DIR=" venv"
46
46
MARKER_FILE=" $VENV_DIR /.bootstrapped"
47
47
REQUIREMENTS_FILE=" scripts/requirements.txt"
48
48
49
- # 计算依赖哈希值
49
+ # Compute dependency hash
50
50
compute_dep_hash () {
51
51
local pyver
52
52
pyver=$( python3 --version 2> /dev/null || echo " unknown" )
@@ -60,128 +60,128 @@ compute_dep_hash() {
60
60
fi
61
61
}
62
62
63
- # 检查是否需要重新引导
63
+ # Decide if bootstrap is needed
64
64
check_bootstrap_needed () {
65
- # 如果虚拟环境不存在,需要引导
65
+ # Need bootstrap if venv directory missing
66
66
if [[ ! -d " $VENV_DIR " ]]; then
67
- return 0 # 需要引导
67
+ return 0 # need bootstrap
68
68
fi
69
69
70
- # 如果标记文件不存在,需要引导
70
+ # Need bootstrap if marker file missing
71
71
if [[ ! -f " $MARKER_FILE " ]]; then
72
- return 0 # 需要引导
72
+ return 0 # need bootstrap
73
73
fi
74
74
75
- # 检查哈希值是否匹配
75
+ # Check dependency hash
76
76
local existing_hash current_hash
77
77
existing_hash=$( awk -F" :" ' /^hash:/ {print $2}' " $MARKER_FILE " 2> /dev/null | tr -d ' [:space:]' ) || existing_hash=" "
78
78
current_hash=$( compute_dep_hash)
79
79
80
80
if [[ " $existing_hash " != " $current_hash " ]]; then
81
- info " 检测到依赖变更,需要重新引导 "
82
- return 0 # 需要引导
81
+ info " Dependency changes detected, re-bootstrap required "
82
+ return 0 # need bootstrap
83
83
fi
84
84
85
- # 检查虚拟环境的Python是否可用
85
+ # Ensure python executable exists in venv
86
86
if [[ ! -x " $VENV_DIR /bin/python3" ]]; then
87
- warning " 虚拟环境的 Python 不可用,需要重新引导 "
88
- return 0 # 需要引导
87
+ warning " Python in virtual env not available, re-bootstrap required "
88
+ return 0 # need bootstrap
89
89
fi
90
90
91
- return 1 # 不需要引导
91
+ return 1 # bootstrap not needed
92
92
}
93
- # 快速检查并退出
93
+ # Fast path: already bootstrapped
94
94
if ! check_bootstrap_needed; then
95
- success " 引导已完成且依赖未更改,跳过引导 "
95
+ success " Bootstrap already done and dependencies unchanged, skipping "
96
96
exit 0
97
97
fi
98
98
99
- info " 开始设置 Python 虚拟环境 ..."
99
+ info " Starting Python virtual environment setup ..."
100
100
101
- # 检查系统依赖
101
+ # Check system dependencies
102
102
check_system_deps () {
103
- info " 检查系统依赖 ..."
103
+ info " Checking system dependencies ..."
104
104
105
- # 检查 Python 3
105
+ # Check python3 exists
106
106
if ! command -v python3 > /dev/null 2>&1 ; then
107
- error " python3 未找到,请先安装 Python 3"
107
+ error " python3 not found. Please install Python 3"
108
108
exit 1
109
109
fi
110
110
111
- # 检查 Python 版本
111
+ # Report Python version
112
112
local pyver
113
113
pyver=$( python3 --version 2>&1 | awk ' {print $2}' | cut -d. -f1,2)
114
- info " 检测到 Python 版本 : $pyver "
114
+ info " Detected Python version : $pyver "
115
115
116
- # 检查 venv 模块
116
+ # Check venv module
117
117
if ! python3 -c " import venv" 2> /dev/null; then
118
- error " python3-venv 模块未找到 "
119
- echo " 请安装 python3-venv:"
120
- echo " Ubuntu/Debian: sudo apt install python3-venv"
121
- echo " CentOS/RHEL: sudo yum install python3-venv"
122
- echo " Fedora: sudo dnf install python3-venv"
118
+ error " python3-venv module not found "
119
+ echo " Install python3-venv via your package manager :"
120
+ echo " Ubuntu/Debian: sudo apt install python3-venv"
121
+ echo " CentOS/RHEL: sudo yum install python3-venv"
122
+ echo " Fedora: sudo dnf install python3-venv"
123
123
exit 1
124
124
fi
125
125
126
- # 检查 requirements.txt
126
+ # Check requirements.txt exists
127
127
if [[ ! -f " $REQUIREMENTS_FILE " ]]; then
128
- error " $REQUIREMENTS_FILE 文件未找到 "
128
+ error " $REQUIREMENTS_FILE not found "
129
129
exit 1
130
130
fi
131
131
132
- success " 系统依赖检查完成 "
132
+ success " System dependency check passed "
133
133
}
134
134
135
- # 创建虚拟环境
135
+ # Create virtual environment
136
136
setup_venv () {
137
- info " 设置虚拟环境 ..."
137
+ info " Preparing virtual environment ..."
138
138
139
- # 如果虚拟环境已存在但损坏,删除它
139
+ # Remove broken venv
140
140
if [[ -d " $VENV_DIR " ]] && [[ ! -x " $VENV_DIR /bin/python3" ]]; then
141
- warning " 检测到损坏的虚拟环境,正在删除 ..."
141
+ warning " Corrupted virtual environment detected, removing ..."
142
142
rm -rf " $VENV_DIR "
143
143
fi
144
144
145
- # 创建虚拟环境
145
+ # Create venv if missing
146
146
if [[ ! -d " $VENV_DIR " ]]; then
147
- info " 创建新的虚拟环境 ..."
147
+ info " Creating new virtual environment ..."
148
148
python3 -m venv " $VENV_DIR "
149
- success " 虚拟环境已创建 "
149
+ success " Virtual environment created "
150
150
else
151
- info " 使用现有虚拟环境 "
151
+ info " Using existing virtual environment "
152
152
fi
153
153
}
154
154
155
- # 安装依赖
155
+ # Install dependencies
156
156
install_deps () {
157
- info " 安装 Python 依赖 ..."
157
+ info " Installing Python dependencies ..."
158
158
159
159
# 激活虚拟环境
160
160
source " $VENV_DIR /bin/activate"
161
161
162
- # 升级 pip(静默)
162
+ # Upgrade pip (quiet)
163
163
python -m pip install -q --upgrade pip -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
164
164
165
- # 安装依赖
165
+ # Install requirements
166
166
pip install -q -r " $REQUIREMENTS_FILE " -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
167
167
168
- success " 依赖安装完成 "
168
+ success " Dependencies installed "
169
169
}
170
170
171
- # 验证安装
171
+ # Verify installation
172
172
verify_installation () {
173
- info " 验证安装 ..."
173
+ info " Verifying installation ..."
174
174
175
175
# 测试 task.py
176
176
if source " $VENV_DIR /bin/activate" && python3 ./scripts/task.py --help > /dev/null 2>&1 ; then
177
- success " task.py 运行正常 "
177
+ success " task.py runs correctly "
178
178
else
179
- error " task.py 运行失败 "
179
+ error " task.py execution failed "
180
180
exit 1
181
181
fi
182
182
}
183
183
184
- # 写入完成标记
184
+ # Write completion marker
185
185
write_marker () {
186
186
local dep_hash
187
187
dep_hash=$( compute_dep_hash)
@@ -192,21 +192,21 @@ timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
192
192
python_version: $( python3 --version)
193
193
EOF
194
194
195
- success " 引导完成标记已写入 (hash: ${dep_hash: 0: 8} ...)"
195
+ success " Bootstrap marker written (hash: ${dep_hash: 0: 8} ...)"
196
196
}
197
197
198
- # 主要执行流程
198
+ # Main execution flow
199
199
main () {
200
200
check_system_deps
201
201
setup_venv
202
202
install_deps
203
203
verify_installation
204
204
write_marker
205
205
206
- success " 虚拟环境设置完成! "
207
- info " 使用 ' source venv/bin/activate' 激活环境 "
208
- info " 使用 'make help' 查看可用命令 "
206
+ success " Virtual environment setup complete! "
207
+ info " Activate with: source venv/bin/activate"
208
+ info " Use 'make help' to see available commands "
209
209
}
210
210
211
- # 执行主函数
211
+ # Execute main function
212
212
main " $@ "
0 commit comments