Skip to content

Commit 9f2567f

Browse files
committed
feat: 整合安装脚本到 tools 目录
- 将安装脚本统一移动到 tools 目录 - 更新 README 文档 - 优化 env.sh 和 env.py 中的 ENV_ROOT 默认值 - 支持 Windows PowerShell 安装脚本 - 添加 touch_env.py 工具
1 parent 3a2f4a3 commit 9f2567f

19 files changed

Lines changed: 5591 additions & 503 deletions

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
*.md text eol=crlf
3030

3131
*.bat text eol=crlf
32-
*.ps1 text eol=crlf
32+
*.ps1 text eol=crlf encoding=UTF-8-BOM
33+
*.sh text eol=lf

README.md

Lines changed: 259 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,297 @@
11
# Python Scripts for RT-Thread Env
22

3-
> WARNING
4-
>
5-
> [env v2.0](https://github.com/RT-Thread/env/tree/master) and [env-windows v2.0](https://github.com/RT-Thread/env-windows/tree/v2.0.0) only **FULL SUPPORT** RT-Thread > v5.1.0 or [master](https://github.com/rt-thread/rt-thread) branch. if you work on RT-Thread <= v5.1.0, please use [env v1.5.x](https://github.com/RT-Thread/env/tree/v1.5.x) for linux, [env-windows v1.5.x](https://github.com/RT-Thread/env-windows/tree/v1.5.2) for windows
3+
**[中文文档](README_ZH.md)**
4+
5+
> **⚠️ Important Notice**
6+
>
7+
> [env v2.0](https://github.com/RT-Thread/env/tree/master) and [env-windows v2.0](https://github.com/RT-Thread/env-windows/tree/v2.0.0) only **fully support** RT-Thread > v5.1.0 or the [master](https://github.com/rt-thread/rt-thread) branch. If you are using RT-Thread <= v5.1.0, please use [env v1.5.x](https://github.com/RT-Thread/env/tree/v1.5.x) (for Linux) or [env-windows v1.5.2](https://github.com/RT-Thread/env-windows/tree/v1.5.2) (for Windows).
68
>
7-
> env v2.0 has made the following important changes:
8-
> - Upgrading Python version from v2 to v3
9-
> - Replacing kconfig-frontends with Python kconfiglib
9+
> **Key Changes in v2.0:**
10+
> - Upgraded Python version from v2 to v3
11+
> - Replaced kconfig-frontends with Python kconfiglib
1012
>
11-
> env v2.0 require python kconfiglib (install by `pip install kconfiglib`), but env v1.5.x confilt with kconfiglib (please run `pip uninstall kconfiglib`)
13+
> **Note:** env v2.0 requires Python kconfiglib (now automatically installed by the installer), but env v1.5.x conflicts with kconfiglib (please run `pip uninstall kconfiglib`).
1214
13-
## Usage under Linux
15+
---
1416

15-
### Tutorial
17+
## Table of Contents
1618

17-
[How to install Env Tool with QEMU simulator in Ubuntu](https://github.com/RT-Thread/rt-thread/blob/master/documentation/quick-start/quick_start_qemu/quick_start_qemu_linux.md)
19+
- [Windows Installation Guide](#windows-installation-guide)
20+
- [Install Env](#install-env)
21+
- [Activate Environment](#activate-rt-thread-env)
22+
- [Linux/macOS Installation Guide](#linuxmacos-installation-guide)
23+
- [Install Env](#install-env-1)
24+
- [Activate Environment](#activate-rt-thread-env-1)
25+
- [Installation Script Parameters](#installation-script-parameters)
26+
- [Env Usage Guide](#env-usage-guide)
27+
- [Troubleshooting](#troubleshooting)
28+
- [Related Documents](#related-documents)
29+
- [License](#license)
30+
- [Related Links](#related-links)
31+
32+
---
33+
34+
## Windows Installation Guide
1835

1936
### Install Env
2037

38+
**Prerequisites:**
39+
- First-time installation requires administrator privileges (to set script execution policy and enable long path support)
40+
- Subsequent updates can use normal user privileges
41+
42+
**Supported PowerShell Versions:**
43+
- Windows PowerShell (PowerShell v5.1 and above)
44+
- PowerShell 7+ (cross-platform version)
45+
46+
**Important Compatibility Notice:**
47+
48+
> ⚠️ **PowerShell Encoding Compatibility**
49+
>
50+
> - **Windows PowerShell**: On Chinese Windows systems, the default encoding is GB2312. Downloaded .ps1 scripts are typically UTF-8 encoded, but Windows PowerShell does not support UTF-8 files without BOM. It can only read UTF-8 with BOM encoded files.
51+
>
52+
> - **PowerShell 7+**: Native UTF-8 support, no encoding issues.
53+
>
54+
> Installation scripts are configured as UTF-8 with BOM encoding to ensure compatibility.
55+
56+
**Windows Installation Command:**
57+
58+
```powershell
59+
Set-ExecutionPolicy -ExecutionPolicy Bypass Process; irm https://raw.githubusercontent.com/RT-Thread/env/master/tools/install.ps1 | Out-File -Encoding utf8 .\install.ps1; .\install.ps1; Remove-Item .\install.ps1
2160
```
22-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh
23-
chmod 777 install_ubuntu.sh
24-
./install_ubuntu.sh
25-
rm install_ubuntu.sh
61+
62+
For users in China (optional):
63+
64+
```powershell
65+
Set-ExecutionPolicy -ExecutionPolicy Bypass Process; irm https://gitee.com/RT-Thread-Mirror/env/raw/master/tools/install.ps1 | Out-File -Encoding utf8 .\install.ps1; .\install.ps1; Remove-Item .\install.ps1
2666
```
2767

28-
对于中国大陆用户,请使用以下命令
68+
**Notes:**
69+
- Installation script automatically selects mirror sources based on geographic location (can be specified using `--cn` or `--official` parameters)
70+
- First-time installation requires administrator privileges
71+
72+
For complete parameter descriptions, see [Installation Script Parameters](#installation-script-parameters).
73+
74+
**Important Tips:**
75+
76+
1. ✅ Installation script requires administrator privileges for script execution policy and long path support settings
77+
2. ⚠️ When running without administrator privileges, if the above settings are required, it will prompt and exit
78+
3. 🦠 Antivirus software may block installation, please temporarily disable if needed
79+
80+
### Activate RT-Thread ENV
81+
82+
After installation, you need to activate the environment variables.
2983

84+
**Option A: Manual Activation Each Time**
85+
86+
Run the following command each time you start a new PowerShell session:
87+
88+
```powershell
89+
~/.rt-env/env.ps1
3090
```
31-
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh
32-
chmod 777 install_ubuntu.sh
33-
./install_ubuntu.sh --gitee
34-
rm install_ubuntu.sh
91+
92+
**Option B: Auto Activation on Startup (Recommended)**
93+
94+
Create or edit a PowerShell configuration file to automatically activate the environment:
95+
96+
```powershell
97+
# Open configuration file (creates if it doesn't exist)
98+
notepad $PROFILE
99+
100+
# Add the following line to the file:
101+
~/.rt-env/env.ps1
35102
```
36103

37-
### Prepare Env
104+
**Configuration File Paths:**
38105

39-
PLAN A: Whenever start the ubuntu system, you need to type command `source ~/.env/env.sh` to activate the environment variables.
106+
| PowerShell Version | Configuration File Path |
107+
|-------------------|------------------------|
108+
| Windows PowerShell (v5.1) | `C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` |
109+
| PowerShell 7+ | `C:\Users\<username>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` |
40110

41-
or PLAN B: open `~/.bashrc` file, and attach the command `source ~/.env/env.sh` at the end of the file. It will be automatically executed when you log in the ubuntu, and you don't need to execute that command any more.
111+
After adding the activation command, the environment will be loaded automatically each time you restart PowerShell, no need to execute Option A.
42112

43-
### Use Env
113+
---
114+
## Linux/macOS Installation Guide
44115

45-
Please see: <https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md#bsp-configuration-menuconfig>
116+
**Unified Installation Script (Linux and macOS)**
46117

47-
## Usage under Windows
118+
```bash
119+
wget -O- https://raw.githubusercontent.com/RT-Thread/env/master/tools/install.sh | bash
120+
```
48121

49-
Tested on the following version of PowerShell:
122+
For users in China (optional):
50123

51-
- PSVersion 5.1.22621.963
52-
- PSVersion 5.1.19041.2673
124+
```bash
125+
wget -O- https://gitee.com/RT-Thread-Mirror/env/raw/master/tools/install.sh | bash --cn
126+
```
53127

54-
### Install Env
128+
**Notes:**
129+
- Installation script automatically selects mirror sources based on geographic location (can be specified using `--cn` or `--official` parameters)
130+
- Linux installation script automatically uses `sudo` to elevate privileges as needed, no need to manually run as root
131+
- All systems support installation with normal user privileges, installation script automatically handles privilege elevation
55132

56-
您需要以管理员身份运行 PowerShell 来设置执行。(You need to run PowerShell as an administrator to set up execution.)
133+
For complete parameter descriptions, see [Installation Script Parameters](#installation-script-parameters).
57134

58-
在 PowerShell 中执行(Execute the command in PowerShell):
135+
### Activate RT-Thread ENV
59136

60-
```powershell
61-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1 -O install_windows.ps1
62-
set-executionpolicy remotesigned
63-
.\install_windows.ps1
137+
After installation, you need to activate the environment variables before using RT-Thread tools.
138+
139+
**Option A: Manual Activation Each Time**
140+
141+
Run the following command each time you open a new terminal:
142+
143+
```bash
144+
source ~/.rt-env/env.sh
145+
```
146+
147+
**Option B: Auto Activation on Login (Recommended)**
148+
149+
Add the activation command to your shell configuration file to make it run automatically:
150+
151+
```bash
152+
# For bash
153+
echo 'source ~/.rt-env/env.sh' >> ~/.bashrc
154+
155+
# For zsh
156+
echo 'source ~/.rt-env/env.sh' >> ~/.zshrc
64157
```
65158

66-
对于中国大陆用户,请使用以下命令:
159+
After adding, the environment will be automatically activated each time you log in, no need to manually execute the command.
67160

161+
### Tutorial
162+
163+
**Env Tool Tutorials:**
164+
165+
- [Install Env with QEMU Simulator in Ubuntu](https://github.com/RT-Thread/rt-thread/blob/master/documentation/quick-start/quick_start_qemu/quick_start_qemu_linux.md)
166+
167+
---
168+
## Installation Script Parameters
169+
170+
The following are the parameter descriptions common to all installation scripts:
171+
172+
| Parameter | Description |
173+
|-----------|-------------|
174+
| `-y`, `--yes`, `--auto` | Automatic installation, no interaction |
175+
| `-c`, `--cn`, `--gitee` | Use China mirror sources (Gitee, PyPI TUNA) |
176+
| `-o`, `--official` | Force use of official sources |
177+
| `-d`, `--pyocd` | Install pyocd (for debugging) |
178+
| `-r`, `--env-root <path>` | Set custom .rt-env directory path (overrides default `~/.rt-env`) |
179+
| `-e`, `--en`, `--english` | Force English display |
180+
| `-z`, `--zh`, `--chinese` | Force Chinese display |
181+
| `-P`, `--packages <repo>[#<branch>]` | Specify packages repository address and branch, format: url[#branch] |
182+
| `-E`, `--env <repo>[#<branch>]` | Specify env repository address and branch, format: url[#branch] |
183+
| `-S`, `--sdk <repo>[#<branch>]` | Specify sdk repository address and branch, format: url[#branch] |
184+
| `-b`, `--backup <strategy>` | Backup strategy: preserve (keep configs and toolchains), delete_all (delete all), backup_all (full backup) |
185+
| `-t`, `--touch-env-url <url>` | Specify touch_env.py download URL |
186+
| `-h`, `--help` | Display help information |
187+
| `-p`, `--python [path]` | Install portable Python, installation directory is path (Windows only, default: D:\Tools\Python) |
188+
189+
**Backup Strategy Description:**
190+
191+
- **preserve** (default): Keep configuration files (.config) and toolchains (local_pkgs), delete other content and reinstall
192+
- **delete_all**: Completely delete existing ENV directory, keep nothing
193+
- **backup_all**: Create full backup, keep all content including configurations and toolchains
194+
195+
**Usage Examples:**
196+
197+
**Windows (PowerShell):**
68198
```powershell
69-
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_windows.ps1 -O install_windows.ps1
70-
set-executionpolicy remotesigned
71-
.\install_windows.ps1 --gitee
199+
# Basic installation
200+
.\install.ps1
201+
202+
# Use China mirror + automatic installation
203+
.\install.ps1 -c -y
204+
205+
# Install portable Python
206+
.\install.ps1 -p "D:\Tools\Python" -r "D:\RT-Env"
207+
208+
# Specify custom env repository branch
209+
.\install.ps1 -E "https://github.com/RT-Thread/env.git#master"
210+
211+
# Install pyocd + official source
212+
.\install.ps1 -d -o
213+
```
214+
215+
**Linux/macOS (bash):**
216+
```bash
217+
# Basic installation
218+
./install.sh
219+
220+
# Use China mirror + automatic installation
221+
./install.sh -c -y
222+
223+
# Specify custom packages repository
224+
./install.sh -P "https://gitee.com/RT-Thread/packages.git#master"
225+
226+
# Use backup strategy
227+
./install.sh -b preserve
228+
229+
# Specify custom sdk repository
230+
./install.sh -S "https://github.com/RT-Thread/sdk.git#master"
231+
```
232+
233+
## Env Usage Guide
234+
235+
For detailed usage instructions, please refer to:
236+
237+
- [Env Tool Usage Guide](https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md)
238+
- [Env Official User Manual](https://www.rt-thread.org/document/site/#/development-tools/env/env)
239+
240+
---
241+
## Troubleshooting
242+
243+
### Mirror Connection Issues
244+
245+
If download is slow or fails:
246+
247+
- Try using `--cn` parameter to use gitee default mirror
248+
- Check network connection
249+
250+
### Permission Issues (Linux/macOS)
251+
252+
The Linux installation script automatically uses `sudo` to install system dependencies, no need to manually execute permission-related commands.
253+
254+
If you encounter permission issues:
255+
256+
```bash
257+
# Check .rt-env directory permissions
258+
ls -la ~/.rt-env
259+
260+
# If .rt-env belongs to root user, try the following command
261+
sudo chown -R $USER:$USER ~/.rt-env
72262
```
73263

74-
注意:
264+
### Permission Issues (Windows)
265+
266+
If you encounter permission errors:
267+
268+
1. Check if antivirus software is blocking the installation
269+
2. The script automatically detects if administrator privileges are needed and will prompt you to run as administrator if required
270+
271+
---
272+
273+
## Related Documents
274+
275+
- [Env Tool Complete Documentation](https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md)
276+
- [QEMU Quick Start](https://github.com/RT-Thread/rt-thread/blob/master/documentation/quick-start/quick_start_qemu/quick_start_qemu_linux.md)
277+
- [BSP Configuration Guide](https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md#bsp-configuration-menuconfig)
278+
279+
---
280+
281+
## License
282+
283+
This project is open-sourced under the GPL-2.0 license.
284+
285+
---
286+
287+
## Related Links
75288

76-
1. Powershell要以管理员身份运行。
77-
2. 将其设置为 remotesigned 后,您可以作为普通用户运行 PowerShell。( After setting it to remotesigned, you can run PowerShell as a normal user.)
78-
3. 一定要关闭杀毒软件,否则安装过程可能会被杀毒软件强退
289+
- [GitHub Repository](https://github.com/RT-Thread/env)
290+
- [RT-Thread Official Website](https://www.rt-thread.org/)
291+
- [RT-Thread Documentation Center](https://www.rt-thread.io/document/site/)
79292

80-
### Prepare Env
293+
---
81294

82-
方案 A:每次重启 PowerShell 时,都需要输入命令 `~/.env/env.ps1`,以激活环境变量。(PLAN A: Each time you restart PowerShell, you need to enter the command `~/.env/env.ps1` to activate the environment variable.)
295+
## Contributors
83296

84-
方案 B (推荐):打开 `C:\Users\user\Documents\WindowsPowerShell`,如果没有`WindowsPowerShell`则新建该文件夹。新建文件 `Microsoft.PowerShell_profile.ps1`,然后写入 `~/.env/env.ps1` 内容即可,它将在你重启 PowerShell 时自动执行,无需再执行方案 A 中的命令。(or PLAN B (recommended): Open `C:\Users\user\Documents\WindowsPowerShell` and create a new file `Microsoft.PowerShell_profile.ps1`. Then write `~/.env/env.ps1` to the file. It will be executed automatically when you restart PowerShell, without having to execute the command in scenario A.)
297+
Thanks to all developers who have contributed to the RT-Thread Env project.

0 commit comments

Comments
 (0)