#!/bin/sh -efu

. sh-functions

reportdir="$workdir/report"

mkdir -p -- \
	"$reportdir"/boot \
	"$reportdir"/etc \
	"$reportdir"/sys \
	"$reportdir"/proc \
	#

if [ -f "${KERNEL_CONFIG-}" ]; then
	cp -a \
		"$KERNEL_CONFIG" \
		"$reportdir"/boot/
fi

cp -aP \
	/sys \
	"$reportdir" 2>/dev/null ||:
cp -a  \
	/proc/config.gz \
	/proc/cpuinfo \
	/proc/cmdline \
	/proc/crypto \
	/proc/devices \
	/proc/filesystems \
	/proc/mdstat \
	/proc/modules \
	/proc/partitions \
	/proc/sys \
	/proc/version \
	"$reportdir"/proc/ 2>/dev/null ||:
cat /proc/mounts > "$reportdir"/proc/mounts

cp -a  \
	/etc/fstab \
	/etc/blkid.tab \
	"$reportdir"/etc/

blkid -c /dev/null >"$reportdir"/etc/blkid.out

[ -z "${VERSION-}" ] ||
		printf '%s\n' "$VERSION" > "$reportdir"/.version

outfile="$PWD/make-initrd-bugreport-$(date +"%Y%m%d").tar.bz2"

cd "$workdir"
tar -cjf "$outfile" report

printf '\nPlease submit %s to authors\n\n' "$outfile"
