首页 > 其他分享 >111

111

时间:2024-02-26 09:00:45浏览次数:21  
标签:send else rainbond 111 fi docker allinone

#!/bin/bash

# Basic environment variables
RAINBOND_VERSION=${VERSION:-'v5.17.0'}
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 <<EOF
###############################################
# 鑴氭湰灏嗚嚜鍔ㄦ娴嬪埌绯荤粺涓瓨鍦ㄧ殑 IP 鍦板潃
# 鎮ㄥ彲浠ラ€氳繃杈撳叆搴忓彿鏉ラ€夋嫨涓€涓� IP 鍦板潃
# 濡傛灉鎮ㄦ湁鍏綉 IP 鍦板潃, 鐩存帴杈撳叆鍗冲彲
###############################################
 
妫€娴嬪埌浠ヤ笅IP:
EOF
        echo -e ${NC}
    else
        echo -e ${GREEN}
        cat <<EOF
###############################################
# The script automatically detects IP addresses in the system
# You can choose one by enter its index
# If you have an Public IP, Just type it in
###############################################
 
The following IP has been detected:
EOF
        echo -e ${NC}
    fi
    for ((i = 1; i <= $IF_NUM; i++)); do
        echo -e "\t${GREEN}$i${NC} : ${ip_list[$i - 1]}"
    done

    for i in 1 2 3; do
        if [ "$LANG" == "zh_CN.UTF-8" ]; then
            echo -e "\n${GREEN}渚嬪: 杈撳叆 '1 or 2' 閫夋嫨 IP, 鎴栨寚瀹欼P '11.22.33.44'(IPv4 address), 鐩存帴鍥炶溅鍒欎娇鐢ㄩ粯璁� IP 鍦板潃${NC}"
            verify_eip $IF_NUM 2
            echo -n -e "杈撳叆鎮ㄧ殑閫夋嫨鎴栨寚瀹� IP 鍦板潃(榛樿IP鏄�: $EIP):"
        else
            echo -e "\n${GREEN}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${NC}"
            verify_eip $IF_NUM 2
            echo -n -e "Enter your choose or a specific IP address( Default IP is $EIP):"
        fi
        read res
        if [ -z $res ]; then
            verify_eip $IF_NUM 2 && break
        else
            verify_eip $IF_NUM $res && break
        fi
        if [ "$LANG" == "zh_CN.UTF-8" ]; then
            echo -e "${RED}杈撳叆閿欒, 璇烽噸鏂拌緭鍏�${NC}"
        else
            echo -e "${RED}Incorrect input, please try again${NC}"
        fi
        if [ "$i" = "3" ]; then
            if [ "$LANG" == "zh_CN.UTF-8" ]; then
                send_error "杈撳叆閿欒瓒呰繃3娆�, 涓瀹夎"
                exit 1
            else
                send_error "The input error exceeds 3 times, aborting"
                exit 1
            fi
        fi
    done
else
    # Gave some tips
    if [ "$LANG" == "zh_CN.UTF-8" ]; then
        echo -e ${YELLOW}
        cat <<EOF
###############################################
# 鑷畾妫€娴� IP 澶辫触
# 鎮ㄥ繀椤绘寚瀹氫竴涓� IP
# 渚嬪: 
#   鎮ㄥ彲浠ヨ緭鍏� "11.22.33.44" 鏉ユ寚瀹氫竴涓� IP
###############################################
EOF
        echo -e ${NC}
    else
        echo -e ${YELLOW}
        cat <<EOF
###############################################
# Failed to automatically detect IP
# You have to specify your own IP
# For example: 
#   you can enter "11.22.33.44" for specific one
###############################################
EOF
        echo -e ${NC}
    fi
    for i in 1 2 3; do
        if [ "$LANG" == "zh_CN.UTF-8" ]; then
            echo -n -e "璇疯緭鍏ユ偍鐨� IP 鍦板潃:"
        else
            echo -n -e "Enter your IP address:"
        fi
        read RES
        verify_eip $IF_NUM $RES && break
        if [ "$LANG" == "zh_CN.UTF-8" ]; then
            echo -e "${RED}杈撳叆閿欒, 璇烽噸鏂拌緭鍏�${NC}"
        else
            echo -e "${RED}Incorrect input, please try again${NC}"
        fi
        if [ "$i" = "3" ]; then
            if [ "$LANG" == "zh_CN.UTF-8" ]; then
                send_error "杈撳叆閿欒瓒呰繃3娆�, 涓瀹夎"
                exit 1
            else
                send_error "The input error exceeds 3 times, aborting"
                exit 1
            fi
        fi
    done
