Skip to content
38 changes: 9 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,22 @@
### Install Env

```
# 中国大陆网络:
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh

# 其他地区网络:
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh

chmod 777 install_ubuntu.sh
./install_ubuntu.sh
rm install_ubuntu.sh
```

对于中国大陆用户,请使用以下命令

```
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh
chmod 777 install_ubuntu.sh
./install_ubuntu.sh --gitee
rm install_ubuntu.sh
```
请根据自身网络地区选择对应的下载地址来下载安装脚本。安装脚本会自动识别网络区域,使用相应镜像下载后续仓库,完成后将仓库远程地址统一设为 GitHub。

### Prepare Env

PLAN A: Whenever start the ubuntu system, you need to type command `source ~/.env/env.sh` to activate the environment variables.

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.
Run `source ~/.env/env.sh` to activate Env. The script creates and activates its Python virtual environment on first use. To activate Env automatically, add this command to `~/.bashrc`.

### Use Env

Expand All @@ -63,13 +59,7 @@ set-executionpolicy remotesigned
.\install_windows.ps1
```

对于中国大陆用户,请使用以下命令:

```powershell
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_windows.ps1 -O install_windows.ps1
set-executionpolicy remotesigned
.\install_windows.ps1 --gitee
```
安装脚本会自动识别网络区域,使用相应镜像下载仓库,完成后将仓库远程地址统一设为 GitHub。

注意:

Expand All @@ -79,14 +69,4 @@ set-executionpolicy remotesigned

### Prepare Env

方案 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.)

方案 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.)

### 常见问题

对于中国大陆用户,请注意首次激活 Env 时可能出现错误,这可能是当前网络下使用的镜像(默认清华源)连接失败,修复方法:

1. 再次进入安装 Env 的目录,运行`.\install_windows.ps1 --gitee`重新安装,并在**安装完成后不要激活 Env**。
2. 打开 `~/.env/env.ps1` 文件,修改 `python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple` 和 `pip install -i https://pypi.tuna.tsinghua.edu.cn/simple "$PSScriptRoot\tools\scriptse` 中的镜像地址 `https://pypi.tuna.tsinghua.edu.cn/simple` 为其他可用的镜像。
3. 激活 Env。
Run `~/.env/env.ps1` to activate Env. The script creates and activates its Python virtual environment on first use. To activate Env automatically, add `~/.env/env.ps1` to your PowerShell profile.
25 changes: 24 additions & 1 deletion env.sh
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
export PATH=~/.env/tools/scripts:$PATH
# shellcheck shell=sh
VENV_ROOT="$HOME/.env/.venv"

if [ ! -d "$VENV_ROOT" ]; then
echo "Create Python venv for RT-Thread..."
if ! python3 -m venv "$VENV_ROOT"; then
echo "Failed to create Python venv for RT-Thread."
return 1
fi
if ! "$VENV_ROOT/bin/python" -m pip install --upgrade pip; then
echo "Failed to upgrade pip for RT-Thread."
rm -rf "$VENV_ROOT"
return 1
fi
if ! "$VENV_ROOT/bin/pip" install "$HOME/.env/tools/scripts"; then
echo "Failed to install RT-Thread dependencies."
rm -rf "$VENV_ROOT"
return 1
fi
fi

. "$VENV_ROOT/bin/activate"
export PATH="$HOME/.env/tools/scripts:$PATH"
export RTT_EXEC_PATH=/usr/bin
20 changes: 13 additions & 7 deletions install_arch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/usr/bin/env bash

