metal/bsp-files/kickstarts/post_miniboot_controller.cfg

505 lines
18 KiB
INI

%pre --erroronfail
# Source common functions
. /tmp/ks-functions.sh
SW_VERSION=xxxPLATFORM_RELEASExxx
STAGING_DIR="platform-backup"
BACKUP_PART_LABEL=Platform\\x20Backup
BACKUP_DEVICE=/dev/disk/by-partlabel/${BACKUP_PART_LABEL}
BACKUP_MOUNT=/mnt/${STAGING_DIR}
BOOTIMAGE_ISO=""
BOOTIMAGE_MOUNT=/mnt/bootimage
PRESTAGE_DIR=${BACKUP_MOUNT}/${SW_VERSION}
KS="Miniboot pre:"
wlog "${KS} local install check"
iso_check=false
iso_mount=false
prestaging_files=false
# Look for and validate the local iso image
if [ -e ${BACKUP_DEVICE} ]; then
mkdir -p ${BACKUP_MOUNT}
mount ${BACKUP_DEVICE} ${BACKUP_MOUNT} 2>/dev/null
rc=$?
if [ $rc -eq 0 ] ; then
sleep 2
# does the prestaging dir for the specified sw version exist
if [ -d "${BACKUP_MOUNT}/${SW_VERSION}" ] ; then
# are there files in it ?
if [ "$(ls -A ${BACKUP_MOUNT}/${SW_VERSION})" ] ; then
# change to prestaging dir and load the file names
cd ${BACKUP_MOUNT}/${SW_VERSION}
# Local Install Bundle Validation:
#
# ISO Image: There must be an iso image whose base
# filename matches an md5 check file and
# that check must pass.
#
# Container Images: Missing container image check file(s) or
# container image validation check failure
# does not reject a Local Install.
#
# Find the iso image first.
# - there should be only one so use the first one found
# just in case there are others there.
# Loop over the files if there are any looking for the iso
iso_filename=""
for file in $(ls -A .) ; do
prestaging_files=true
filename="${file%.*}"
extension="${file##*.}"
if [ "${extension}" = "iso" ] ; then
iso_filename="${filename}"
# Found the iso name for the mount operation below
BOOTIMAGE_ISO=${BACKUP_MOUNT}/${SW_VERSION}/${file}
wlog "${KS} found prestaged iso image ${BOOTIMAGE_ISO}"
if [ -f ${filename}.md5 ] ; then
md5sum -c "${filename}.md5"
if [ $? -eq 0 ] ; then
wlog "${KS} ${file} iso check passed"
iso_check=true
mkdir -p ${BOOTIMAGE_MOUNT}
mount -o loop ${BOOTIMAGE_ISO} ${BOOTIMAGE_MOUNT}
if [ $? -eq 0 ] ; then
iso_mount=true
wlog "${KS} local iso mounted ${BOOTIMAGE_MOUNT}"
else
wlog "${KS} local iso mount failed"
fi
else
wlog "${KS} ${file} iso check failed"
fi
else
wlog "${KS} no iso image check file found ${filename}.md5"
fi
break
fi
done
# Loop over the files again this time to run checks
# on md5 files that are not the iso.
# Such files are expected to be checks for container image sets.
# Failure of container image sets check will not reject
# the local install.
for file in $(ls -A .) ; do
prestaging_files=true
filename="${file%.*}"
extension="${file##*.}"
if [ "${extension}" = "md5" -a "${filename}" != "${iso_filename}" ] ; then
wlog "${KS} prestaged file : ${file}"
md5sum -c "${file}"
if [ $? -eq 0 ] ; then
wlog "${KS} ${file} check passed"
else
wlog "${KS} ${file} check failed"
fi
fi
done
fi
if [ "${prestaging_files}" = false ] ; then
wlog "${KS} no prestaged files"
fi
else
wlog "${KS} Error: ${BACKUP_MOUNT} not mounted"
fi
else
wlog "${KS} mount of ${BACKUP_DEVICE} to ${BACKUP_MOUNT} failed rc:$rc"
fi
else
wlog "${KS} backup device ${BACKUP_DEVICE} does not exist"
fi
if [ "${iso_check}" = true -a "${iso_mount}" = true ] ; then
wlog "${KS} Local Install ready"
fi
if [ "${iso_mount}" = false ] ; then
wlog "${KS} Prestage ISO is not available"
fi
# Make sure the prestage directory exists, as well as the required subdirectories.
exists_prestage=false
if [ ! -e ${PRESTAGE_DIR} ] || [ ! -e ${PRESTAGE_DIR}/Packages ] || [ ! -e ${PRESTAGE_DIR}/repodata ]; then
exists_prestage=false
else
exists_prestage=true
fi
#
# This controls where the packages come from.
# Lower cost has higher priority ; making local install preferred.
#
# If ${BOOTIMAGE_MOUNT} exists then install from local iso - Local Install
# Otherwise, they are fetched from platform backup if the Packages have been
# prestaged.
# If this fails, they are fetched from the System Controller - Remote Install
#
if [ "${exists_prestage}" = true ]; then
wlog "${KS} Prestage directory found: ${PRESTAGE_DIR}"
cat << EOF > /tmp/repo-include
repo --name=local-base --cost=100 --baseurl=file://${BOOTIMAGE_MOUNT}/
repo --name=local-updates --cost=100 --baseurl=file://${BOOTIMAGE_MOUNT}/patches/
repo --name=local-base --cost=200 --baseurl=file://${PRESTAGE_DIR}/
repo --name=local-updates --cost=200 --baseurl=file://${PRESTAGE_DIR}/patches/
repo --name=remote-base --cost=300 --baseurl=xxxHTTP_URLxxx/
repo --name=remote-updates --cost=300 --baseurl=xxxHTTP_URLxxx/patches/
EOF
else
wlog "${KS} Packages will either be retrieved from prestage iso or downloaded"
cat << EOF > /tmp/repo-include
repo --name=local-base --cost=100 --baseurl=file://${BOOTIMAGE_MOUNT}/
repo --name=local-updates --cost=100 --baseurl=file://${BOOTIMAGE_MOUNT}/patches/
repo --name=remote-base --cost=200 --baseurl=xxxHTTP_URLxxx/
repo --name=remote-updates --cost=200 --baseurl=xxxHTTP_URLxxx/patches/
EOF
fi
%end
# Repository arguments from %pre
%include /tmp/repo-include
%post --erroronfail
# Source common functions
. /tmp/ks-functions.sh
KS="Miniboot post:"
# wlog "${KS} cmdLine: $(cat /proc/cmdline)"
if [ -e /dev/disk/by-label/oe_iso_boot ]; then
# This is a hybrid ISO/network install. Mount the media to ensure Anaconda
# ejects it on reboot.
mkdir /mnt/iso
wlog "${KS} mount for eject"
mount /dev/disk/by-label/oe_iso_boot /mnt/iso
else
wlog "${KS} /dev/disk/by-label/oe_iso_boot does not exist"
fi
# persist the default http port number to platform configuration. This
# will get overwritten when config_controller is run.
echo http_port=8080 >> /etc/platform/platform.conf
# Build networking scripts
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
IPV6_AUTOCONF=no
NAME=loopback
EOF
%end
%post --nochroot --erroronfail
# Source common functions
. /tmp/ks-functions.sh
# Mirror local software repositories
SYSIMAGE_MOUNT=/mnt/sysimage
FEED_DIR=${SYSIMAGE_MOUNT}/var/www/pages/feed/rel-xxxPLATFORM_RELEASExxx
UPDATES_DIR=${SYSIMAGE_MOUNT}/var/www/pages/updates/rel-xxxPLATFORM_RELEASExxx
PATCHING_DIR=${SYSIMAGE_MOUNT}/opt/patching
PACKAGES_DIR=${PATCHING_DIR}/packages/xxxPLATFORM_RELEASExxx/
KS="Miniboot post:"
if [ -d ${SYSIMAGE_MOUNT} ] ; then
files="$(ls -lrt ${SYSIMAGE_MOUNT})"
wlog "${KS} ${SYSIMAGE_MOUNT} files : $files[@]"
if [ -d ${FEED_DIR} ] ; then
files=$(ls -lrt ${FEED_MOUNT})
wlog "${KS} $FEED_DIR files : $files[@]"
else
wlog "${KS} error : feed dir '$FEED_DIR' does not exist"
fi
# Check updates Dir
if [ -d ${UPDATES_DIR} ] ; then
files=$(ls -lrt ${UPDATES_DIR})
wlog "${KS} $UPDATES_DIR files : $files[@]"
else
wlog "${KS} $UPDATES_DIR does not exist"
fi
# Check Packages Dir
if [ -d ${PATCHING_DIR} ] ; then
files=$(ls -lrt ${PATCHING_DIR})
wlog "${KS} $PATCHING_DIR files : $files[@]"
if [ -d ${PATCHING_DIR}/metadata ] ; then
files=$(ls -lrt ${PATCHING_DIR}/metadata)
wlog "${KS} $PATCHING_DIR/metadata files : $files[@]"
if [ -d ${PATCHING_DIR}/metadata/applied ] ; then
files=$(ls -lrt ${PATCHING_DIR}/metadata/applied)
wlog "${KS} $PATCHING_DIR/metadata/applied files : $files[@]"
else
wlog "${KS} $PATCHING_DIR/metadata/applied does not exist"
fi
if [ -d ${PATCHING_DIR}/metadata/available ] ; then
files=$(ls -lrt ${PATCHING_DIR}/metadata/available)
wlog "${KS} $PATCHING_DIR/metadata/available files : $files[@]"
else
wlog "${KS} $PATCHING_DIR/metadata/available does not exist"
fi
else
wlog "${KS} $PATCHING_DIR/metadata does not exist"
fi
else
wlog "${KS} $PATCHING_DIR does not exist"
fi
# Check Packages Dir
if [ -d ${PACKAGES_DIR} ] ; then
files=$(ls -lrt ${PACKAGES_DIR})
wlog "${KS} $PACKAGES_DIR files : $files[@]"
else
wlog "${KS} $PACKAGES_DIR does not exist"
fi
wlog "${KS} end of sysimage_mount ${SYSIMAGE_MOUNT}"
else
wlog "${KS} Error : $SYSIMAGE_MOUNT does not exists or is not a directory"
fi
# # Handle 3 prestaging conditions
#
# 1. Full local install ; iso present in platform-backup/rel
# 2. Prioritized install ; use prestaged content and fetch what's missing remotely
# 3. Full remote install ; no prestaging content in platform-backup/rel
if [ -d /mnt/bootimage ]; then
wlog "${KS} /mnt/bootimage"
srcdir=/mnt/bootimage
elif [ -d /mnt/platform-backup/xxxPLATFORM_RELEASExxx ] ; then
wlog "${KS} looking for packages in /mnt/platform_backup"
srcdir=/mnt/platform-backup/xxxPLATFORM_RELEASExxx
else
# Remote System Controller
wlog "${KS} /mnt/install/source"
srcdir=/mnt/install/source
fi
need_packages=false
need_patches=false
# prepare to boot other hosts by mirroring sw repository
if [ -d $srcdir/Packages ] ; then
wlog "${KS} copying software repository $srcdir/Packages"
mkdir -p ${FEED_DIR}
packagefilecount=$(ls ${srcdir}/Packages | wc -l)
if [ ${packagefilecount} = 0 ]; then
wlog "${KS} ${srcdir}/Packages is empty. Fetching remotely"
need_packages=true
else
cp -r $srcdir/Packages ${FEED_DIR}/Packages
if [ -d $srcdir/repodata ] ; then
repodatafilecount=$(ls ${srcdir}/repodata | wc -l)
if [ ${repodatafilecount} = 0 ]; then
wlog "${KS} ${srcdir}/repodata is empty.Fetching remotely"
need_packages=true
else
cp -r $srcdir/repodata ${FEED_DIR}/repodata
fi
else
wlog "${KS} $srcdir/repodata dir does not exist. Fetching remotely"
need_packages=true
fi
fi
else
wlog "${KS} $srcdir/Packages not found. Fetching remotely"
need_packages=true
fi
if [ -d $srcdir/patches ]; then
if [ -d $srcdir/patches/Packages ] ; then
wlog "${KS} copying patch Packages $srcdir/patches/Packages"
mkdir -p ${UPDATES_DIR}
cp -r $srcdir/patches/Packages ${UPDATES_DIR}/Packages
else
wlog "${KS} $srcdir/patches/Packages does not exist. Fetching remotely"
need_patches=true
fi
if [ -d $srcdir/patches/repodata ] ; then
wlog "${KS} copying patch repository $srcdir/patches/repodata"
mkdir -p ${UPDATES_DIR}
cp -r $srcdir/patches/repodata ${UPDATES_DIR}/repodata
else
wlog "${KS} $srcdir/patches/repodata does not exist. Fetching remotely"
need_patches=true
fi
else
wlog "${KS} $srcdir/patches does not exist. Fetching remotely"
need_patches=true
fi
if [ -d $srcdir/patches/metadata -a "${need_patches}" = false ] ; then
mkdir -p ${PATCHING_DIR}
wlog "${KS} copying $srcdir/patches/metadata to ${PATCHING_DIR}"
cp -r $srcdir/patches/metadata ${PATCHING_DIR}/metadata
else
wlog "${KS} $srcdir/patches/metadata doesn't exist. Fetching remotely"
need_patches=true
fi
if [ -d $srcdir/patches -a "${need_patches}" = false ]; then
mkdir -p ${PACKAGES_DIR}
wlog "${KS} copying packages"
find ${UPDATES_DIR}/Packages -name '*.rpm' \
| xargs --no-run-if-empty -I files cp --preserve=all files ${PACKAGES_DIR}
else
wlog "${KS} $srcdir/patches doesn't exist: fetching remotely"
need_patches=true
fi
if [ "${need_packages}" = true ]; then
echo > ${SYSIMAGE_MOUNT}/tmp/needpackages
fi
if [ "${need_patches}" = true ]; then
echo > ${SYSIMAGE_MOUNT}/tmp/needpatches
fi
%end
%post --erroronfail
# Source common functions
. /tmp/ks-functions.sh
KS="Miniboot post:"
# Create a uuid specific to this installation
INSTALL_UUID=`uuidgen`
echo $INSTALL_UUID > /var/www/pages/feed/rel-xxxPLATFORM_RELEASExxx/install_uuid
echo "INSTALL_UUID=$INSTALL_UUID" >> /etc/platform/platform.conf
wlog "${KS} updating platform.conf with install uuid : ${INSTALL_UUID}"
# Mirror remote software repositories
anaconda_logdir=/var/log/anaconda
mkdir -p $anaconda_logdir
# Check for inst.noverifyssl
if grep -q inst.noverifyssl /proc/cmdline; then
NOVERIFYSSL_WGET_OPT="--no-check-certificate"
else
NOVERIFYSSL_WGET_OPT=""
fi
# If the path to $FEED_DIR does not exist then proceed to create it and
# fetch the ISO content in pieces from the system controller:
#
# - Packages
# - Repodata
#
FEED_DIR=/var/www/pages/feed/rel-xxxPLATFORM_RELEASExxx
declare -i cut_dirs=NUM_DIRS
declare need_packages=
declare need_patches=
if [ -f /tmp/needpackages ]; then
wlog "${KS} Packages need to be downloaded"
need_packages=true
rm /tmp/needpackages
else
need_packages=false
fi
if [ -f /tmp/needpatches ]; then
wlog "${KS} patches need to be downloaded"
need_patches=true
rm /tmp/needpatches
else
need_patches=false
fi
if ( [ ! -d "${FEED_DIR}/Packages" ] || [ ! -d "${FEED_DIR}/repodata" ] ) && [ "${need_packages}" = true ]; then
mkdir -p "${FEED_DIR}/Packages"
mkdir -p "${FEED_DIR}/repodata"
cd "${FEED_DIR}"
feed_url=xxxHTTP_URLxxx
wlog "${KS} Remote Install"
wlog "${KS} downloading software repository $feed_url"
# Fetch Packages
wget ${NOVERIFYSSL_WGET_OPT} --mirror --no-parent --no-host-directories --reject 'index.html*' \
--cut-dirs=$cut_dirs $feed_url/Packages/ -o $anaconda_logdir/rpmget.log \
|| report_post_failure_with_logfile $anaconda_logdir/rpmget.log
wlog "${KS} download of $feed_url/Packages/ complete"
# Fetch Repodata. In the case of "${need_packages} = yes", it is better to fetch
# both the Packages as well as the repodata (since repodata is correlated with the Packages)
wget ${NOVERIFYSSL_WGET_OPT} --mirror --no-parent --no-host-directories --reject 'index.html*' \
--cut-dirs=$cut_dirs $feed_url/repodata/ -o $anaconda_logdir/rpmget_repo.log \
|| report_post_failure_with_logfile $anaconda_logdir/rpmget_repo.log
wlog "${KS} download of $feed_url/repodata/ complete"
else
wlog "${KS} Local Install"
fi
# Fetch Patch Package Data quietly
# - Patch Packages
# - Patches repodata
# - Patches metadata
# - Save all patch packages to /opt/patching/packages/xxxPLATFORM_RELEASExxx
patches_url=xxxHTTP_URLxxx/patches
wget ${NOVERIFYSSL_WGET_OPT} -q --spider ${patches_url}/
if [ $? -eq 0 ] && [ "${need_patches}" = true ]; then
wlog "${KS} downloading patch repository $patches_url"
cd /var/www/pages
mkdir -p updates/rel-xxxPLATFORM_RELEASExxx/Packages
mkdir -p updates/rel-xxxPLATFORM_RELEASExxx/repodata
cd updates/rel-xxxPLATFORM_RELEASExxx
declare -i patches_cut_dirs=$((cut_dirs+1))
wlog "${KS} fetch packages"
wget ${NOVERIFYSSL_WGET_OPT} --mirror --no-parent --no-host-directories --reject 'index.html*' \
--cut-dirs=$patches_cut_dirs $patches_url/Packages/ -o $anaconda_logdir/patches_rpmget.log \
|| report_post_failure_with_logfile $anaconda_logdir/patches_rpmget.log
wlog "${KS} fetch package repodata"
wget ${NOVERIFYSSL_WGET_OPT} --mirror --no-parent --no-host-directories --reject 'index.html*' \
--cut-dirs=$patches_cut_dirs $patches_url/repodata/ -o $anaconda_logdir/patches_rpmget_repo.log \
|| report_post_failure_with_logfile $anaconda_logdir/patches_rpmget_repo.log
mkdir -p /opt/patching/metadata
mkdir -p /opt/patching/packages/xxxPLATFORM_RELEASExxx
cd /opt/patching
wlog "${KS} fetch patch metadata"
wget ${NOVERIFYSSL_WGET_OPT} --mirror --no-parent --no-host-directories --reject 'index.html*' \
--cut-dirs=$patches_cut_dirs $patches_url/metadata/ -o $anaconda_logdir/patches_rpmget_metadata.log \
|| report_post_failure_with_logfile $anaconda_logdir/patches_rpmget_metadata.log
wlog "${KS} save a copy of all patch packages, preserve attributes"
find /var/www/pages/updates/rel-xxxPLATFORM_RELEASExxx/Packages -name '*.rpm' \
| xargs --no-run-if-empty -I files cp --preserve=all files /opt/patching/packages/xxxPLATFORM_RELEASExxx/
else
wlog "${KS} Patches are not required to be downloaded"
fi
%end