#!/bin/bash -e # description: CI/CD Utility helper. Builds linux rootfs file from kickstart input file in docker/podman enviroment # param: 1. kickstart file and 2. rootfs file name to be generated # license: MIT. usage() { cat 1>&2 <&2 <&2 exit 1 ;; esac if [ ${TYPE} == 'wsl' ]; then BUILD_COMPTYPE='gzip' fi BUILD_LOGDIR=${OUTPUT_DIR}/logs if [ -z ${KICKSTART_FILE} ] || [ -z ${IMAGE_NAME} ] then echo "Please provide two parameters, kickstart source file and rootfs output file name" usage exit 1 fi # Write run summary to console run-summary # set anaconda base product cat << _EOF > /etc/anaconda/product.d/ks2rootfs.conf # Anaconda configuration file for Kickstart to Rootfs. [Product] product_name = Kickstart to RootFS [Base Product] product_name = AlmaLinux [Storage] file_system_type = [License] eula = _EOF # create rootfs livemedia-creator --logfile="/tmp/ks2rootfs.log" \ --make-tar --ks="${BUILD_WORK_DIR}/${KICKSTART_FILE}" --no-virt \ --image-only --image-name="${IMAGE_NAME}" \ --anaconda-arg "--product Kickstart to RootFS" \ --compression ${BUILD_COMPTYPE} # copy rootfs to working dir cp -rp /var/tmp/${IMAGE_NAME} ${OUTPUT_DIR}/${IMAGE_NAME} echo "Copied disk image from /var/tmp/${IMAGE_NAME} to ${OUTPUT_DIR}/${IMAGE_NAME}" # save list of packages installed jq .[] -r /tmp/dnf.cache/tempfiles.json | awk -F '/' '{print $5}' | sort > ${OUTPUT_DIR}/rpm-packags # cat ${OUTPUT_DIR}/rpm-packags | sed 's/-[0-9].*//g' > ${OUTPUT_DIR}/pkgs-list-only # cat ${OUTPUT_DIR}/rpm-packags | sed 's/.el[0-9].*//g' > ${OUTPUT_DIR}/pkgs-list echo "Generated '${OUTPUT_DIR}/rpm-packags' file." if [ ${FLAG_WRITE_META} == 'true' ]; then # extract os-release info tar -xvf /var/tmp/${IMAGE_NAME} -C /tmp/ --strip-components=3 ./usr/lib/os-release os_release_id=$(awk -F= '$1=="ID" { print $2 ;}' /tmp/os-release | tr -d '"') distro_release=$(grep "${os_release_id}.*-release-" /tmp/anaconda/packaging.log | grep -o "Verifying:.*" | sed -n 's/Verifying: //p') if [ -z ${distro_release+x} ]; then exit 1 else echo 'Writting meta data ... ' # save distro release info echo "$distro_release" > ${OUTPUT_DIR}/distro-release fi echo 'Writting meta data completed.' else echo 'Skip writing meta data.' fi if [ ${FLAG_RETAIN_LOG} == 'true' ]; then rm -rf ${BUILD_LOGDIR} mkdir -p ${BUILD_LOGDIR} ${BUILD_LOGDIR}/anaconda echo "Copying logs to '${BUILD_LOGDIR}' ..." cp /tmp/ks2rootfs.log rm -rf ${BUILD_LOGDIR}/ks2rootfs.log cp -rp /tmp/anaconda/* ${BUILD_LOGDIR}/anaconda echo 'Copying logs completed.' else echo 'Skip copying logs data based on configuration (default). ' fi STARTCMD=$( cat < "${OUTPUT_DIR}/Dockerfile" FROM scratch ADD ${IMAGE_NAME} / ${STARTCMD} EOF echo "Generating '${OUTPUT_DIR}/Dockerfile' completed."