TOUCH_ENV_URL=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
COUNTRY=$(wget -qO- --timeout=3 https://ipinfo.io/country 2>/dev/null)
if [ "$COUNTRY" = "CN" ]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
elif [ -z "$COUNTRY" ] && [ -t 0 ]; then
read -r -p "Unable to detect network region. Use Gitee mirror? (y/N, default: GitHub) " use_gitee
if [[ "$use_gitee" =~ ^[Yy]$ ]]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi
fi

# 函数:从 AUR 安装 rt-thread-env-meta 包
install_from_aur() {
echo "正在从 AUR 安装 rt-thread-env-meta 包..."
Expand Down Expand Up @@ -59,12 +70,7 @@ esac

echo "安装完成。"

url=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
if [ $1 ] && [ $1 = --gitee ]; then
url=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi

wget $url -O touch_env.sh
wget "$TOUCH_ENV_URL" -O touch_env.sh
chmod 777 touch_env.sh
./touch_env.sh $@
./touch_env.sh
rm touch_env.sh
8 changes: 2 additions & 6 deletions install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ if ! [ -x "$(command -v arm-none-eabi-gcc)" ]; then
brew install gnu-arm-embedded
fi

url=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
if [ $1 ] && [ $1 = --gitee ]; then
url=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi
curl $url -o touch_env.sh
curl https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh -o touch_env.sh
chmod 777 touch_env.sh
./touch_env.sh $@
./touch_env.sh
rm touch_env.sh
22 changes: 14 additions & 8 deletions install_suse.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/usr/bin/env bash

TOUCH_ENV_URL=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
COUNTRY=$(wget -qO- --timeout=3 https://ipinfo.io/country 2>/dev/null)
if [ "$COUNTRY" = "CN" ]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
elif [ -z "$COUNTRY" ] && [ -t 0 ]; then
read -r -p "Unable to detect network region. Use Gitee mirror? (y/N, default: GitHub) " use_gitee
if [[ "$use_gitee" =~ ^[Yy]$ ]]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi
fi

sudo zypper update -y

sudo zypper install python3 python3-pip gcc git ncurses-devel cross-arm-none-gcc11-bootstrap cross-arm-binutils qemu qemu-arm qemu-extra -y
sudo zypper install python3 python3-pip python3-venv gcc git ncurses-devel cross-arm-none-gcc11-bootstrap cross-arm-binutils qemu qemu-arm qemu-extra -y
python3 -m pip install scons requests tqdm kconfiglib
python3 -m pip install -U pyocd

url=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
if [ $1 ] && [ $1 = --gitee ]; then
url=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi

wget $url -O touch_env.sh
wget "$TOUCH_ENV_URL" -O touch_env.sh
chmod 777 touch_env.sh
./touch_env.sh $@
./touch_env.sh
rm touch_env.sh
22 changes: 14 additions & 8 deletions install_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/usr/bin/env bash

TOUCH_ENV_URL=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
COUNTRY=$(wget -qO- --timeout=3 https://ipinfo.io/country 2>/dev/null)
if [ "$COUNTRY" = "CN" ]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
elif [ -z "$COUNTRY" ] && [ -t 0 ]; then
read -r -p "Unable to detect network region. Use Gitee mirror? (y/N, default: GitHub) " use_gitee
if [[ "$use_gitee" =~ ^[Yy]$ ]]; then
TOUCH_ENV_URL=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi
fi

sudo apt-get update
sudo apt-get -qq install python3 python3-pip gcc git libncurses5-dev -y
sudo apt-get -qq install python3 python3-pip python3-venv gcc git libncurses5-dev -y
pip install scons requests tqdm kconfiglib pyyaml

url=https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.sh
if [ $1 ] && [ $1 = --gitee ]; then
url=https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.sh
fi

wget $url -O touch_env.sh
wget "$TOUCH_ENV_URL" -O touch_env.sh
chmod 777 touch_env.sh
./touch_env.sh $@
./touch_env.sh
rm touch_env.sh
15 changes: 10 additions & 5 deletions install_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ if (!$?) {
echo "Python environment has installed. Jump this step."
}

try {
$useGitee = (Invoke-RestMethod -Uri "https://ipinfo.io/json" -UseBasicParsing -TimeoutSec 3).country -eq "CN"
} catch {
$useGitee = $false
}

$git_url = "https://github.com/git-for-windows/git/releases/download/v2.39.2.windows.1/Git-2.39.2-64-bit.exe"
if ($args[0] -eq "--gitee") {
echo "Use gitee mirror server!"
if ($useGitee) {
$git_url = "https://registry.npmmirror.com/-/binary/git-for-windows/v2.39.2.windows.1/Git-2.39.2-64-bit.exe"
}

Expand All @@ -53,7 +58,7 @@ if (!(Test-Command git)) {

$PIP_SOURCE = "https://pypi.org/simple"
$PIP_HOST = "pypi.org"
if ($args[0] -eq "--gitee") {
if ($useGitee) {
$PIP_SOURCE = "http://mirrors.aliyun.com/pypi/simple"
$PIP_HOST = "mirrors.aliyun.com"
}
Expand Down Expand Up @@ -116,13 +121,13 @@ if (!$?) {
}

$url = "https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.ps1"
if ($args[0] -eq "--gitee") {
if ($useGitee) {
$url = "https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.ps1"
}

wget $url -O touch_env.ps1
echo "run touch_env.ps1"
./touch_env.ps1 $args[0]
./touch_env.ps1

if ($args.Count -ge 2 -and $args[1] -eq "-y") {
echo "Windows Env environment installment has finished. (auto mode, no pause)"
Expand Down
17 changes: 13 additions & 4 deletions touch_env.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ $DEFAULT_RTT_PACKAGE_URL = "https://github.com/RT-Thread/packages.git"
$ENV_URL = "https://github.com/RT-Thread/env.git"
$SDK_URL = "https://github.com/RT-Thread/sdk.git"

if ($args[0] -eq "--gitee") {
echo "Using gitee service."
try {
$useGitee = (Invoke-RestMethod -Uri "https://ipinfo.io/json" -UseBasicParsing -TimeoutSec 3).country -eq "CN"
} catch {
$useGitee = $false
}

if ($useGitee) {
$DEFAULT_RTT_PACKAGE_URL = "https://gitee.com/RT-Thread-Mirror/packages.git"
$ENV_URL = "https://gitee.com/RT-Thread-Mirror/env.git"
$SDK_URL = "https://gitee.com/RT-Thread-Mirror/sdk.git"
Expand All @@ -12,8 +17,9 @@ if ($args[0] -eq "--gitee") {
$env_dir = "$HOME\.env"

if (Test-Path -Path $env_dir) {
$option = Read-Host ".env directory already exists. Would you like to remove and recreate .env directory? (Y/N) " option
} if (( $option -eq 'Y' ) -or ($option -eq 'y')) {
$option = Read-Host ".env directory already exists. Would you like to remove and recreate .env directory? (Y/N) "
}
if (( $option -eq 'Y' ) -or ($option -eq 'y')) {
Get-ChildItem $env_dir -Recurse | Remove-Item -Force -Recurse
rm -r $env_dir
}
Expand All @@ -29,6 +35,9 @@ if (!(Test-Path -Path $env_dir)) {
echo 'source "$PKGS_DIR/packages/Kconfig"' | Out-File -FilePath $env_dir/packages/Kconfig -Encoding ASCII
git clone $SDK_URL $env_dir/packages/sdk --depth=1
git clone $ENV_URL $env_dir/tools/scripts --depth=1
git -C $env_dir/packages/packages remote set-url origin https://github.com/RT-Thread/packages.git
git -C $env_dir/packages/sdk remote set-url origin https://github.com/RT-Thread/sdk.git
git -C $env_dir/tools/scripts remote set-url origin https://github.com/RT-Thread/env.git
copy $env_dir/tools/scripts/env.ps1 $env_dir/env.ps1
} else {
echo ".env folder has exsited. Jump this step."
Expand Down
12 changes: 9 additions & 3 deletions touch_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ DEFAULT_RTT_PACKAGE_URL=https://github.com/RT-Thread/packages.git
ENV_URL=https://github.com/RT-Thread/env.git
SDK_URL="https://github.com/RT-Thread/sdk.git"

if [ $1 ] && [ $1 = --gitee ]; then
gitee=1
if [ "$(wget -qO- --timeout=3 https://ipinfo.io/country 2>/dev/null)" = "CN" ]; then
DEFAULT_RTT_PACKAGE_URL=https://gitee.com/RT-Thread-Mirror/packages.git
ENV_URL=https://gitee.com/RT-Thread-Mirror/env.git
SDK_URL="https://gitee.com/RT-Thread-Mirror/sdk.git"
Expand All @@ -29,5 +28,12 @@ if ! [ -d $env_dir ]; then
echo 'source "$PKGS_DIR/packages/Kconfig"' >$env_dir/packages/Kconfig
git clone $SDK_URL $env_dir/packages/sdk --depth=1
git clone $ENV_URL $env_dir/tools/scripts --depth=1
echo -e 'export PATH=`python3 -m site --user-base`/bin:$HOME/.env/tools/scripts:$PATH\nexport RTT_EXEC_PATH=/usr/bin' >$env_dir/env.sh
git -C $env_dir/packages/packages remote set-url origin https://github.com/RT-Thread/packages.git
git -C $env_dir/packages/sdk remote set-url origin https://github.com/RT-Thread/sdk.git
git -C $env_dir/tools/scripts remote set-url origin https://github.com/RT-Thread/env.git
if ! cp $env_dir/tools/scripts/env.sh $env_dir/env.sh; then
echo "Failed to set up Env activation script."
rm -rf $env_dir
exit 1
fi
fi