fi

################## Main ################
# Start install rainbond-dind-allinone
# Automatically generate install cmd with envs
########################################

# Gave some info
if [ "$LANG" == "zh_CN.UTF-8" ]; then
    echo -e ${GREEN}
    cat <<EOF
###############################################
# Rainbond 鐗堟湰: $RAINBOND_VERSION
# 鏋舵瀯: $ARCH_TYPE
# 鎿嶄綔绯荤粺: $OS_TYPE
# Web 鎺у埗鍙拌闂湴鍧€: http://$EIP:7070
# Rainbond 鏂囨。: https://www.rainbond.com/docs
# 濡傝繃鎮ㄥ畨瑁呴亣鍒伴棶棰橈紝璇峰弽棣堣嚦:
#     https://www.rainbond.com/community/support
###############################################

EOF
    echo -e "${NC}"
else
    echo -e ${GREEN}
    cat <<EOF
###############################################
# Rainbond dind allinone will be installed with:
# Rainbond Version: $RAINBOND_VERSION
# Arch: $ARCH_TYPE
# OS: $OS_TYPE
# Web Site: http://$EIP:7070
# Rainbond Docs: https://www.rainbond.com/docs
# If you install problem, please feedback to: 
#     https://www.rainbond.com/community/support
###############################################

EOF
    echo -e "${NC}"
fi

if [ "$LANG" == "zh_CN.UTF-8" ]; then
    echo -e "${GREEN}鐢熸垚瀹夎鍛戒护:${NC}"
    sleep 3
else
    echo -e "${GREEN}Generating the installation command:${NC}"
    sleep 3
fi

# Generate the installation command based on the detect results
if [ "$OS_TYPE" = "Linux" ]; then
    if [ "$ARCH_TYPE" = "amd64" ]; then
        VOLUME_OPTS="-v ~/.ssh:/root/.ssh -v ~/rainbonddata:/app/data -v /opt/rainbond:/opt/rainbond"
        RBD_IMAGE="${IMGHUB_MIRROR}/rainbond:${RAINBOND_VERSION}-dind-allinone"
    elif [ "$ARCH_TYPE" = "arm64" ]; then
        VOLUME_OPTS="-v ~/.ssh:/root/.ssh -v ~/rainbonddata:/app/data -v /opt/rainbond:/opt/rainbond"
        RBD_IMAGE="${IMGHUB_MIRROR}/rainbond:${RAINBOND_VERSION}-arm64-dind-allinone"
    fi
elif [ "$OS_TYPE" = "Darwin" ]; then
    if [ "$ARCH_TYPE" = "amd64" ]; then
        VOLUME_OPTS="-v ~/.ssh:/root/.ssh -v rainbond-data:/app/data -v rainbond-opt:/opt/rainbond"
        RBD_IMAGE="${IMGHUB_MIRROR}/rainbond:${RAINBOND_VERSION}-dind-allinone"
    elif [ "$ARCH_TYPE" = "arm64" ]; then
        VOLUME_OPTS="-v ~/.ssh:/root/.ssh -v rainbond-data:/app/data -v rainbond-opt:/opt/rainbond"
        RBD_IMAGE="${IMGHUB_MIRROR}/rainbond:${RAINBOND_VERSION}-arm64-dind-allinone"
    fi
fi

# Generate cmd
docker_run_cmd="docker run --privileged -d -p 7070:7070 -p 80:80 -p 443:443 -p 6060:6060 -p 10000-10010:10000-10010 --name=rainbond-allinone --restart=on-failure \
${VOLUME_OPTS} -e EIP=$EIP -e UUID=${UUID} ${RBD_IMAGE}"
send_info "$docker_run_cmd"

# Pull image
if [ "$LANG" == "zh_CN.UTF-8" ]; then
    send_info "鑾峰彇闀滃儚涓� ${RBD_IMAGE}..."
else
    send_info "Pulling image ${RBD_IMAGE}..."
fi
if docker pull ${RBD_IMAGE}; then
    rbd_image_id=$(docker images | grep dind-allinone | grep ${RAINBOND_VERSION} | awk '{print $3}')
    if [ "$LANG" == "zh_CN.UTF-8" ]; then
        send_info "Rainbond 瀹瑰櫒 ID 涓�: ${rbd_image_id}"
    else
        send_info "Rainbond container ID is: ${rbd_image_id}"
    fi
