Merge pull request #344 from marcov/dracut-improvements

dracut: improve host distro support
This commit is contained in:
Julio Montes 2019-08-09 11:39:23 -05:00 committed by GitHub
commit 987fe3067e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -401,8 +401,6 @@ prepare_overlay()
# provided as argument # provided as argument
setup_rootfs() setup_rootfs()
{ {
[ -z "$distro" ] && prepare_overlay
info "Create symlink to /tmp in /var to create private temporal directories with systemd" info "Create symlink to /tmp in /var to create private temporal directories with systemd"
pushd "${ROOTFS_DIR}" >> /dev/null pushd "${ROOTFS_DIR}" >> /dev/null
if [ "$PWD" != "/" ] ; then if [ "$PWD" != "/" ] ; then
@ -448,14 +446,21 @@ EOT
[ -n "${KERNEL_MODULES_DIR}" ] && copy_kernel_modules ${KERNEL_MODULES_DIR} ${ROOTFS_DIR} [ -n "${KERNEL_MODULES_DIR}" ] && copy_kernel_modules ${KERNEL_MODULES_DIR} ${ROOTFS_DIR}
chrony_conf_file="${ROOTFS_DIR}/etc/chrony.conf"
if [ "${distro}" == "ubuntu" ] || [ "${distro}" == "debian" ] ; then
chrony_conf_file="${ROOTFS_DIR}/etc/chrony/chrony.conf"
fi
info "Create ${ROOTFS_DIR}/etc" info "Create ${ROOTFS_DIR}/etc"
mkdir -p "${ROOTFS_DIR}/etc" mkdir -p "${ROOTFS_DIR}/etc"
case "${distro}" in
"ubuntu" | "debian")
echo "I am ubuntu or debian"
chrony_conf_file="${ROOTFS_DIR}/etc/chrony/chrony.conf"
chrony_systemd_service="${ROOTFS_DIR}/lib/systemd/system/chrony.service"
;;
*)
chrony_conf_file="${ROOTFS_DIR}/etc/chrony.conf"
chrony_systemd_service="${ROOTFS_DIR}/usr/lib/systemd/system/chronyd.service"
;;
esac
info "Configure chrony file ${chrony_conf_file}" info "Configure chrony file ${chrony_conf_file}"
cat >> "${chrony_conf_file}" <<EOT cat >> "${chrony_conf_file}" <<EOT
refclock PHC /dev/ptp0 poll 3 dpoll -2 offset 0 refclock PHC /dev/ptp0 poll 3 dpoll -2 offset 0
@ -468,11 +473,6 @@ EOT
# Reference: https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html # Reference: https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html
sed -i 's/^\(server \|pool \|peer \)/# &/g' ${chrony_conf_file} sed -i 's/^\(server \|pool \|peer \)/# &/g' ${chrony_conf_file}
chrony_systemd_service="${ROOTFS_DIR}/usr/lib/systemd/system/chronyd.service"
if [ ${distro} == ubuntu ] || [ ${distro} == debian ] ; then
chrony_systemd_service="${ROOTFS_DIR}/lib/systemd/system/chrony.service"
fi
if [ -f "$chrony_systemd_service" ]; then if [ -f "$chrony_systemd_service" ]; then
sed -i '/^\[Unit\]/a ConditionPathExists=\/dev\/ptp0' ${chrony_systemd_service} sed -i '/^\[Unit\]/a ConditionPathExists=\/dev\/ptp0' ${chrony_systemd_service}
fi fi
@ -533,6 +533,23 @@ parse_arguments()
distro="$1" distro="$1"
} }
detect_host_distro()
{
source /etc/os-release
case "$ID" in
"*suse*")
distro="suse"
;;
"clear-linux-os")
distro="clearlinux"
;;
*)
distro="$ID"
;;
esac
}
main() main()
{ {
parse_arguments $* parse_arguments $*
@ -544,6 +561,10 @@ main()
else else
#Make sure ROOTFS_DIR is set correctly #Make sure ROOTFS_DIR is set correctly
[ -d "${ROOTFS_DIR}" ] || die "Invalid rootfs directory: '$ROOTFS_DIR'" [ -d "${ROOTFS_DIR}" ] || die "Invalid rootfs directory: '$ROOTFS_DIR'"
# Set the distro for dracut build method
detect_host_distro
prepare_overlay
fi fi
setup_rootfs setup_rootfs