Files
kata-containers/tools/osbuilder/rootfs-builder/ubuntu/rootfs_lib.sh
Fabiano Fidêncio 483407b216 tools: Fix shellcheck issues in rootfs_lib.sh
Fix shellcheck warnings and notes identified by running
shellcheck --severity=style.

Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
2026-04-24 08:14:08 +02:00

44 lines
1.5 KiB
Bash

#!/usr/bin/env bash
#
# Copyright (c) 2018 Yash Jain, 2022 IBM Corp.
#
# SPDX-License-Identifier: Apache-2.0
build_rootfs() {
local rootfs_dir=$1
# This fixes the spurious error
# E: Can't find a source to download version '2021.03.26' of 'ubuntu-keyring:amd64'
apt update
# focal version of mmdebstrap only supports comma separated package lists
# shellcheck disable=SC2154
if [[ "${OS_VERSION}" = "focal" ]]; then
PACKAGES=$(echo "${PACKAGES}" | tr ' ' ',')
EXTRA_PKGS=$(echo "${EXTRA_PKGS}" | tr ' ' ',')
fi
# shellcheck disable=SC2154
if ! mmdebstrap --mode auto --arch "${DEB_ARCH}" --variant required \
--components="${REPO_COMPONENTS}" \
--include "${PACKAGES},${EXTRA_PKGS}" "${OS_VERSION}" "${rootfs_dir}" "${REPO_URL}"; then
echo "ERROR: mmdebstrap failed, cannot proceed" && exit 1
else
echo "INFO: mmdebstrap succeeded"
fi
rm -rf "${rootfs_dir}/var/run"
ln -s /run "${rootfs_dir}/var/run"
cp --remove-destination /etc/resolv.conf "${rootfs_dir}/etc"
local dir="${rootfs_dir}/etc/ssl/certs"
mkdir -p "${dir}"
cp --remove-destination /etc/ssl/certs/ca-certificates.crt "${dir}"
# Reduce image size and memory footprint by removing unnecessary files and directories.
rm -rf "${rootfs_dir}"/usr/share/{bash-completion,bug,doc,info,lintian,locale,man,menu,misc,pixmaps,terminfo,zsh}
# Minimal set of device nodes needed when AGENT_INIT=yes so that the
# kernel can properly setup stdout/stdin/stderr for us
pushd "${rootfs_dir}/dev" || return
MAKEDEV -v console tty ttyS null zero fd
popd || return
}