#! /bin/sh

dst=$1
theme=$2
cfg=$3
spl=$4

splash -s -f /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg >/$dst/$spl.spl
splash -s -c -f /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg | gzip -9c >/$dst/gz/$spl.spl

cp -a /etc/bootsplash/themes/$theme/images /$dst
rm -f /$dst/images/*-*.jpg

mkdir -p /$dst/unpacked/$spl
gunzip -c /$dst/gz/$spl.spl | ( cd /$dst/unpacked/$spl ; cpio --quiet -di )

mount -t proc proc proc

mkdir xxx
cp -a --parents /etc/bootsplash/themes/$theme/config/*-$cfg.* xxx
cp -a --parents /etc/bootsplash/themes/$theme/images/*-$cfg.* xxx
ln -s /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg xxx/etc/splash.cfg
cp -a xxx/* /$dst/unpacked/$spl
cd xxx
chmod -R a+rX .
find | cpio --quiet -o -H newc | gzip -9 >>/$dst/gz/$spl.spl
cd /
rm -r xxx

umount proc

