From 8cbbb8841899c276bd191db38f0ae33371d5a3ba Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Sun, 5 Mar 2023 10:05:35 +0800 Subject: [PATCH] add powershell install script. --- install_windows.ps1 | 59 +++++++++++++++++++++++++++++++++++++++++++++ touch_env.ps1 | 25 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 install_windows.ps1 create mode 100644 touch_env.ps1 diff --git a/install_windows.ps1 b/install_windows.ps1 new file mode 100644 index 00000000..e0ef6127 --- /dev/null +++ b/install_windows.ps1 @@ -0,0 +1,59 @@ + +$RTT_PYTHON = "python" + +function Test-Command( [string] $CommandName ) { + (Get-Command $CommandName -ErrorAction SilentlyContinue) -ne $null +} + +foreach ($p_cmd in ("python3","python")) { + cmd /c $p_cmd --version | Out-Null + if (!$?) { continue } + $RTT_PYTHON = $p_cmd + break +} + +if (!(Test-Command $RTT_PYTHON)) { + echo "Python not installed. Will install python 3.11.2." + echo "Downloading Python." + wget -O Python_setup.exe https://www.python.org/ftp/python/3.11.2/python-3.11.2.exe + echo "Installing Python." + if (Test-Path -Path "D:\") { + cmd /c Python_setup.exe /quiet TargetDir=D:\Progrem\Python311 InstallAllUsers=1 PrependPath=1 Include_test=0 + } + else { + cmd /c Python_setup.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 + } +} + +if (!(Test-Command git)) { + echo "Git not installed. Will install Git." + echo "Installing git." + winget install --id Git.Git -e --source winget +} + +cmd /c $RTT_PYTHON -m pip list | Out-Null +if (!$?) { + echo "Installing pip." + cmd /c $RTT_PYTHON -m ensurepip --upgrade +} + +cmd /c $RTT_PYTHON -m pip install --upgrade pip | Out-Null + +if (!(Test-Command scons)) { + echo "Installing scons." + cmd /c $RTT_PYTHON -m pip install scons +} + +cmd /c $RTT_PYTHON -m pip list | findstr "requests" | Out-Null +if (!$?) { + echo "Installing requests." + cmd /c $RTT_PYTHON -m pip install requests +} + +$url="https://raw.githubusercontent.com/RT-Thread/env/master/touch_env.ps1" +if ($args[0] -eq "--gitee") { + $url="https://gitee.com/RT-Thread-Mirror/env/raw/master/touch_env.ps1" +} + +wget $url -O touch_env.ps1 +./touch_env.ps1 $args[0] diff --git a/touch_env.ps1 b/touch_env.ps1 new file mode 100644 index 00000000..3a2621d1 --- /dev/null +++ b/touch_env.ps1 @@ -0,0 +1,25 @@ +$DEFAULT_RTT_PACKAGE_URL="https://github.com/RT-Thread/packages.git" +# you can change the package url by defining RTT_PACKAGE_URL, ex: +# export RTT_PACKAGE_URL=https://github.com/Varanda-Labs/packages.git +$RTT_URL="https://github.com/RT-Thread/rt-thread.git" +$ENV_URL="https://github.com/RT-Thread/env.git" + +if ($args[0] -eq "--gitee") { + echo "Using gitee service." + $DEFAULT_RTT_PACKAGE_URL="https://gitee.com/RT-Thread-Mirror/packages.git" + $RTT_URL="https://gitee.com/rtthread/rt-thread.git" + $ENV_URL="https://gitee.com/RT-Thread-Mirror/env.git" +} + +$env_dir = "$HOME\.env" +if (!(Test-Path -Path $env_dir)) { + $package_url=$DEFAULT_RTT_PACKAGE_URL + mkdir $env_dir | Out-Null + mkdir $env_dir\local_pkgs | Out-Null + mkdir $env_dir\packages | Out-Null + mkdir $env_dir\tools | Out-Null + git clone $package_url $env_dir/packages/packages + echo 'source "$PKGS_DIR/packages/Kconfig"' > $env_dir/packages/Kconfig + git clone $ENV_URL $env_dir/tools/scripts + echo '$env:path="$HOME\.env\tools\scripts;$env:path"' > $env_dir/env.ps1 +} \ No newline at end of file