#!/bin/sh

. /lib/partman/definitions.sh

# At least one file system to mount on /
no_root () {
    mountpoints=$(
	for i in /lib/partman/fstab.d/*; do
	    [ -x "$i" ] || continue
	    $i
	done | 
	while read fs mp type options dump pass; do
	    echo $mp
	done
    )
    
    for mp in $mountpoints; do
	if [ "$mp" = / ]; then
	    return 0
	fi
    done
    
    db_input critical partman-target/no_root || true
    db_go || true
    exit 1
}

# No two file systems with one and the same mount point
same_mountpoints () {
    mountpoints=$(
	for i in /lib/partman/fstab.d/*; do
	    [ -x "$i" ] || continue
	    $i
	done | 
	while read fs mp type options dump pass; do
	    case "$mp" in
		/*)
		    echo $mp,$fs;;
	    esac
	done |
	sort
    )
    
    oldmp=' '
    for x in $mountpoints; do
	mp=${x%,*}
	fs=${x#*,}
	if [ "$mp" = "$oldmp" ]; then
	    db_subst partman-target/same_mountpoint PART1 $(humandev $oldfs)
	    db_subst partman-target/same_mountpoint PART2 $(humandev $fs)
	    db_subst partman-target/same_mountpoint MOUNTPOINT "$mp"
	    db_input critical partman-target/same_mountpoint || true
	    db_go || true
	    exit 1
	else
	    oldmp="$mp"
	    oldfs="$fs"
	fi
    done
}

no_root
same_mountpoints
