#!/bin/bash

[ -x /usr/share/initramfs-tools/init ] ||
apt-get install initramfs-tools

out=/dev/null
out=$PWD/initramfs-$(uname -r)
stdout=$(mkinitramfs -d $PWD/configs -k -o $out)
rm -f $out

day=$(date +%F)

[[ $stdout =~ Working\ files\ in\ ([a-zA-Z0-9_/]+), ]] || exit

dir="${BASH_REMATCH[1]}"
rm -fr $dir/lib/modules/$(uname -r)
rm -fr $dir/lib/firmware
rm -fr initramfs-$day
cp -a $dir initramfs-$day

./create-cpio.sh initramfs-$day