else
    if [ "$LANG" == "zh_CN.UTF-8" ]; then
        send_error "鑾峰彇闀滃儚澶辫触."
    else
        send_error "Pull image failed."
    fi
fi
sleep 3

# Run container
if [ "$LANG" == "zh_CN.UTF-8" ]; then
    send_info "Rainbond dind allinone 姝e湪瀹夎涓�...\n"
else
    send_info "Rainbond dind allinone distribution is installing...\n"
fi
docker_run_meg=$(bash -c "$docker_run_cmd" 2>&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

标签:send,else,rainbond,111,fi,docker,allinone
From: https://www.cnblogs.com/monco-sxy/p/18033588

相关文章

  • HuaWei AR111-s
    [email protected]'spassword:Pre-authenticationbannermessagefromserver:||Error:Authenticationfailed.EndofbannermessagefromserverFurtherauthenticationrequiredadmin@192.168.2.1'spassword:---......
  • 1111
    转载自:https://www.cnblogs.com/MayeZhang/p/12374196.html本来天真的以为hi,jhi,j就是发射端第ii个天线和接收端第jj个天线之间的固定通道连接,后来在看一篇Millimeter-Wave通信论文时候发现这每一个hi,jhi,j就应该相当于一个子信道,也是由一堆不同的路径叠加而成的。发......
  • ARC111B Reversible Cards 题解 (套路题)
    考虑将\(a_i,b_i\)之间连边,发现题目可以被转化为给定一个图,要求对于每条边将其一个顶点染色,问最多能将多少个点染色。于是我们对于每个连通块分开来考虑。对于一个连通块,注意到我们不能将每个顶点染色当且仅当这个连通块是树,且此时可以染色的定点数量为连通块大小减一,如下:如......
  • 代码随想录算法训练营第十六天 | 104.二叉树的最大深度| 559.n叉树的最大深度|222.完
    222.完全二叉树的节点个数 已解答简单 相关标签相关企业 给你一棵 完全二叉树 的根节点 root ,求出该树的节点个数。完全二叉树 的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中......
  • 11111
    <!DOCTYPEhtml><html> <headlang="en">  <metacharset="UTF-8">  <title>(重复)径向渐变-示例(含参数说明)</title>  <styletype="text/css">    .common{      width:1200px;  ......
  • P10111 [GESP202312 七级] 纸牌游戏
    原题链接思路1.任意一轮出牌,只有三种选择2.每一轮的得分只与当前一轮出的牌和上一轮出的牌相关由此我们可以设\(dp[i][j]\)为第\(i\)轮,出牌\(j\)的得分3.由于扣分机制,扣的分数与扣的次数有关,所以我们再加一层\(dp\)代表扣的次数code,注意细节#include<bits/stdc++.......
  • P1116 车厢重组
    1.题目介绍车厢重组题目描述在一个旧式的火车站旁边有一座桥,其桥面可以绕河中心的桥墩水平旋转。一个车站的职工发现桥的长度最多能容纳两节车厢,如果将桥旋转\(180\)度,则可以把相邻两节车厢的位置交换,用这种方法可以重新排列车厢的顺序。于是他就负责用这座桥将进站的车厢按......
  • P1113 杂务
    一眼拓扑排序。但是发现可以同时做多件杂务,这就需要我们考虑好每件杂务的完成时间。显然,一件杂务要开始做,一定是该杂务的准备都完成,所以开始时间应该选择准备中最晚的完成时间。怎么处理这个时间?考虑一件杂务的“入度”是怎么变成\(0\)的,显然是队列中靠前的准备杂务到后面的......
  • 代码随想录算法训练营第十六天| 104.二叉树的最大深度 559.n叉树的最大深度 111.二
    104.二叉树的最大深度  题目链接:104.二叉树的最大深度-力扣(LeetCode)n叉树也一样思路:我的普通递归方法classSolution{public:intdepth(TreeNode*node,intd){intl=0,r=0;if(node->left==NULL&&node->right==NULL)returnd;if(node-......
  • 1114 Family Property
    Thistime,youaresupposedtohelpuscollectthedataforfamily-ownedproperty.Giveneachperson'sfamilymembers,andtheestate(房产)infounderhis/herownname,weneedtoknowthesizeofeachfamily,andtheaverageareaandnumberofsetsof......