kata-containers/tools/osbuilder/dracut/add_libs.sh
Jakob Naucke b8133a188c
osbuilder/dracut: Add missing libraries
When the guest is built using dracut and the agent uses glibc (esp.
ppc64le/s390x), libraries might be missing. In my case, it was
`libutil.so`, but more can be added easily. Add a script to configure
`install_items` for dracut w.r.t. `ldd` of the agent.

Fixes: #2384
Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
2021-08-04 13:50:42 +02:00

51 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2021 IBM Corp.
#
# SPDX-License-Identifier: Apache-2.0
script_name="$(basename "$0")"
usage() {
cat >&2 << EOF
Usage: ${script_name} [-h] <agent-binary>
Output dracut configuration with required additional libraries for the Kata agent.
Example:
${script_name} \$GOPATH/src/github.com/kata-containers/kata-containers/src/agent/target/x86_64-unknown-linux-gnu/release/kata-agent
Options:
-h: Show this help
EOF
exit "$1"
}
if [[ $# != 1 || "$1" == "-h" ]]; then
usage 0
fi
agent_binary="$1"
non_standard_libs=("libutil.so")
install_items=""
if [ ! -x "${agent_binary}" ]; then
echo >&2 "ERROR: ${agent_binary} is not an executable file"
usage 1
fi
# Cover both cases of "not a dynamic executable" being printed to STDERR
# and "statically linked" being printed to STDOUT
linked_libs="$(ldd "${agent_binary}" 2>&1)"
if [ "$(wc -l <<< "${linked_libs}")" == 1 ]; then
echo >&2 "Agent appears to be linked statically, exiting"
exit 0
fi
for lib in "${non_standard_libs[@]}"; do
install_items+=" $(grep -F "${lib}" <<< "${linked_libs}" | cut -d" " -f3)"
done
cat << EOF
# add libraries that the Kata agent is linked against, but that are not included by default
install_items+="${install_items} "
EOF