metal/bsp-files/upgrades/import.sh
Guilherme Schons bf5162bc20 Add patch extract from load
This commit adds extracting the patches files (metadata) from the
load being imported.

Test Plan:
    Passed: load from previous version imported as inactive
    Passed: load from new version imported

Story: 2010611
Task: 48546

Change-Id: I12a2c9f62523f6b08294f2538ad77b5c8338a751
Signed-off-by: Guilherme Schons <guilherme.dossantosschons@windriver.com>
2023-08-08 12:15:00 -03:00

101 lines
3.0 KiB
Bash

#!/bin/bash
# Copyright (c) 2015-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script is run during the load-import command
# It is used to copy the required files from the iso to the
# controller.
set -e
exec 2>>/var/log/load-import.log
set -x
echo "$(date): Starting execution: $0 $@"
cleanup() {
rm -rf ${TMP_RPM}
}
rollback() {
rm -rf ${FEED_DIR}
}
error() {
local parent_lineno="$1"
local err_code="${2}"
echo "Error executing import script at line: ${parent_lineno} with error code: ${err_code}"
rollback
exit "${err_code}"
}
trap 'error ${LINENO} $?' ERR
if [ -n "$1" ]; then
# mount point of the ISO to be imported.
# This is to import inactive load (an older load)
ISO_DIR=$1
UPGRADES_DIR="${ISO_DIR}/upgrades"
else
UPGRADES_DIR=$(dirname $0)
ISO_DIR=$(dirname ${UPGRADES_DIR})
fi
source ${UPGRADES_DIR}/version
source /etc/build.info
FEED_DIR=/var/www/pages/feed/rel-${VERSION}
# Feed directory is different in 21.12 vs. 22.06
CURRENT_FEED_DIR=/var/www/pages/feed/rel-${SW_VERSION}
if [ ${SW_VERSION} == "21.12" ]; then
CURRENT_FEED_DIR=/www/pages/feed/rel-${SW_VERSION}
FEED_DIR=/www/pages/feed/rel-${VERSION}
fi
rm -rf ${FEED_DIR}
mkdir -p ${FEED_DIR}
# copy pxeboot, kickstart, ostree_repo to feed directory
echo "Copy kickstart to ${FEED_DIR}"
cp -rp ${ISO_DIR}/kickstart ${FEED_DIR}/
echo "Copy pxeboot to ${FEED_DIR}"
cp -rp ${ISO_DIR}/pxeboot ${FEED_DIR}/
echo "Copy ostree_repo to ${FEED_DIR}"
cp -rp ${ISO_DIR}/ostree_repo ${FEED_DIR}/
echo "Copy install_uuid to ${FEED_DIR}"
cp ${CURRENT_FEED_DIR}/install_uuid ${FEED_DIR}/
mkdir ${FEED_DIR}/upgrades
echo "Copy pxeboot-update-${VERSION}.sh to ${FEED_DIR}/upgrades"
cp ${ISO_DIR}/upgrades/pxeboot-update-${VERSION}.sh ${FEED_DIR}/upgrades/
echo "Copy efi.img to ${FEED_DIR}"
cp ${ISO_DIR}/efi.img ${FEED_DIR}/
# for upgrade from 22.06 to Debian 22.12, patch during upgrade is not supported
echo "Copy pxeboot-update-${SW_VERSION}.sh to ${CURRENT_FEED_DIR}/upgrades"
mkdir -p ${CURRENT_FEED_DIR}/upgrades/
# In stx 8.0, the pxeboot-update-22.12.sh is in /usr/sbin
# In stx 9.0, the pxeboot-update-23.09.sh is in /etc due to the ostree managed
# /usr directory.
cp -rp /usr/sbin/pxeboot-update-22.12.sh ${CURRENT_FEED_DIR}/upgrades/ 2>/dev/null || \
cp -rp /etc/pxeboot-update-${SW_VERSION}.sh ${CURRENT_FEED_DIR}/upgrades/
# The pxelinux.cfg.files directory is from the current release feed in Debian.
echo "Copy pxelinux.cfg.files directory to ${CURRENT_FEED_DIR}"
mkdir -p ${CURRENT_FEED_DIR}/pxeboot/pxelinux.cfg.files/
find /var/pxeboot/pxelinux.cfg.files -type f ! -name "*${VERSION}" \
-exec cp -p {} ${CURRENT_FEED_DIR}/pxeboot/pxelinux.cfg.files/ \;
if [ -d ${ISO_DIR}/patches ]; then
rsync --mkpath -ac ${ISO_DIR}/patches/ /opt/patching/metadata/committed/
# copy patch metadata to feed, so to be picked up by kickstart to copy to release N+1
mkdir ${CURRENT_FEED_DIR}/patches -p
cp -a ${ISO_DIR}/patches/* ${CURRENT_FEED_DIR}/patches/
fi
echo 'import has completed'