|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2024 The Kuasar Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +make_vmm_task() { |
| 17 | + local repo_dir="$1" |
| 18 | + |
| 19 | + yum install -y cmake make gcc-c++ wget |
| 20 | + |
| 21 | + # update cert file under internal proxy scenario |
| 22 | + if [ -f "${cert_file_path}" ]; then |
| 23 | + cp ${cert_file_path} /etc/pki/ca-trust/source/anchors/ |
| 24 | + update-ca-trust extract |
| 25 | + fi |
| 26 | + |
| 27 | + # install rust to compile vmm-task |
| 28 | + pushd ${repo_dir} |
| 29 | + |
| 30 | + source vmm/scripts/image/install_rust.sh |
| 31 | + |
| 32 | + make bin/vmm-task ARCH=${ARCH} |
| 33 | + popd |
| 34 | +} |
| 35 | + |
| 36 | +install_golang() { |
| 37 | + pushd /home/ |
| 38 | + arch_name="" |
| 39 | + if [ "${ARCH}" == "aarch64" ]; then |
| 40 | + arch_name="arm64" |
| 41 | + elif [ "${ARCH}" == "x86_64" ]; then |
| 42 | + arch_name="amd64" |
| 43 | + else |
| 44 | + echo "Unsupported arch: ${ARCH}" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + rm -f go${golang_version}.linux-${arch_name}.tar.gz |
| 48 | + wget -q "https://go.dev/dl/go${golang_version}.linux-${arch_name}.tar.gz" |
| 49 | + rm -rf /usr/local/go && tar -C /usr/local -xzf "go${golang_version}.linux-${arch_name}.tar.gz" |
| 50 | + echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile |
| 51 | + source /etc/profile |
| 52 | + go version |
| 53 | + popd |
| 54 | +} |
| 55 | + |
| 56 | +build_runc() { |
| 57 | + local repo_dir="$1" |
| 58 | + mkdir -p /tmp/gopath |
| 59 | + GOPATH=/tmp/gopath go install github.com/opencontainers/ [email protected] |
| 60 | + cp /tmp/gopath/bin/runc ${repo_dir}/bin/ |
| 61 | +} |
| 62 | + |
| 63 | +create_tmp_rootfs() { |
| 64 | + local rootfs_dir="$1" |
| 65 | + rm -rf ${rootfs_dir}/* |
| 66 | + mkdir -p ${rootfs_dir}/lib \ |
| 67 | + ${rootfs_dir}/lib64 \ |
| 68 | + ${rootfs_dir}/lib/modules |
| 69 | + |
| 70 | + mkdir -m 0755 -p ${rootfs_dir}/dev \ |
| 71 | + ${rootfs_dir}/sys \ |
| 72 | + ${rootfs_dir}/sbin \ |
| 73 | + ${rootfs_dir}/bin \ |
| 74 | + ${rootfs_dir}/tmp \ |
| 75 | + ${rootfs_dir}/proc \ |
| 76 | + ${rootfs_dir}/etc \ |
| 77 | + ${rootfs_dir}/run \ |
| 78 | + ${rootfs_dir}/var |
| 79 | + |
| 80 | + ln -s ../run ${rootfs_dir}/var/run |
| 81 | + touch ${rootfs_dir}/etc/resolv.conf |
| 82 | +} |
| 83 | + |
| 84 | +install_and_copy_rpm() { |
| 85 | + set +e |
| 86 | + local rpm_list_file="$1" |
| 87 | + local rootfs_dir="$2" |
| 88 | + cat ${rpm_list_file} | while read rpm; do |
| 89 | + if [ "${rpm:0:1}" != "#" ]; then |
| 90 | + rpm -ql $rpm >/dev/null 2>&1 |
| 91 | + if [ $? -ne 0 ]; then |
| 92 | + yum install -y $rpm >/dev/null 2>&1 |
| 93 | + if [ $? -ne 0 ]; then |
| 94 | + echo "Can not install $rpm by yum" |
| 95 | + continue |
| 96 | + fi |
| 97 | + rpm -ql $rpm >/dev/null 2>&1 || continue |
| 98 | + fi |
| 99 | + array=($(rpm -ql $rpm | grep -v "share" | grep -v ".build-id")) |
| 100 | + for file in ${array[@]}; do |
| 101 | + source=$file |
| 102 | + dst_file=${rootfs_dir}$file |
| 103 | + dst_folder=${dst_file%/*} |
| 104 | + if [ ! -d "$dst_folder" ] && [ ! -L "$dst_folder" ]; then |
| 105 | + mkdir -p $dst_folder |
| 106 | + fi |
| 107 | + cp -r -f -d $source $dst_folder |
| 108 | + done |
| 109 | + fi |
| 110 | + done |
| 111 | + set -e |
| 112 | +} |
| 113 | + |
| 114 | +copy_binaries() { |
| 115 | + local binaries_list_file="$1" |
| 116 | + local rootfs_dir="$2" |
| 117 | + cat $binaries_list_file | while read line; do |
| 118 | + if [ -n "${line}" ] && [ "${line:0:1}" != "#" ]; then |
| 119 | + source=$(echo "${line}" | awk '{print $1}') |
| 120 | + des=$(echo "${line}" | awk '{print $2}') |
| 121 | + if [ ! -d "$des" ]; then |
| 122 | + mkdir -p $des |
| 123 | + fi |
| 124 | + cp -r -d $source ${rootfs_dir}/$des |
| 125 | + fi |
| 126 | + done |
| 127 | +} |
| 128 | + |
| 129 | +copy_libs() { |
| 130 | + local binaries_list_file="$1" |
| 131 | + local rootfs_dir="$2" |
| 132 | + binaries_list=$(cat $binaries_list_file | grep -v "#" | awk '{print $1}') |
| 133 | + binaries_list=(${binaries_list[@]} ${rootfs_dir}/sbin/init) |
| 134 | + for bin in ${binaries_list[@]}; do |
| 135 | + ldd ${bin} | while read line; do |
| 136 | + arr=(${line// / }) |
| 137 | + |
| 138 | + for lib in ${arr[@]}; do |
| 139 | + echo $lib |
| 140 | + if [ "${lib:0:1}" = "/" ]; then |
| 141 | + dir=${rootfs_dir}/$(dirname $lib) |
| 142 | + mkdir -p "${dir}" |
| 143 | + cp -f $lib $dir |
| 144 | + fi |
| 145 | + done |
| 146 | + done |
| 147 | + done |
| 148 | +} |
0 commit comments