#!/bin/sh

. /lib/partman/definitions.sh

task=$1
dev=$2
id=$3

cd $dev

new_flags=''
open_dialog GET_FLAGS $id
while { read_line flag; [ "$flag" ]; }; do
    if [ "$flag" != boot ]; then
	if [ "$new_flags" ]; then
	    new_flags="$new_flags
$flag"
	else
	    new_flags="$flag"
	fi
    fi
done
close_dialog

if [ $task = bootable ]; then
    new_flags="$new_flags
boot"
fi

open_dialog SET_FLAGS $id
write_line "$new_flags"
write_line NO_MORE
close_dialog

partitions=''
numparts=1
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
    [ "$fs" != free ] || continue
    partitions="$partitions $id"
    numparts=$(($numparts + 1))
done
close_dialog

db_progress START 0 $numparts partman/text/please_wait
db_progress INFO partman-partitioning/new_state

for id in $partitions; do
    update_partition $dev $id
    db_progress STEP 1
done

db_progress STOP
