#!/bin/sh
# Automatic FreeBSD ZFS bootcode updater
# Mark Felder <feld@FreeBSD.org>
# 
# WARNING! This script blindly applies gptzfsboot update to any freebsd-boot
# partition that is identified as already containing ZFS bootcode
# It is a horrible hack. Make sure you understand what you're doing.

for i in $(gpart show -p | awk '/freebsd-boot/ && /p1/ {print $3}'); do
    strings /dev/${i} | grep -q ZFS && gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${i%p1} || echo "${i}: No ZFS bootloader found."
done
