#!/bin/sh -Cefux


set -Cefux


cd /root/files/fbsd/embedded || exit 1


rsync -avhhhiHAXUS \
--delete --delete-excluded \
'--exclude=loader.env.root?' \
overlays/npinc/boot/ \
sdboot/


rsync -avhhhiHAXUS \
overlays/npinc-sd/boot/ \
sdboot/


rsync -avhhhiHAXUS \
--delete \
rootfs/ \
sdroot/


rsync -avhhhiHAXUS \
overlays/npinc-sd/root/ \
sdroot/


rsync -avhhhiHAXUS \
/usr/local/share/u-boot/u-boot-nanopi_m1plus/ \
sdroot/root/install/uboot/


rsync -avhhhiHAXUS \
overlays/npinc/boot/ \
sdroot/root/install/msdosfs/


rsync -avhhhiHAXUS \
--include=fstab \
--include=rc.conf \
'--exclude=*' \
overlays/npinc/root/etc/ \
sdroot/root/install/etc/


rsync -avhhhiHAXUS \
--no-owner \
--no-group \
--include=ca.crt \
--include=ca.key \
'--exclude=*' \
/home/ketas/files/priv/ca/poedaemon/ \
sdroot/root/install/priv/ca/


umount /mnt || true


fsck_msdosfs -y /dev/msdosfs/SDBOOT

mount_msdosfs -o noatime /dev/msdosfs/SDBOOT /mnt

rsync -avhhhiHAXUS \
--delete \
--modify-window=1 \
sdboot/ \
/mnt/ \
|| true

umount /mnt

fsck_msdosfs -y /dev/msdosfs/SDBOOT


fsck -y /dev/ufs/sdroot

mount -o noatime /dev/ufs/sdroot /mnt

rsync -avhhhiHAXUS \
--delete \
--exclude=/.snap \
--exclude=/var/empty \
sdroot/ \
/mnt/

umount /mnt

fsck -y /dev/ufs/sdroot
