#!/bin/sh

# This script sets method "newworld" for all hfs partitions that have the
# boot flag set.

. /lib/partman/lib/base.sh

for dev in /var/lib/partman/devices/*; do
	[ -d "$dev" ] || continue
	cd $dev
	partitions=
	open_dialog PARTITIONS
	while { read_line num id size type fs path name; [ "$id" ]; }; do
		if [ "$fs" = hfs ]; then
			partitions="$partitions $id"
		fi
	done
	close_dialog

	for id in $partitions; do
		newworld=no
		open_dialog GET_FLAGS $id
		while { read_line flag; [ "$flag" ]; }; do
			if [ "$flag" = boot ]; then
				newworld=yes
				# cannot break here
			fi
		done
		close_dialog
		if [ "$newworld" = yes ]; then
			mkdir -p $id
			echo newworld >$id/method
		fi
	done
done
