#!/bin/bash
#
#%stage: setup
#%depends: start

# We don't need to copy the binaries since boot-plymouth.sh does that for us

[ -z "$tmp_mnt" ] && exit 1

THEME=$(plymouth-set-default-theme)

PLUGIN_PATH=$(plymouth --get-splash-plugin-path)

MODULE=$(grep "ModuleName *= *" /usr/share/plymouth/themes/${THEME}/${THEME}.plymouth | sed 's/ModuleName *= *//')

if [ ! -f "$PLUGIN_PATH/${MODULE}.so" ]; then
	echo "The default plymouth plugin ($MODULE) doesn't exist." > /dev/stderr
	exit 1
fi

FILES="/usr/share/plymouth/themes/text/text.plymouth \
	/usr/share/plymouth/themes/details/details.plymouth \
	/usr/share/plymouth/plymouthd.defaults \
	/usr/share/plymouth/themes/${THEME}/* \
	/etc/plymouth/plymouthd.conf \
       /usr/share/fonts/uni/unifont.pcf.gz /etc/os-release \
       /etc/fonts/fonts.conf \
       /etc/fonts/conf.d/69-unifont.conf "

PLUGINS="${PLUGIN_PATH}/details.so \
	${PLUGIN_PATH}/text.so \
	${PLUGIN_PATH}/label.so \
	${PLUGIN_PATH}/${MODULE}.so \
	${PLUGIN_PATH}/renderers/drm.so \
	${PLUGIN_PATH}/renderers/frame-buffer.so"

for file in $FILES; do
	install -D $file $tmp_mnt/$file
done

for plugin in $PLUGINS; do
	mkdir -p $tmp_mnt/$(dirname $plugin)
	cp_bin $plugin $tmp_mnt/$plugin
done

_libdir=`rpm --eval '%{_lib}'`
mkdir -p $tmp_mnt/etc/pango
if [ "$_libdir" == "lib64" ];
  then
     _pangodir=`pango-querymodules-64 | grep ModulesPath | awk '{print $4}'`
     pango-querymodules-64 > $tmp_mnt/etc/pango/pango.modules
     pangobasicfc="${_pangodir}/pango-basic-fc.so"
  else
     _pangodir=`pango-querymodules | grep ModulesPath | awk '{print $4}'`
     pango-querymodules > $tmp_mnt/etc/pango/pango.modules
     pangobasicfc="${_pangodir}/pango-basic-fc.so"
fi
install -D ${pangobasicfc} $tmp_mnt/${pangobasicfc}
mkdir -p $tmp_mnt/var/cache/fontconfig
