build-guest: accept extra RPMs on command line

- Accept additional RPM file names or package names to be installed into
  the guest image
- Don't fail if build-info/release-info.inc doesn't exist

Story: 2009108
Task: 42968

Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
Change-Id: Id532f3cfcd7bb16d8ca4c6bdf7615fe6d79f41b1
This commit is contained in:
Davlet Panech 2021-08-13 13:11:07 -04:00
parent 0f1e54c8be
commit 55fdee2aee
1 changed files with 51 additions and 14 deletions

View File

@ -101,12 +101,11 @@ function check_vars {
RELEASE_INFO="$(get_release_info)"
if [ $? -ne 0 ]; then
echo "ERROR: failed to find a release info file."
exit 1
echo "WARNING: failed to find a release info file."
else
export PLATFORM_RELEASE=$(source "$RELEASE_INFO" && echo $PLATFORM_RELEASE)
fi
export PLATFORM_RELEASE=$(source "$RELEASE_INFO" && echo $PLATFORM_RELEASE)
}
@ -169,7 +168,7 @@ function create_rootfs {
exit 1
fi
$MOCK -r $GUEST_CFG --install ${INC_RPM_LIST} ${TIS_RPM_LIST} ${EXTRA_REPOS}
$MOCK -r $GUEST_CFG ${EXTRA_REPOS} --install ${INC_RPM_LIST} ${TIS_RPM_LIST} "$@"
if [ $? -ne 0 ]; then
printf "=====\n"
cat $GUEST_DIR/mock/result/root.log | sed -n '/Error:/,$p' | sed '/Child return code was:/q'
@ -180,18 +179,33 @@ function create_rootfs {
# Make sure all requested packages are installed
MISSING=$(
$MOCK -r $GUEST_CFG --chroot -- rpm -q --whatprovides ${INC_RPM_LIST} ${TIS_RPM_LIST} \
| tee /tmp/dpanech.log \
extra_rpm_names="$(
for p in "$@" ; do
# skip URLs
if [[ "$p" =~ :// ]] ; then
continue
fi
# if it contains a slash or ends with .rpm, assume its a local file
# and read its embedded package name
if [[ "$p" =~ / || "$p" =~ [.]rpm$ ]] ; then
rpm -q --qf '%{name}\n' -p "$p"
# otherwise assume its a package name already
else
echo "$p"
fi
done
)"
$MOCK -r $GUEST_CFG --chroot -- rpm -q --whatprovides ${INC_RPM_LIST} ${TIS_RPM_LIST} $extra_rpm_names \
| sed -n 's/^no package provides //p' \
| sort -u
)
if [ -n "$MISSING" ]; then
printf "=====\n"
printf "WARNING: The following RPMs requested in .inc files are missing or could not be installed:\n"
for zz in $MISSING ; do
echo " [$zz]"
printf "WARNING: The following RPMs are missing or could not be installed:\n"
local p
for p in $MISSING ; do
echo " [$p]"
done
#echo $MISSING | tr ' ' '\n' | sed 's/^/\t/'
printf "=====\n"
fi
@ -306,7 +320,7 @@ function clean_guest {
$MOCK -r $GUEST_CFG --scrub=cache
rm -rf $GUEST_DIR
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
printf " Error -- Failed to remove guest $GUEST_DIR\n";
exit 1
fi
@ -321,10 +335,11 @@ function clean_guest {
usage () {
echo ""
echo "Usage: "
echo " build-guest [--rt | --std] [--verbose]"
echo " build-guest [--rt | --std] [--verbose] [EXTRA_RPMS...]"
echo " build-guest [--help]"
echo " build-guest [--clean]"
echo ""
echo "EXTRA_RPMS are either package names or full RPM file paths"
}
# Default argument values
@ -355,6 +370,28 @@ if [ $HELP -eq 1 ]; then
exit 0
fi
if [[ $CLEAN -eq 1 && "$#" -gt 0 ]] ; then
echo "Too many arguments!" >&2 ; exit 1
else
# make sure extra RPM files exist
for p in "$@" ; do
# skip URLs
if [[ "$p" =~ :// ]] ; then
continue
fi
# if it contains a slash or ends with .rpm assume its a local file name
if [[ "$p" =~ / || "$p" =~ [.]rpm$ ]] ; then
# make sure it exists and is an RPM file
true <"$p" || exit 1
if ! file --brief --mime-type "$p" | grep -q "^application/x-rpm$" ; then
echo "$p: not an RPM file" >&2
exit 1
fi
fi
done
unset p
fi
(
printf "\n*****************************\n"
printf "Create Titanium Cloud/CentOS Guest Image\n"
@ -368,7 +405,7 @@ if [ $CLEAN -eq 1 ]; then
exit 0
fi
create_rootfs
create_rootfs "$@"
update_rootfs
build_image