|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright (c) 2024, RT-Thread Development Team |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: Apache-2.0 |
| 7 | +# |
| 8 | +# Change Logs: |
| 9 | +# Date Author Notes |
| 10 | +# 2024-08-27 Supperthomas the first version |
| 11 | +# |
| 12 | + |
| 13 | +#这个脚本用于安装RT-Thread开发环境 请确保网络畅通 |
| 14 | + |
| 15 | +# 设置环境变量 如果希望生效请在当前shell中执行source install.sh |
| 16 | + |
| 17 | +export RTT_ROOT=$(pwd) |
| 18 | +export RTT_CC=gcc |
| 19 | + |
| 20 | +echo "RTT_ROOT is set to: $RTT_ROOT" |
| 21 | + |
| 22 | +# 检测操作系统类型和发行版 |
| 23 | +detect_os() { |
| 24 | + if command -v uname >/dev/null 2>&1; then |
| 25 | + OS=$(uname -s) |
| 26 | + else |
| 27 | + if [ -f "/etc/os-release" ]; then |
| 28 | + OS="Linux" |
| 29 | + elif [ -f "/System/Library/CoreServices/SystemVersion.plist" ]; then |
| 30 | + OS="macOS" |
| 31 | + elif [[ -d "/mnt/c/Windows" || -d "/c/Windows" ]]; then |
| 32 | + OS="WSL" |
| 33 | + else |
| 34 | + OS="UNKNOWN" |
| 35 | + fi |
| 36 | + fi |
| 37 | + |
| 38 | + if [ "$OS" == "Linux" ]; then |
| 39 | + if [ -f /etc/os-release ]; then |
| 40 | + . /etc/os-release |
| 41 | + DISTRO=$ID |
| 42 | + VERSION=$VERSION_ID |
| 43 | + elif [ -f /etc/lsb-release ]; then |
| 44 | + . /etc/lsb-release |
| 45 | + DISTRO=$DISTRIB_ID |
| 46 | + VERSION=$DISTRIB_RELEASE |
| 47 | + else |
| 48 | + DISTRO="UNKNOWN" |
| 49 | + VERSION="UNKNOWN" |
| 50 | + fi |
| 51 | + fi |
| 52 | + |
| 53 | + echo "Detected Operating System: $OS, Distribution: $DISTRO, Version: $VERSION" |
| 54 | +} |
| 55 | + |
| 56 | +# 安装函数 |
| 57 | +install_on_ubuntu() { |
| 58 | + echo "Installing on Debian/Ubuntu..." |
| 59 | + wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh |
| 60 | + chmod 777 install_ubuntu.sh |
| 61 | + ./install_ubuntu.sh |
| 62 | +} |
| 63 | + |
| 64 | +install_on_fedora() { |
| 65 | + echo "Installing on Fedora..." |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | +install_on_centos() { |
| 70 | + echo "Installing on CentOS/RHEL..." |
| 71 | +} |
| 72 | + |
| 73 | +install_on_arch() { |
| 74 | + echo "Installing on Arch Linux..." |
| 75 | +} |
| 76 | + |
| 77 | +install_on_macos() { |
| 78 | + echo "Installing on macOS..." |
| 79 | + wget https://raw.githubusercontent.com/RT-Thread/env/master/install_macos.sh |
| 80 | + chmod 777 install_macos.sh |
| 81 | + ./install_macos.sh |
| 82 | +} |
| 83 | + |
| 84 | +install_on_wsl() { |
| 85 | + echo "Installing on Windows Subsystem for Linux (WSL)..." |
| 86 | +} |
| 87 | + |
| 88 | +install_on_windows() { |
| 89 | + echo "Installing on Windows using PowerShell..." |
| 90 | + wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1 |
| 91 | + chmod 777 install_windows.ps1 |
| 92 | + ./install_windows.ps1 |
| 93 | +} |
| 94 | + |
| 95 | +install_on_opensuse() { |
| 96 | + echo "Installing on openSUSE..." |
| 97 | + wget https://raw.githubusercontent.com/RT-Thread/env/master/install_suse.sh |
| 98 | + chmod 777 install_suse.sh |
| 99 | + ./install_suse.sh |
| 100 | +} |
| 101 | +# 主函数 |
| 102 | +main() { |
| 103 | + detect_os |
| 104 | + case "$OS" in |
| 105 | + Linux) |
| 106 | + case "$DISTRO" in |
| 107 | + ubuntu|debian) |
| 108 | + install_on_ubuntu |
| 109 | + ;; |
| 110 | + fedora) |
| 111 | + install_on_fedora |
| 112 | + ;; |
| 113 | + centos|rhel) |
| 114 | + install_on_centos |
| 115 | + ;; |
| 116 | + arch) |
| 117 | + install_on_arch |
| 118 | + ;; |
| 119 | + *) |
| 120 | + echo "Unsupported Linux distribution: $DISTRO" |
| 121 | + exit 1 |
| 122 | + ;; |
| 123 | + esac |
| 124 | + ;; |
| 125 | + macOS) |
| 126 | + install_on_macos |
| 127 | + ;; |
| 128 | + WSL) |
| 129 | + install_on_wsl |
| 130 | + ;; |
| 131 | + Windows) |
| 132 | + install_on_windows |
| 133 | + ;; |
| 134 | + *) |
| 135 | + echo "Unsupported Operating System: $OS" |
| 136 | + exit 1 |
| 137 | + ;; |
| 138 | + esac |
| 139 | + echo "Installation completed!" |
| 140 | +} |
| 141 | + |
| 142 | +# 执行主函数 |
| 143 | +main |
0 commit comments