diff --git a/script/install-dind.ps1 b/script/install-dind.ps1 new file mode 100644 index 0000000000..0b2f4341f2 --- /dev/null +++ b/script/install-dind.ps1 @@ -0,0 +1,186 @@ +$RAINBOND_VERSION="v5.15.0" +$IMGHUB_MIRROR="registry.cn-hangzhou.aliyuncs.com/goodrain" +$DATE=Get-Date -Format "yyyy-MM-dd HH:mm:ss" + +# Define color +function Write-ColoredText($Text,$Color) { + switch -regex ($Color) { + "green" { + Write-Host "$DATE - INFO: $Text" -ForegroundColor green + send_msg $Text + } + "yellow" { + Write-Host "$DATE - WARN: $Text" -ForegroundColor yellow + send_msg $Text + } + "red" { + Write-Host "$DATE - ERROR: $Text" -ForegroundColor red + send_msg $Text + } + } +} + +function send_msg ($msg) { + + $os_name = (Get-WmiObject -Class Win32_OperatingSystem).Name + $body = @{ + "message" = "$msg" + "os_info" = "$os_name" + "eip" = "$EIP" + "uuid" = "$UUID" + } | ConvertTo-Json + $params = @{ + Uri = "https://log.rainbond.com/dindlog" + Method = "POST" + ContentType = "application/json" + Body = $body + } + Invoke-RestMethod @params > $null +} + +$os_info = Get-WmiObject -Class Win32_OperatingSystem +if ($os_info.Name -match 'Microsoft Windows') { + $os_arch = $os_info.OSArchitecture + $os_type = $os_info.Name.Split("|")[0] +} else { + Write-ColoredText "The current system is not Windows OS" red + Exit +} + +# Check if Docker is installed and running +function Check_Docker { + + if (-not (Get-Command -Name docker -ErrorAction SilentlyContinue)) { + Write-ColoredText "Ops! Docker has not been installed.`nPlease visit the following website to get the latest Docker Desktop for Windows.`n`thttps://docs.docker.com/desktop/install/windows-install/" red + Exit + } + if (-not (Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue)) { + Write-ColoredText "Ops! Docker daemon is not running. Start docker first please.`n`t- For Windows, start the Docker Desktop for Windwos.`n`t- And re-exec this script." red + Exit + } + if (docker ps -a | Select-String "rainbond-allinone") { + Write-ColoredText "Ops! rainbond-allinone container already exists.`n`t- Ensure if rainbond-allinone is running.`n`t- Try to exec 'docker start rainbond-allinone' to start it.`n`t- Or you can remove it by 'docker rm -f rainbond-allinone'" red + Exit + } +} + +# check ports +function Check_Ports { + $ports = @(80, 443, 6060, 7070) + foreach ($port in $ports) { + if (netstat -ano | Select-String -Pattern "LISTENING" | Select-String -Pattern ":$port\s") { + Write-ColoredText "Port $port is already in use" red + Exit + } + } +} + +function MD5 { + $systemInfo = Get-CimInstance Win32_OperatingSystem | Select-Object Caption, OSArchitecture, Manufacturer, SerialNumber + $infoString = $systemInfo | ForEach-Object { $_.Caption + $_.OSArchitecture + $_.Manufacturer + $_.SerialNumber } | Out-String + $md5Hasher = [System.Security.Cryptography.MD5]::Create() + $hashBytes = $md5Hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($infoString)) + $global:UUID = [System.BitConverter]::ToString($hashBytes).ToLower() -replace "-", "" +} + +function Test-ValidIPAddress { + param ( + [string]$IPAddress + ) + + $pattern = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' + $regex = [System.Text.RegularExpressions.Regex]::new($pattern) + + if ($IPAddress -match $regex) { + return $true + } else { + return $false + } +} + +function Prompt { + + Write-Host "Welcome to install Rainbond, If you install problem, please feedback to https://www.rainbond.com/community/support. `n" -ForegroundColor green + + Write-Host "######################################################################" -ForegroundColor green + Write-Host "# The script automatically detects IP addresses in the system" -ForegroundColor green + Write-Host "# You can choose one by enter its index" -ForegroundColor green + Write-Host "# If you have an Public IP, Just type it in" -ForegroundColor green + Write-Host "######################################################################" -ForegroundColor green +} + +function Select_EIP { + # exec prompt + prompt + + $Default_IP = "127.0.0.1" + Write-Host "The following IP has been detected:" -ForegroundColor green + $IPAddress_List = (Get-NetIPAddress | Where-Object { $_.InterfaceAlias -ne 'Loopback Pseudo-Interface 1' -and $_.AddressFamily -eq 'IPv4' }).IPAddress + + for ($i = 0; $i -lt $IPAddress_List.Count; $i++) { + Write-Host "$($i+1). $($IPAddress_List[$i])" + } + $Custom_EIP = Read-Host "For example: enter '1 or 2' to choose the IP, or input '11.22.33.44'(IPv4 address) for specific one, press enter to use the default IP address`nEnter your choose or a specific IP address( Default IP is $Default_IP)" + if ([string]::IsNullOrWhiteSpace($Custom_EIP)) { + $global:EIP = $Default_IP + } elseif ($Custom_EIP -match '^\d+$') { + $index = [int]$Custom_EIP + if ($index -ge 1 -and $index -le $IPAddress_List.Count) { + $global:EIP = $IPAddress_List[$index - 1] + } + else { + Write-ColoredText "Invalid index, please run the script again and enter a valid index." red + exit + } + } elseif (-not (Test-ValidIPAddress $selectedIP)){ + Write-ColoredText "Invalid IP address, please run the script again and enter a valid IP address." red + Exit + } + + Write-Host "The selected IP address is: $EIP" -ForegroundColor green +} +#输出安装检测准备好的信息 +function Check_Message { + Write-Host "##############################################" -ForegroundColor green + Write-Host "# Rainbond dind allinone will be installed:" -ForegroundColor green + Write-Host "# Rainbond version: $RAINBOND_VERSION" -ForegroundColor green + Write-Host "# Arch: $os_arch" -ForegroundColor green + Write-Host "# OS: $os_type" -ForegroundColor green + Write-Host "# Web Site: http://${EIP}:7070" -ForegroundColor green + Write-Host "# Rainbond Docs: https://www.rainbond.com/docs" -ForegroundColor green + Write-Host "# If you install problem, please feedback to:" -ForegroundColor green + Write-Host "# https://www.rainbond.com/community/support" -ForegroundColor green + Write-Host "##############################################" -ForegroundColor green +} + +function CMD { + Write-Host "Generating the installation command:" -ForegroundColor green + $global:docker_run_cmd = "docker run --privileged -d --name=rainbond-allinone --restart=on-failure -p 7070:7070 -p 80:80 -p 443:443 -p 6060:6060 -p 10000-10010:10000-10010 -v rainbond-data:/app/data -v rainbond-opt:/opt/rainbond -e EIP=$EIP -e uuid=$UUID $IMGHUB_MIRROR/rainbond:$($RAINBOND_VERSION)-dind-allinone" + Write-Host $docker_run_cmd + send_msg $docker_run_cmd +} +#启动容器 +function Running_Rainbond { + CMD + + $container_id = iex $docker_run_cmd + if ($container_id) { + Write-ColoredText "Rainbond dind allinone container startup succeeded with $container_id. Please observe rainbond-allinone container startup logs." green + } else { + Write-ColoredText "Ops! Rainbond dind allinone container startup failed. please observe rainbond-allinone container startup logs." red + Exit + } + docker logs -f rainbond-allinone +} + +MD5 + +Check_Docker + +Check_Ports + +Select_EIP + +Check_Message + +Running_Rainbond \ No newline at end of file diff --git a/script/windows.ps1 b/script/windows.ps1 deleted file mode 100644 index b18eca252f..0000000000 --- a/script/windows.ps1 +++ /dev/null @@ -1,235 +0,0 @@ -$OutputEncoding = [System.Text.Encoding]::GetEncoding("UTF-8") -#基本环境变量 -$RAINBOND_VERSION="v5.14.2" -$IMGHUB_MIRROR="registry.cn-hangzhou.aliyuncs.com/goodrain" -$clock=Get-Date -$ports = @(80, 443, 6060, 7070, 8443) - -#定义颜色输出函数 -function Write-ColoredText($Text,$Color) { - Write-Host $Text -ForegroundColor $Color -} -#等待时间 -function Wait-Time([int]$Seconds) { - $remainingSeconds = $Seconds - while ($remainingSeconds -gt 0) { - Write-Host "Remaining seconds: $remainingSeconds" -ForegroundColor green -NoNewline - Start-Sleep -Seconds 1 - Write-Host "`r" -NoNewline - $remainingSeconds-- - } - #Write-Host "Done!" -} -#系统MD5值 -function cmd5 { - $systemInfo = Get-CimInstance Win32_OperatingSystem | Select-Object Caption, OSArchitecture, Manufacturer, SerialNumber - $infoString = $systemInfo | ForEach-Object { $_.Caption + $_.OSArchitecture + $_.Manufacturer + $_.SerialNumber } | Out-String - #使用MD5哈希算法计算信息的哈希值 - $md5Hasher = [System.Security.Cryptography.MD5]::Create() - $hashBytes = $md5Hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($infoString)) - $global:md5Hash = [System.BitConverter]::ToString($hashBytes) -replace "-", "" - #Write-Host "系统信息的MD5哈希值:$global:md5Hash" -} -#请求信息记录 -function send_msg { - $dest_url = "https://log.rainbond.com" - if (-not $global:args) { - $msg = "Terminating by userself." - } - else { - $msg = $global:args[0] -replace '"', ' ' -replace "'", ' ' - } - $body = @{ - "message" = $msg - "os_info" = [System.Environment]::OSVersion.Version - "eip" = $selectedIP - "uuid" = $md5Hash - } | ConvertTo-Json - $params = @{ - Uri = "$dest_url/dindlog" - Method = "POST" - ContentType = "application/json" - Body = $body - } - - try { - Invoke-RestMethod @params > $null - } - catch { - ; - } - - if ($msg -eq "Terminating by userself.") { - exit - } - #Write-Host Invoke-RestMethod @params -} -#系统架构判断 -function system-judgment { - $osInfo = Get-WmiObject -Class Win32_OperatingSystem - $isWindows = $osInfo.Caption.Contains("Windows") - if ($isWindows) { - $architecture = $osInfo.OSArchitecture - $global:ostype="Windows" - $global:osarch=$architecture - } - else { - Write-ColoredText "not Windows OS" red - Exit - } -} -#欢迎语句 -function welcome { - $global:args="$clock :Welcome! Let's get started Rainbond dind allinone install..." - send_msg - Write-ColoredText "$clock :Welcome! Let's get started Rainbond dind allinone install..." green -} -#检测端口是否开放 -function port-is-open-or-no { - foreach ($port in $ports) { - $tcpClient = New-Object System.Net.Sockets.TcpClient - try { - $tcpClient.Connect('localhost', $port) - $tcpClient.Close() - Write-ColoredText "Warning port $port Opened." Yellow - } catch { - - } - } -} -#检测 Docker 是否已安装,且是否正在运行 -function docker-install-and-run { - $dockerDesktopInstalled = Get-Command -ErrorAction SilentlyContinue -Name "docker" | Select-Object -First 1 - - if ($dockerDesktopInstalled) { - ; - $dockerDesktopRunning = Get-Process -Name "Docker Desktop" 2>$null - - if ($dockerDesktopRunning) { - ; - } - else { - Write-ColoredText "Docker Desktop Not running, start it first" red - Exit - } - } - else { - Write-ColoredText "Docker Desktop Not installed." red - Exit - } -} -#输出IP提示 -function messageip { - Write-ColoredText "######################################################################" green - Write-ColoredText "# The following IPs are automatically detected on your system" green - Write-ColoredText "# You can select one by entering its index" green - Write-ColoredText "# For example:" green - Write-ColoredText "# You can enter 1 to select the first IP" green - Write-ColoredText "# Or enter an IP address like 11.22.33.44" green - Write-ColoredText "# Or directly enter 127.0.0.1 as the selected IP address by default" green - Write-ColoredText "######################################################################" green -} -#选择IP地址 -function selected-ip { - $defaultIP = "127.0.0.1" - Write-ColoredText "Available local IP addresses:" green - $ipAddresses = (Get-NetIPAddress | Where-Object { $_.InterfaceAlias -ne 'Loopback Pseudo-Interface 1' -and $_.AddressFamily -eq 'IPv4' }).IPAddress - - for ($i = 0; $i -lt $ipAddresses.Count; $i++) { - Write-ColoredText "$($i+1). $($ipAddresses[$i])" green - } - $selectedIP = Read-Host "Please select the serial number of the IP address (Enter directly to select the default address 127.0.0.1)" - if ([string]::IsNullOrWhiteSpace($selectedIP)) { - $global:selectedIP = $defaultIP - } - elseif ($selectedIP -match '^\d+$') { - $selectedIndex = [int]$selectedIP - if ($selectedIndex -ge 1 -and $selectedIndex -le $ipAddresses.Count) { - $global:selectedIP = $ipAddresses[$selectedIndex - 1] - } - else { - Write-ColoredText "Invalid index, please run the script again and enter a valid index." red - exit - } - } - else { - if ([System.Net.IPAddress]::TryParse($selectedIP, [ref]$null)) { - $global:selectedIP = $selectedIP - } - else { - Write-ColoredText "Invalid IP address, please run the script again and enter a valid IP address." red - exit - } - } - - Write-Host - Write-ColoredText "The selected IP address is: $global:selectedIP" blue - Write-Host -} -#输出安装检测准备好的信息 -function check-message { - Write-ColoredText "##############################################" green - Write-ColoredText "# Rainbond dind allinone will be installed:" green - Write-ColoredText "# Rainbond version: $RAINBOND_VERSION" green - Write-ColoredText "# System architecture: $osarch" green - Write-ColoredText "# OS: $ostype" green - Write-ColoredText "# URL: http://$($global:selectedIP):7070" green - Write-ColoredText "# Rainbond document: https://www.rainbond.com/docs" green - Write-ColoredText "# If you encounter any problems, you can submit a problem to:" green - Write-ColoredText "# https://github.com/goodrain/rainbond" green - Write-ColoredText "# Time: $clock" green - Write-ColoredText "##############################################" green - Write-Host - Write-ColoredText "To start installing Rainbond, please wait" green - Wait-Time -Seconds 130 -} -#启动容器 -function start-rainbond { - $containerId = docker run --privileged -d -p 7070:7070 --name=rainbond-allinone --restart=on-failure ` - -p 80:80 -p 443:443 -p 6060:6060 -p 8443:8443 -p 10000-10010:10000-10010 ` - -v rainbond-data:/app/data ` - -v rainbond-opt:/opt/rainbond ` - -e EIP=$global:selectedIP ` - -e uuid=$global:selectedIP ` - $IMGHUB_MIRROR/rainbond:$($RAINBOND_VERSION)-dind-allinone - if ($containerId) { - $global:args = "Docker The container started successfully." - send_msg - Write-Host - Write-ColoredText "#############################################################" green - Write-ColoredText "Next is the installed log message, starting up, please wait~" green - Write-ColoredText "#############################################################" green - Start-Sleep -Seconds 130 - } else { - Write-Host - Write-ColoredText "Docker The container failed to start, check to see if there is a duplicate name" red - $global:args=docker logs rainbond-allinone - send_msg - exit - } -} -#输出日志信息 -function print-logs { -Write-Host -Write-Host -$variable =docker ps -q -docker logs $variable -if ($LASTEXITCODE -eq 0) { - Write-Host - Write-Host - Write-ColoredText "http://$($global:selectedIP):7070 Access Rainbond" green -} -Write-ColoredText "Press any key to exit..." blue -$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") -} -##############################main######################### -cmd5 -system-judgment -port-is-open-or-no -welcome -docker-install-and-run -messageip -selected-ip -check-message -start-rainbond -print-logs diff --git a/windows-install.bat b/windows-install.bat deleted file mode 100644 index fa456dea3a..0000000000 --- a/windows-install.bat +++ /dev/null @@ -1,182 +0,0 @@ -@echo off -@chcp 65001 >nul - -::基本环境变量 -set RAINBOND_VERSION=VERSION:-v5.14.1 -set IMGHUB_MIRROR=registry.cn-hangzhou.aliyuncs.com/goodrain -set OS_TYPE=%OS% -set clock=%date%---%time% - -::系统判断 -:System-judgment - @echo off - if "%OS%"=="Windows_NT" goto continue - echo 此脚本仅在 Windows 操作系统上运行。 - exit /b - :continue - echo 这是一个 Windows 操作系统 >nul - - ::系统架构判断 - @echo off - IF "%PROCESSOR_ARCHITECTURE%"=="x86" ( - set OS_ARCH=x86 - ) ELSE IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( - set OS_ARCH=AMD64 - ) - - -::检测端口是否开放 -:port-is-open-or-no - @echo off - setlocal enabledelayedexpansion - set PORTS_IN_USE=0 - set LISTEN_PORTS=80 443 6060 7070 8443 - for %%p in (%LISTEN_PORTS%) do ( - netstat -an | findstr ":!p " >nul - if !errorlevel! equ 0 ( - set PORTS_IN_USE=1 - echo 警告端口 %%p 正在使用. - ) else ( - echo Port %%p is not in use. >nul - ) - ) - if %PORTS_IN_USE%==1 ( - echo. - echo 请修改或者清理之前的环境,按任意键退出! - pause >nul - exit /b - ) - - -:: 检查 Docker 是否已安装,且是否正在运行 -:docker-install-and-run - @echo off - rem 检查是否安装了 Docker 桌面 - where docker >nul 2>&1 - if %errorlevel% equ 0 ( - rem 检查 Docker Desktop 是否正在运行 - docker system info >nul 2>&1 - if %errorlevel% equ 0 ( - echo Docker Desktop 已经安装且正在运行.>nul - ) else ( - echo Docker Desktop 已经安装但是没有运行,请先点击docker-desktop运行. - exit - ) - ) else ( - echo Docker Desktop 没有安装请先按照官网安装. - exit - ) - - -::欢迎语句 -:welcome - @echo off - echo ###################################### Start #################################### - echo "%clock%:欢迎!让我们开始 Rainbond dind allinone 安装..." - echo ################################################################################# - - -::选择IP地址 -:selected-ip - echo. - echo ############################################### - echo # 自动检测到您的系统上有以下 IP - echo # 您可以通过输入其索引来选择一个 - @echo off - echo # 例如: - echo # 您可以输入1选择第一个IP - echo # 或直接回车默认使用127.0.0.1作为所选IP地址 - echo ############################################### - echo. - ::检测IP地址用来选择绑定的ip - @echo off - setlocal enabledelayedexpansion - set "defaultIP=127.0.0.1" - set "counter=1" - for /f "tokens=2 delims=:" %%A in ('ipconfig ^| findstr /c:"IPv4"') do ( - for /f "tokens=1 delims= " %%B in ("%%A") do ( - set "IP[!counter!]=%%B" - echo !counter!. %%B - set /a counter+=1 - ) - ) - echo. - echo 请选择一个IP地址(默认回车为 %defaultIP%) - set /p choice=请输入选项数字: - - if "%choice%"=="" ( - set "selectedIP=%defaultIP%" - ) else if not defined IP[%choice%] ( - echo 无效选项! - exit /b 1 - ) else ( - set "selectedIP=!IP[%choice%]!" - ) - - -::输出安装检测准备好的信息 -:check-message - @echo off - echo ############################################### - echo # Rainbond dind allinone 将安装: - echo # Rainbond 版本: %RAINBOND_VERSION% - echo # 系统架构: %OS_ARCH% - echo # 系统: %OS_TYPE% - echo # 网址: http://%selectedIP%:7070 - echo # Rainbond 文档: https://www.rainbond.com/docs - echo # 如果您遇到任何问题,都可以提交问题到: - echo # https://github.com/goodrain/rainbond - echo # 时间: %clock% - echo ############################################### - echo. - echo 开始安装rainbond请稍等 - timeout /t 3 - - -::启动容器 -:start-rainbond - call docker run --privileged -d -p 7070:7070 --name=rainbond-allinone --restart=on-failure ^ - -p 80:80 -p 443:443 -p 6060:6060 -p 8443:8443 -p 10000-10010:10000-10010 ^ - -v rainbond-data:/app/data ^ - -v rainbond-opt:/opt/rainbond ^ - -e EIP=%selectedIP% ^ - registry.cn-hangzhou.aliyuncs.com/goodrain/rainbond:v5.14.2-dind-allinone - if errorlevel 1 goto Fail - if errorlevel 0 goto Success - - - :Fail - echo. - echo docker启动失败或者已经启动,请按任意键继续 - echo. - pause >nul - - :Success - echo docker 成功安装>nul - echo. - echo ############################################### - echo 接下来是已经安装好的日志信息,正在启动请稍等~ - echo ############################################### - echo. - timeout /t 150 - -::输出日志信息 -:print-logs - for /f "usebackq delims=" %%i in (`docker ps -q`) do set dockerID=%%i - docker logs %dockerID% - echo 请通过 http://%selectedIP%:7070 访问 Rainbond(按住ctrl+鼠标左键单击即左边网址即可跳转) - @echo off - echo 按任意键退出脚本 - pause >nul - exit /b - -::#############################main########################### -if -call :System-judgment -call :port-is-open-or-no -call :docker-install-and-run -call :welcome -call :selected-ip -call :check-message -call :start-rainbond -call :print-logs