%post --nochroot --erroronfail # Source common functions . /tmp/ks-functions.sh KS="Prestaging post:" # # The /tmp/backup-guid-change.sh script assignes the Label # and GUID to the Platform Backup partition. This script is # dynamically created in the pre_disk_aio.cfg kickstart, which # serves as the disk setup kickstart for the prestaging bundle. # # However, this script is only run afterward; in post_common.cfg # which is not used in the prestaging bundle ; it contains too # much in-service controller function setup stuff. # # Therefore, it is added here to ensure that if the prestaging # ISO's pre_disk_aio.cfg 'created' the 'Platform Backup/platform_backup' # partition then it will get labeled for prestaging group. # # This prestaging kickstart file uses the GUID to find the # platform backup partition for its prestaging function. # change_guid=/tmp/backup-guid-change.sh if [ -f "$change_guid" ]; then wlog "${KS} applying label to backup partition" sh $change_guid || report_post_failure_with_logfile "ERROR: Failed to update platform backup label and GUID" else wlog "${KS} /tmp/backup-guid-change.sh not found !!" fi %end %post --nochroot --erroronfail # Source common functions . /tmp/ks-functions.sh KS="Prestaging post:" error=false wlog "${KS} cmdLine: $(cat /proc/cmdline)" if [ -d /mnt/install/source ]; then SOURCE_DIR=/mnt/install/source else SOURCE_DIR=/run/install/repo fi wlog "${KS} install source : $SOURCE_DIR" export SW_VERSION=xxxPLATFORM_RELEASExxx export STAGING_DIR="platform-backup" export BACKUP_PART_GUID="BA5EBA11-0000-1111-2222-000000000002" export BACKUP_DEVICE= export PRESTAGING_REPO_DIR="${SOURCE_DIR}/opt/${STAGING_DIR}" export PRESTAGING_LOCAL_DIR="/mnt/${STAGING_DIR}" wlog "${KS} SW_VERSION : ${SW_VERSION}" wlog "${KS} IMAGE_MOUNT : ${SOURCE_DIR}" wlog "${KS} PRESTAGING_REPO_DIR : ${PRESTAGING_REPO_DIR}" wlog "${KS} PRESTAGING_LOCAL_DIR : ${PRESTAGING_LOCAL_DIR}" # check for required directories if [ ! -d ${SOURCE_DIR} ] ; then msg="install source '${SOURCE_DIR}' does not exists or is not a directory" wlog "${KS} Prestaging Failed: ${msg}" report_pre_failure_with_msg "${msg}" elif [ ! -d "${PRESTAGING_REPO_DIR}" ] ; then msg="repo ${PRESTAGING_REPO_DIR} does not exist" wlog "${KS} Prestaging Failed: ${msg}" report_pre_failure_with_msg "${msg}" elif [ ! -d "${PRESTAGING_REPO_DIR}/${SW_VERSION}" ] ; then msg="repo ${PRESTAGING_REPO_DIR}/${SW_VERSION} sw version content missing" wlog "${KS} Prestaging Failed: ${msg}" report_prestaging_failure_with_msg "${msg}" fi # Poll for the platform backup GUID for i in {1..6} ; do # Search for a backup partition, using GUID (which appears lower case in the blkid output): while read -r device_path; do if [ "$(blkid -p "${device_path}" | grep -c -i "${BACKUP_PART_GUID}")" -gt 0 ]; then BACKUP_DEVICE=${device_path} wlog "Found backup device: ${BACKUP_DEVICE}" break fi done <<<"$(lsblk --noheadings --list --path --output NAME)" if [ -n "${BACKUP_DEVICE}" ] ; then break else wlog "${KS} searching for backup partition ${BACKUP_PART_GUID} GUID [${i}/6]" sleep 10 fi done if [ -z "${BACKUP_DEVICE}" ]; then msg="Could not find backup device from GUID ${BACKUP_PART_GUID}" wlog "${KS} Prestaging failed: ${msg}" report_prestaging_failure_with_msg "${msg}" fi errmsg= if [ ! -d "${PRESTAGING_LOCAL_DIR}" ] ; then wlog "${KS} mounting ${PRESTAGING_LOCAL_DIR}" mkdir -p "${PRESTAGING_LOCAL_DIR}" mount "${BACKUP_DEVICE}" "${PRESTAGING_LOCAL_DIR}" rc=$? if [ $rc -eq 0 ] ; then sleep 2 if [ ! -d "${PRESTAGING_LOCAL_DIR}" ] ; then errmsg="${KS} mount of staging '${PRESTAGING_LOCAL_DIR}' does not exist" fi else errmsg="${KS} mount of '${BACKUP_DEVICE}' to '${PRESTAGING_LOCAL_DIR}' failed rc:${rc}" fi fi if [ -n "$errmsg" ] ; then wlog "${KS} Prestaging failed: ${errmsg}" report_prestaging_failure_with_msg "${errmsg}" fi # nuke local prestaging dir - cleanup operation if [ -d ${PRESTAGING_LOCAL_DIR}/${SW_VERSION} ] ; then wlog "${KS} cleanup; wiping existing prestaging dir '${PRESTAGING_LOCAL_DIR}/${SW_VERSION}'" rm -rf ${PRESTAGING_LOCAL_DIR}/${SW_VERSION} fi # create local prestaging dir mkdir ${PRESTAGING_LOCAL_DIR}/${SW_VERSION} # enter the local prestaging dir for this release cd ${PRESTAGING_LOCAL_DIR}/${SW_VERSION} # copy repo prestaging files to the local mount wlog "${KS} copy prestaging files: from '${PRESTAGING_REPO_DIR}/${SW_VERSION}' to '${PRESTAGING_LOCAL_DIR}'" cp -a "${PRESTAGING_REPO_DIR}/${SW_VERSION}" "${PRESTAGING_LOCAL_DIR}/" rc=$? if [ $rc -ne 0 ] ; then msg="copy failed from '${PRESTAGING_REPO_DIR}/${SW_VERSION}' to '${PRESTAGING_LOCAL_DIR}/', rc=${rc}" wlog "${KS} Prestaging Failed: ${msg}" report_prestaging_failure_with_msg "${msg}" fi wlog "${KS} prestaging files copy done" # loop over all the prestaged files # - log files found # - do md5 check on md5 files found for file in * ; do filename="${file%.*}" extension="${file##*.}" wlog "${KS} prestaged file : ${file}" if [ "${extension}" = "md5" ] ; then md5sum -c "${file}" if [ $? -eq 0 ] ; then wlog "${KS} ${filename} check passed" else wlog "${KS} ${filename} check failed" error=true fi fi done # handle any md5 check errors or log success/complete result if [ "$error" = true ] ; then msg="prestaging file(s) failed integrity check ; see logs for details" wlog "${KS} Prestaging failed: ${msg}" report_prestaging_failure_with_msg "${msg}" else wlog "${KS} prestaging integrity checks passed" fi wlog "${KS} prestaging complete" %end