#!/bin/bash # Basic environment variables RAINBOND_VERSION=${VERSION:-'v5.17.2'} IMGHUB_MIRROR=${IMGHUB_MIRROR:-'registry.cn-hangzhou.aliyuncs.com/goodrain'} # Define colorful stdout RED='\033[0;31m' GREEN='\033[32;1m' YELLOW='\033[33;1m' NC='\033[0m' TIME="+%Y-%m-%d %H:%M:%S" ######################################## # Information collection # Automatically collect the install details. # Help us improve the success rate of installation. ######################################## function send_msg() { dest_url="https://log.rainbond.com" #msg=${1:-"Terminating by userself."} if [ -z "$1" ]; then msg="Terminating by userself." else msg=$(echo $1 | tr '"' " " | tr "'" " ") fi # send a message to remote url curl --silent -H "Content-Type: application/json" -X POST "$dest_url/dindlog" \ -d "{\"message\":\"$msg\", \"os_info\":\"${OS_INFO}\", \"eip\":\"$EIP\", \"uuid\":\"${UUID}\"}" 2>&1 >/dev/null || : if [ "$msg" == "Terminating by userself." ]; then exit 1 fi } function send_info() { info=$1 echo -e "${GREEN}$(date "$TIME") INFO: $info${NC}" send_msg "$info" } function send_warn() { warn=$1 echo -e "${YELLOW}$(date "$TIME") WARN: $warn${NC}" send_msg "$warn" } function send_error() { error=$1 echo -e "${RED}$(date "$TIME") ERROR: $error${NC}" send_msg "$error" } # Trap SIGINT signal when detect Ctrl + C trap send_msg SIGINT ######################################## # OS Detect # Automatically check the operating system type. # Return Linux or Darwin. ######################################## OS_TYPE=$(uname -s) if [ "${OS_TYPE}" == "Linux" ]; then MD5_CMD="md5sum" if find /lib/modules/$(uname -r) -type f -name '*.ko*' | grep iptable_raw; then if ! lsmod | grep iptable_raw; then echo iptable_raw >/etc/modules-load.d/iptable_raw.conf modprobe iptable_raw fi fi elif [ "${OS_TYPE}" == "Darwin" ]; then MD5_CMD="md5" else if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "${OS_TYPE} 操作系统暂不支持" exit 1 else send_error "Rainbond do not support ${OS_TYPE} OS" exit 1 fi fi OS_INFO=$(uname -a) UUID=$(echo $OS_INFO | ${MD5_CMD} | cut -b 1-32) ################ Start ################# if [ "$LANG" == "zh_CN.UTF-8" ]; then send_info "欢迎您安装 Rainbond, 如果您安装遇到问题, 请反馈到 https://www.rainbond.com/community/support" else send_info "Welcome to install Rainbond, If you install problem, please feedback to https://www.rainbond.com/community/support" fi ######################################## # Envrionment Check # Check docker is running or not. # Check ports can be use or not. # If not, quit. ######################################## if ! (docker info &>/dev/null); then if (which docker &>/dev/null); then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "未检测到 Docker 守护进程, 请先启动 Docker.\n\t- Linux 系统请执行 'systemctl start docker' 启动 Docker.\n\t- MacOS 系统请先启动 Docker Desktop APP.\n\t- 然后重新执行本脚本." exit 1 else send_error "Ops! Docker daemon is not running. Start docker first please.\n\t- For Linux, exec 'systemctl start docker' start docker.\n\t- For MacOS, start the Docker Desktop APP.\n\t- And re-exec this script." exit 1 fi elif [ "${OS_TYPE}" = "Linux" ]; then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_warn "未检测到 Docker 环境, 即将自动安装 Docker...\n" else send_warn "Ops! Docker has not been installed.\nDocker is going to be automatically installed...\n" fi sleep 3 curl -sfL https://get.rainbond.com/install_docker | bash if [ "$?" != "0" ]; then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "自动安装 Docker 失败!请自行手动安装 Docker 后重新执行本脚本." exit 1 else send_error "Ops! Automatic docker installation failed." exit 1 fi fi elif [ "${OS_TYPE}" = "Darwin" ]; then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_warn "未检测到 Docker 环境, 请先安装 Docker Desktop APP, 然后重新执行本脚本." exit 1 else send_warn "Ops! Docker has not been installed.\nPlease visit the following website to get the latest Docker Desktop APP.\n\thttps://www.docker.com/products/docker-desktop/" exit 1 fi fi else if docker ps -a | grep rainbond-allinone 2>&1 >/dev/null; then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "rainbond-allinone 容器已存在.\n\t- 确保 rainbond-allinone 是否在运行.\n\t- 尝试执行 'docker start rainbond-allinone' 命令启动.\n\t- 或者你可以选择删除该容器 'docker rm -f rainbond-allinone'" exit 1 else send_error "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'" exit 1 fi fi fi ports=(80 443 6060 7070) for port in ${ports[@]}; do if (curl -s 127.0.0.1:$port >/dev/null); then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "$port 端口已被占用." exit 1 else send_error "Ops! Port $port has been used." exit 1 fi fi done ######################################## # Arch Detect # Automatically check the CPU architecture type. # Return amd64 or arm64. ######################################## if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then ARCH_TYPE=amd64 elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then ARCH_TYPE=arm64 elif [ $(arch) = "i386" ]; then ARCH_TYPE=amd64 if [ "$LANG" == "zh_CN.UTF-8" ]; then send_warn "检测到 i386, 我们把它当做 x86_64(amd64). 如果您使用的是 M1 芯片的 MacOS, 确保您禁用了 Rosetta. \n\t 请参阅: https://github.com/goodrain/rainbond/issues/1439 " else send_warn "i386 has been detect, we'll treat it like x86_64(amd64). If you are using the M1 chip MacOS,make sure your terminal has Rosetta disabled.\n\t Have a look : https://github.com/goodrain/rainbond/issues/1439 " fi else if [ "$LANG" == "zh_CN.UTF-8" ]; then send_error "Rainbond 目前还不支持 $(arch) 架构" exit 1 else send_error "Rainbond do not support $(arch) architecture" exit 1 fi fi ######################################## # EIP Detect # Automatically check the IP address. # User customization is also supported. ######################################## # Choose tool for IP detect. if which ip >/dev/null; then IF_NUM=$(ip -4 a | egrep -v "docker0|flannel|cni|calico|kube" | grep inet | wc -l) IPS=$(ip -4 a | egrep -v "docker0|flannel|cni|calico|kube" | grep inet | awk '{print $2}' | awk -F '/' '{print $1}' | tr '\n' ' ') elif which ifconfig >/dev/null; then IF_NUM=$(ifconfig | grep -w inet | awk '{print $2}' | wc -l) IPS=$(ifconfig | grep -w inet | awk '{print $2}') elif which ipconfig >/dev/null; then # TODO IF_NUM=$(ipconfig ifcount) IPS="" else IF_NUM=0 IPS="" fi # Func for verify the result entered. function verify_eip() { local result=$2 local max=$1 if [ -z $result ]; then echo -e "${YELLOW}Do not enter null values${NC}" return 1 # Regular matching IPv4 elif [[ $result =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then export EIP=$result return 0 # Regular matching positive integer elif [[ $result =~ \d? ]]; then if [ $result -gt 0 ] && [ $result -le $max ]; then export EIP=${ip_list[$result - 1]} return 0 else return 1 fi else return 1 fi } # The user chooses the IP address to use if [ -n "$IPS" ]; then # Convert to indexed array declare -a ip_list=$(echo \($IPS\)) # Gave some tips if [ "$LANG" == "zh_CN.UTF-8" ]; then echo -e ${GREEN} cat <&1) send_info "$docker_run_meg" sleep 3 # Verify startup container_id=$(docker ps -a | grep rainbond-allinone | awk '{print $1}') if docker ps | grep rainbond-allinone 2>&1 >/dev/null; then if [ "$LANG" == "zh_CN.UTF-8" ]; then send_info "Rainbond dind allinone 启动成功,容器 ID 为: $container_id. 请观察 rainbond-allinone 容器启动日志.\n" else send_info "Rainbond dind allinone container startup succeeded with $container_id. Please observe rainbond-allinone container startup logs.\n" fi else if [ "$LANG" == "zh_CN.UTF-8" ]; then send_warn "Rainbond dind allinone 容器启动失败. 请查看 rainbond-allinone 容器启动日志.\n" else send_warn "Ops! Rainbond dind allinone container startup failed. please observe rainbond-allinone container startup logs.\n" fi send_msg "$(docker logs rainbond-allinone)" # Msg maybe too lang fi sleep 3 # Follow logs stdout docker logs -f rainbond-allinone