#!/bin/sh

. /usr/share/debconf/confmodule

dev=$1
num=$2
id=$3
size=$4
type=$5
fs=$6
path=$7
name=$8

cd $dev

# The purpose of this preliminary code is to execute the time
# consuming file system detection. check using tune2fs only once.
# From now on, we no longer need to run tune2fs but simply check
# for the existence of detected_ext2r0.
if [ ! -f /var/lib/partman/filesystems_detected ] && \
   [ -f $id/detected_filesystem ] && \
   [ "$(cat $id/detected_filesystem)" = ext2 ]; then
	if $(tune2fs -l $path | \
	     grep -q '^Filesystem revision #: \+0 (original)$'); then
		>$id/detected_ext2r0
	else
		rm -f $id/detected_ext2r0
	fi
fi

# List the ext2r0 partition as ext2r0 in the main partman screen
if [ "$fs" != free ] && [ ! -f $id/method ] && [ -f $id/detected_filesystem ] && \
   [ "$(cat $id/detected_filesystem)" = ext2 ] && [ -f $id/detected_ext2r0 ]; then
	db_metaget partman/filesystem_short/ext2r0 description || RET=''
	RET="${RET:-ext2r0}"
	printf %s "$RET" >$id/visual_filesystem
fi
