#!/bin/bash
if ldd /sbin/plymouthd |grep -q lib64; then
    LIBDIR="/usr/lib64"
else
    LIBDIR="/usr/lib"
fi
PLYMOUTH_LOGO_FILE="/usr/share/pixmaps/system-logo-white.png"
PLYMOUTH_THEME=$(plymouth-set-default-theme)

inst /sbin/plymouthd /bin/plymouthd
dracut_install /bin/plymouth \
    "${PLYMOUTH_LOGO_FILE}" \
    /etc/system-release 

mkdir -p "${initdir}/etc/plymouth"
mkdir -p "${initdir}/usr/share/plymouth/themes"
mkdir -p "${initdir}/var/lib/plymouth"
mkdir -p "${initdir}/var/run/plymouth"
mkdir -p "${initdir}/var/spool/plymouth"

inst /etc/plymouth/plymouthd.conf
inst ${LIBDIR}/plymouth/details.so
if [[ -f ${LIBDIR}/plymouth/renderers/drm.so ]]; then
    inst ${LIBDIR}/plymouth/renderers/drm.so
fi
if [[ -f ${LIBDIR}/plymouth/renderers/frame-buffer.so ]]; then
    inst ${LIBDIR}/plymouth/renderers/frame-buffer.so
fi
if [[ -f ${LIBDIR}/plymouth/renderers/x11.so ]]; then
    inst ${LIBDIR}/plymouth/renderers/x11.so
fi
if [[ -f ${LIBDIR}/plymouth/script.so ]]; then
    inst ${LIBDIR}/plymouth/script.so
fi
if [[ -f ${LIBDIR}/plymouth/two-step.so ]]; then
    inst ${LIBDIR}/plymouth/two-step.so
fi
if [[ -f ${LIBDIR}/plymouth/label.so ]]; then
    inst ${LIBDIR}/plymouth/label.so
fi
if [[ -f ${LIBDIR}/plymouth/label-freetype.so ]]; then
    inst ${LIBDIR}/plymouth/label-freetype.so
fi
if [[ -f ${LIBDIR}/plymouth/label-pango.so ]]; then
    inst ${LIBDIR}/plymouth/label-pango.so
fi
inst ${LIBDIR}/plymouth/text.so
inst /usr/share/plymouth/default-boot-duration
inst /usr/share/plymouth/plymouthd.defaults
inst /usr/share/plymouth/themes/details/details.plymouth
inst /usr/share/plymouth/themes/text/text.plymouth
inst /var/lib/plymouth/boot-duration

if [[ $hostonly ]]; then 
    dracut_install \
        "/etc/plymouth/plymouthd.conf" \
        "${LIBDIR}/plymouth/details.so" \
        "${LIBDIR}/plymouth/renderers/drm.so" \
        "${LIBDIR}/plymouth/renderers/frame-buffer.so" \
        "${LIBDIR}/plymouth/text.so" \
        "/usr/share/plymouth/default-boot-duration" \
        "/usr/share/plymouth/plymouthd.defaults" \
        "/usr/share/plymouth/themes/details/details.plymouth" \
        "/usr/share/plymouth/themes/text/text.plymouth" \
        "/var/lib/plymouth/boot-duration" \

    if [[ -f ${LIBDIR}/plymouth/renderers/x11.so ]]; then
        dracut_install \
            "${LIBDIR}/plymouth/renderers/x11.so" \

    fi

    if [[ -d /usr/share/plymouth/themes/${PLYMOUTH_THEME} ]]; then
	for x in "/usr/share/plymouth/themes/${PLYMOUTH_THEME}"/* ; do
            [[ -f "$x" ]] || break
            inst $x
	done
    fi

    if [ -L /usr/share/plymouth/themes/default.plymouth ]; then
	inst /usr/share/plymouth/themes/default.plymouth
        # Install plugin for this theme
	PLYMOUTH_PLUGIN=$(grep "^ModuleName=" /usr/share/plymouth/themes/default.plymouth | while read a b c; do echo $b; done;)
	inst ${LIBDIR}/plymouth/${PLYMOUTH_PLUGIN}.so
    fi
else
    for x in /usr/share/plymouth/themes/{text,details}/* ; do
        [[ -f "$x" ]] || continue
	THEME_DIR=$(dirname "$x")
	mkdir -p "${initdir}/$THEME_DIR"
        dracut_install "$x"
    done
    for x in ${LIBDIR}/plymouth/{text,details}.so ; do
        [[ -f "$x" ]] || continue
        [[ "$x" != "${x%%/label.so}" ]] && continue
        dracut_install "$x"
    done
    for x in ${LIBDIR}/plymouth/{label-freetype,label-pango}.so ; do
        [[ -f "$x" ]] || continue
        dracut_install "$x"
    done
    (
	cd ${initdir}/usr/share/plymouth/themes;
	ln -s text/text.plymouth default.plymouth 2>&1;       
    )
fi

# vim:ts=8:sw=4:sts=4:et
