108 lines
3.7 KiB
Bash
108 lines
3.7 KiB
Bash
#!/bin/bash -e
|
|
# vim: set ts=4 sw=4 sts=4 et :
|
|
|
|
source ./functions.sh >/dev/null
|
|
source ./umount_kill.sh >/dev/null
|
|
|
|
setVerboseMode
|
|
output "${bold}${under}INFO: ${SCRIPTSDIR}/distribution.sh imported by: ${0}${reset}"
|
|
|
|
# ==============================================================================
|
|
# Cleanup function
|
|
# ==============================================================================
|
|
function cleanup() {
|
|
errval=$?
|
|
trap - ERR EXIT
|
|
trap
|
|
error "${1:-"${0}: Error. Cleaning up and un-mounting any existing mounts"}"
|
|
umount_kill "${INSTALLDIR}" || true
|
|
|
|
# Return xtrace to original state
|
|
[[ -n "${XTRACE}" ]] && [[ "${XTRACE}" -eq 0 ]] && set -x || set +x
|
|
|
|
exit $errval
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Create system mount points
|
|
# ==============================================================================
|
|
function prepareChroot() {
|
|
info "--> Preparing environment..."
|
|
mount -t proc proc "${INSTALLDIR}/proc"
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Yum install package(s)
|
|
# ==============================================================================
|
|
function yumInstall() {
|
|
files="$@"
|
|
mount --bind /etc/resolv.conf ${INSTALLDIR}/etc/resolv.conf
|
|
if [ -e "${INSTALLDIR}/usr/bin/yum" ]; then
|
|
chroot yum install ${YUM_OPTS} -y ${files[@]} || exit 1
|
|
else
|
|
yum install -c ${PWD}/yum.conf ${YUM_OPTS} -y --installroot=${INSTALLDIR} ${files[@]} || exit 1
|
|
fi
|
|
umount ${INSTALLDIR}/etc/resolv.conf
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Verify RPM packages
|
|
# ==============================================================================
|
|
function verifyPackages() {
|
|
for file in $@; do
|
|
result=$(rpm --root="${INSTALLDIR}" --checksig "${file}") || {
|
|
echo "Filename: ${file} failed verification. Exiting!"
|
|
exit 1
|
|
}
|
|
result_status="${result##*:}"
|
|
echo "${result_status}" | grep -q 'PGP' && {
|
|
echo "Filename: ${file} contains an invalid PGP signature. Exiting!"
|
|
exit 1
|
|
}
|
|
echo "${result_status}" | grep -q 'pgp' || {
|
|
echo "Filename: ${file} is not signed. Exiting!"
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Install extra packages in script_${DIST}/packages.list file
|
|
# -and / or- TEMPLATE_FLAVOR directories
|
|
# ==============================================================================
|
|
function installPackages() {
|
|
if [ -n "${1}" ]; then
|
|
# Locate packages within sub dirs
|
|
if [ ${#@} == "1" ]; then
|
|
getFileLocations packages_list "${1}" ""
|
|
else
|
|
packages_list="$@"
|
|
fi
|
|
else
|
|
# TODO: Add into template flavor handler the ability to
|
|
# detect flavors that will not append recursive values
|
|
# Only file 'minimal' package lists
|
|
if [ "$TEMPLATE_FLAVOR" == "minimal" ]; then
|
|
getFileLocations packages_list "packages.list" "${DIST}_minimal"
|
|
else
|
|
getFileLocations packages_list "packages.list" "${DIST}"
|
|
fi
|
|
if [ -z "${packages_list}" ]; then
|
|
error "Can not locate a package.list file!"
|
|
umount_all || true
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
for package_list in ${packages_list[@]}; do
|
|
debug "Installing extra packages from: ${package_list}"
|
|
declare -a packages
|
|
readarray -t packages < "${package_list}"
|
|
|
|
info "Packages: "${packages[@]}""
|
|
yumInstall "${packages[@]}" || return $?
|
|
done
|
|
}
|