github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/hack/setup_for_IEF.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2018 The KubeEdge Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  if [ "$1" = "" ];then
    18      echo "Please specify the node configuration file"
    19      exist 1
    20  fi
    21  
    22  NODE_CONFIG_FILE=$1
    23  SRC_DIR=${GOPATH}/src/github.com/kubeedge/kubeedge/edge
    24  
    25  if [ -z "${GOPATH}" ]; then
    26      echo "Please export GOPATH"
    27      exit 1
    28  fi
    29  
    30  echo "make new dir for certs..."
    31  if [ ! -d kubeedge_work_dir ]; then
    32  	mkdir kubeedge_work_dir
    33  else
    34  	rm -rf kubeedge_work_dir/*
    35  fi
    36  KUBEEDGE_WORK_DIR=`pwd`/kubeedge_work_dir
    37  
    38  echo "unzip to get the certificates and user_config..."
    39  tar -zxvf ${NODE_CONFIG_FILE} -C kubeedge_work_dir/
    40  
    41  CURRENT_PATH=${SRC_DIR}
    42  CERT_PATH=${KUBEEDGE_WORK_DIR}
    43  DEFAULT_PLACEMENT_FLAG="true"
    44  create_system_config() {
    45      #docker root dir
    46  set +e
    47      docker_info=`docker info |grep "Docker Root Dir"`
    48      local rt=$?
    49  set -e
    50      if [ ${rt} -ne 0 ]; then
    51          echo "Docker Root Dir should be exist, please check docker version(>=1.11)"
    52          exit 1
    53      fi
    54      docker_root_dir=`echo $docker_info|sed 's/"//g' | sed 's/Docker Root Dir://'|sed 's/ //g'`
    55      if [ ! -f ${CURRENT_PATH}/conf/system.yaml ]; then
    56          cat > ${CURRENT_PATH}/conf/system.yaml <<EOF
    57  systeminfo:
    58      architecture: {ARCH}
    59      docker_root_dir: ${docker_root_dir}
    60  EOF
    61      else
    62          sed -i "s|{DOCKER_ROOT}|$docker_root_dir|g" ${CURRENT_PATH}/conf/system.yaml
    63      fi
    64  
    65      #ARCH
    66      #TODO: need to confirm the output of `arch` in different architecture:i386、i486、i586、alpha、sparc、arm、m68k、mips、ppc、i686 x86_64
    67      arch_info=`arch`
    68      case $arch_info in
    69      "x86_64" | "amd64")
    70          archInfo="x86_64"
    71          sed -i "s/{ARCH}/${arch_info}/g" ${CURRENT_PATH}/conf/system.yaml
    72          ;;
    73      "arm" | "armv7" | "armv7l")
    74          archInfo="arm32"
    75          sed -i "s/{ARCH}/${archInfo}/g" ${CURRENT_PATH}/conf/system.yaml
    76          ;;
    77      "aarch64")
    78          archInfo="arm64"
    79          sed -i "s/{ARCH}/${archInfo}/g" ${CURRENT_PATH}/conf/system.yaml
    80          ;;
    81      "i386")
    82          archInfo="i386"
    83          sed -i "s/{ARCH}/${archInfo}/g" ${CURRENT_PATH}/conf/system.yaml
    84          ;;
    85      *)
    86          echo "Don't support architecture ${arch_info}!"
    87          exit 1
    88          ;;
    89      esac
    90      export GOARCHAIUS_CONFIG_PATH=${CURRENT_PATH}
    91  }
    92  
    93  parse_config() {
    94      if [ ! -f ${CERT_PATH}/user_config ]; then
    95          echo "file user_config must be exist in the directory: ${CERT_PATH}"
    96          exit 1
    97      fi
    98  
    99      MASTER_ADDR_FOREDGE=`cat ${CERT_PATH}/user_config | grep -Po '"MASTER_URL":".*?"' | sed 's/"//g' | sed 's/MASTER_URL://'`
   100      if [ $? -ne 0 ] || [ "${MASTER_ADDR_FOREDGE}"x = x ]; then
   101          echo "Parse MASTER_URL failed!"
   102          exit 1
   103      fi
   104  
   105      NODE_HOST_NAME=`cat ${CERT_PATH}/user_config | grep -Po '"NODE_ID":".*?"' | sed 's/"//g' | cut -d":" -f2`
   106      if [ $? -ne 0 ] || [ "${NODE_HOST_NAME}"x = x ]; then
   107          echo "Parse NODE_ID failed!"
   108          exit 1
   109      fi
   110  
   111      EDGE_NAMESPACE=`cat ${CERT_PATH}/user_config | grep -Po '"PROJECT_ID":".*?"' | sed 's/"//g' | cut -d":" -f2`
   112      if [ $? -ne 0 ] || [ "${EDGE_NAMESPACE}"x = x ]; then
   113          echo "Parse PROJECT_ID failed!"
   114          exit 1
   115      fi
   116  
   117      PRIVATE_CERT_FILE=`cat ${CERT_PATH}/user_config | grep -Po '"PRIVATE_CERTIFICATE":".*?"' | sed 's/"//g' | sed 's/PRIVATE_CERTIFICATE://'`
   118      if [ $? -ne 0 ] || [ "${PRIVATE_CERT_FILE}"x = x ]; then
   119          echo "Parse PRIVATE_CERTIFICATE failed!"
   120          exit 1
   121      fi
   122  
   123      PRIVATE_KEY_FILE=`cat ${CERT_PATH}/user_config | grep -Po '"PRIVATE_KEY":".*?"' | sed 's/"//g' | sed 's/PRIVATE_KEY://'`
   124      if [ $? -ne 0 ] || [ "${PRIVATE_KEY_FILE}"x = x ]; then
   125          echo "Parse PRIVATE_KEY failed!"
   126          exit 1
   127      fi
   128  
   129      ROOT_CA_FILE=`cat ${CERT_PATH}/user_config | grep -Po '"ROOT_CA":".*?"' | sed 's/"//g' | sed 's/ROOT_CA://'`
   130      if [ $? -ne 0 ] || [ "${ROOT_CA_FILE}"x = x ]; then
   131          echo "Parse ROOT_CA failed!"
   132          exit 1
   133      fi
   134  
   135      ENABLE_GPU=`cat ${CERT_PATH}/user_config | grep -Po '"ENABLE_GPU":".*?"' | sed 's/"//g' | sed 's/ENABLE_GPU://'`
   136      if [ $? -ne 0 ] || [ "${ENABLE_GPU}"x = x ]; then
   137          echo "Parse ENABLE_GPU failed!"
   138          exit 1
   139      fi
   140  
   141      DIS_URL=`cat ${CERT_PATH}/user_config | grep -Po '"DIS_URL":".*?"' | sed 's/"//g' | sed 's/DIS_URL://'`
   142      if [ $? -ne 0 ] || [ "${DIS_URL}"x = x ]; then
   143          echo "Parse DIS_URL failed!"
   144          exit 1
   145      fi
   146  
   147      DIS_API_VERSION=`cat ${CERT_PATH}/user_config | grep -Po '"DIS_API_VERSION":".*?"' | sed 's/"//g' | sed 's/DIS_API_VERSION://'`
   148      if [ $? -ne 0 ] || [ "${DIS_API_VERSION}"x = x ]; then
   149          echo "Parse DIS_API_VERSION failed!"
   150          exit 1
   151      fi
   152  
   153      REGION=`cat ${CERT_PATH}/user_config | grep -Po '"REGION":".*?"' | sed 's/"//g' | sed 's/REGION://'`
   154      if [ $? -ne 0 ] || [ "${REGION}"x = x ]; then
   155          echo "Parse REGION failed!"
   156          exit 1
   157      fi
   158  
   159      OBS_URL=`cat ${CERT_PATH}/user_config | grep -Po '"OBS_URL":".*?"' | sed 's/"//g' | sed 's/OBS_URL://'`
   160      if [ $? -ne 0 ] || [ "${OBS_URL}"x = x ]; then
   161          echo "Parse OBS_URL failed!"
   162          exit 1
   163      fi
   164  }
   165  
   166  create_edge_config() {
   167      if [ ! -f ${CURRENT_PATH}/conf/edge.yaml ]; then
   168          echo "There is no ${CURRENT_PATH}/conf/edge.yaml!"
   169          exit 1
   170      fi
   171      sed -i "s|certfile: .*|certfile: ${CERT_PATH}/${PRIVATE_CERT_FILE}|g" ${CURRENT_PATH}/conf/edge.yaml
   172      sed -i "s|keyfile: .*|keyfile: ${CERT_PATH}/${PRIVATE_KEY_FILE}|g" ${CURRENT_PATH}/conf/edge.yaml
   173      sed -i "s|project-id: .*|project-id: ${EDGE_NAMESPACE}|g" ${CURRENT_PATH}/conf/edge.yaml
   174      sed -i "s|node-id: .*|node-id: ${NODE_HOST_NAME}|g" ${CURRENT_PATH}/conf/edge.yaml
   175      sed -i "s|register-node-namespace: .*|register-node-namespace: ${EDGE_NAMESPACE}|g" ${CURRENT_PATH}/conf/edge.yaml
   176      sed -i "s|hostname-override: .*|hostname-override: ${NODE_HOST_NAME}|g" ${CURRENT_PATH}/conf/edge.yaml
   177      sed -i "s|device-plugin-enabled: .*|device-plugin-enabled: ${ENABLE_GPU}|g" ${CURRENT_PATH}/conf/edge.yaml
   178      sed -i "s|gpu-plugin-enabled: .*|gpu-plugin-enabled: ${ENABLE_GPU}|g" ${CURRENT_PATH}/conf/edge.yaml
   179      sed -i "s|api-version: .*|api-version: ${DIS_API_VERSION}|g" ${CURRENT_PATH}/conf/edge.yaml
   180      sed -i "s|region: .*|region: ${REGION}|g" ${CURRENT_PATH}/conf/edge.yaml
   181      sed -i "s|obs_endpoint: .*|obs_endpoint: ${OBS_URL}|g" ${CURRENT_PATH}/conf/edge.yaml
   182  }
   183  
   184  
   185  create_system_config
   186  parse_config
   187  create_edge_config