update/cgcs-patch/bin/upgrade-start-pkg-extract
Carmen Rata cf8fc1bfff Update upgrade-start-pkg-extract to use dnf package
This commit replaces the use of "repoquery" in the
upgrade-start-pkg-extract utility with "dnf repoquery".

Story: 2007403
Task: 39059
Change-Id: I8bc86af11cc7adc85b6d5d30f3a7368581c7988c
Signed-off-by: Carmen Rata <carmen.rata@windriver.com>
2020-03-13 16:57:13 -04:00

136 lines
3.2 KiB
Bash

#!/bin/bash
#
# Copyright (c) 2018 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
function show_usage()
{
cat >&2 <<EOF
$(basename $0): -r <release>
This tool will extract required packages to support upgrade-start
Options:
-r <release> : Release ID for target release.
EOF
exit 1
}
. /etc/build.info
if [ -z "${SW_VERSION}" ]; then
logger -t $0 "Unable to identify running release ID"
exit 1
fi
declare TGT_RELEASE=
while getopts "r:h" opt; do
case $opt in
r)
TGT_RELEASE=$OPTARG
;;
h)
show_usage
;;
*)
logger -t $0 "Unsupported option"
show_usage
;;
esac
done
if [ -z "${TGT_RELEASE}" ]; then
logger -t $0 "You must specify the target release."
exit 1
fi
if [ "${TGT_RELEASE}" = "${SW_VERSION}" ]; then
logger -t $0 "Target release cannot be running release."
exit 1
fi
declare TGT_BASE_REPO=/www/pages/feed/rel-${TGT_RELEASE}
declare TGT_PATCHES_REPO=/www/pages/updates/rel-${TGT_RELEASE}
if [ ! -d ${TGT_BASE_REPO} ]; then
logger -t $0 "Target release ${TGT_RELEASE} is not installed"
exit 1
fi
declare TGT_PATCHES_REPO_OPT=""
if [ -d ${TGT_PATCHES_REPO} ]; then
TGT_PATCHES_REPO_OPT="--repofrompath updates,${TGT_PATCHES_REPO}"
fi
declare WORKDIR=
function cleanup() {
if [ -n "${WORKDIR}" -a -d "${WORKDIR}" ]; then
rm -rf ${WORKDIR}
fi
}
trap cleanup EXIT
function extract_pkg() {
local pkgname=$1
ORIG_PWD=$PWD
cd $WORKDIR
# Find the RPM
local pkgfile=$(dnf repoquery --repofrompath base,${TGT_BASE_REPO} ${TGT_PATCHES_REPO_OPT} --location -q ${pkgname})
if [ -z "${pkgfile}" ]; then
logger -t $0 "Could not find ${pkgname}"
exit 1
fi
# Chop off the file: from the start of the file location
local rpmfile=${pkgfile/file://}
rpm2cpio ${rpmfile} | cpio -idm
if [ $? -ne 0 ]; then
logger -t $0 "Failed to extract $pkgname files from ${pkgfile/file://}"
exit 1
fi
cd ${ORIG_PWD}
}
# Extract files from pxe-network-installer
WORKDIR=$(mktemp -d --tmpdir=/scratch pkgextract_XXXX)
if [ -z "${WORKDIR}" -o ! -d "${WORKDIR}" ]; then
logger -t $0 "Failed to create workdir"
exit 1
fi
extract_pkg pxe-network-installer
rsync -ac ${WORKDIR}/usr/ /usr/ &&
rsync -ac ${WORKDIR}/pxeboot/rel-${TGT_RELEASE}/ /pxeboot/rel-${TGT_RELEASE}/ &&
rsync -c ${WORKDIR}/pxeboot/pxelinux.cfg.files/*-${TGT_RELEASE} /pxeboot/pxelinux.cfg.files/ &&
rsync -ac ${WORKDIR}/www/pages/feed/rel-${TGT_RELEASE}/ /www/pages/feed/rel-${TGT_RELEASE}/
if [ $? -ne 0 ]; then
logger -t $0 "rsync command failed, extracting pxe-network-installer"
exit 1
fi
rm -rf ${WORKDIR}
# Extract files from platform-kickstarts
WORKDIR=$(mktemp -d --tmpdir=/scratch pkgextract_XXXX)
if [ -z "${WORKDIR}" -o ! -d "${WORKDIR}" ]; then
logger -t $0 "Failed to create workdir"
exit 1
fi
extract_pkg platform-kickstarts
rsync -ac ${WORKDIR}/www/pages/feed/rel-${TGT_RELEASE}/ /www/pages/feed/rel-${TGT_RELEASE}/
if [ $? -ne 0 ]; then
logger -t $0 "rsync command failed, extracting platform-kickstarts"
exit 1
fi
rm -rf ${WORKDIR}
exit 0