github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/utils/virtcontainers-setup.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2017,2018 Intel Corporation
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  set -e
     9  
    10  SCRIPT_PATH=$(dirname $(readlink -f $0))
    11  
    12  if [ ! $(command -v go) ]; then
    13  	echo "This script requires go to be installed and executable"
    14  	exit 1
    15  fi
    16  
    17  GOPATH=$(go env "GOPATH")
    18  
    19  if [ ! $(command -v docker) ]; then
    20  	echo "This script requires docker to be installed and executable"
    21  	exit 1
    22  fi
    23  
    24  if [ ! $(command -v git) ]; then
    25  	echo "This script requires git to be installed and executable"
    26  	exit 1
    27  fi
    28  
    29  tmpdir=$(mktemp -d)
    30  virtcontainers_build_dir="virtcontainers/build"
    31  echo -e "Create temporary build directory ${tmpdir}/${virtcontainers_build_dir}"
    32  mkdir -p ${tmpdir}/${virtcontainers_build_dir}
    33  
    34  TMPDIR="${SCRIPT_PATH}/supportfiles"
    35  OPTDIR="/opt"
    36  ETCDIR="/etc"
    37  
    38  echo -e "Create ${TMPDIR}/cni/bin (needed by testing)"
    39  rm -rf ${TMPDIR}/cni/bin
    40  mkdir -p ${TMPDIR}/cni/bin
    41  echo -e "Create cni directories ${OPTDIR}/cni/bin and ${ETCDIR}/cni/net.d"
    42  sudo mkdir -p ${OPTDIR}/cni/bin
    43  sudo mkdir -p ${ETCDIR}/cni/net.d
    44  
    45  bundlesdir="${TMPDIR}/bundles"
    46  echo -e "Create bundles in ${bundlesdir}"
    47  rm -rf ${bundlesdir}
    48  busybox_bundle="${bundlesdir}/busybox"
    49  mkdir -p ${busybox_bundle}
    50  docker pull busybox
    51  pushd ${busybox_bundle}
    52  rootfsdir="rootfs"
    53  mkdir ${rootfsdir}
    54  docker export $(docker create busybox) | tar -C ${rootfsdir} -xvf -
    55  echo -e '#!/bin/sh\ncd "\"\n"sh"' > ${rootfsdir}/.containerexec
    56  echo -e 'HOME=/root\nPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\nTERM=xterm' > ${rootfsdir}/.containerenv
    57  popd
    58  
    59  echo -e "Move to ${tmpdir}/${virtcontainers_build_dir}"
    60  pushd ${tmpdir}/${virtcontainers_build_dir}
    61  echo "Clone cni"
    62  git clone https://github.com/containernetworking/plugins.git
    63  pushd plugins
    64  git checkout 7f98c94613021d8b57acfa1a2f0c8d0f6fd7ae5a
    65  
    66  echo "Copy CNI config files"
    67  cp $GOPATH/src/github.com/kata-containers/runtime/virtcontainers/test/cni/10-mynet.conf ${ETCDIR}/cni/net.d/
    68  cp $GOPATH/src/github.com/kata-containers/runtime/virtcontainers/test/cni/99-loopback.conf ${ETCDIR}/cni/net.d/
    69  
    70  ./build.sh
    71  cp ./bin/bridge ${TMPDIR}/cni/bin/cni-bridge
    72  cp ./bin/loopback ${TMPDIR}/cni/bin/loopback
    73  cp ./bin/host-local ${TMPDIR}/cni/bin/host-local
    74  popd
    75  popd
    76  sudo cp ${TMPDIR}/cni/bin/* ${OPTDIR}/cni/bin/
    77  
    78  rm -rf ${tmpdir}