do_option 5.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/sh

set -e

. /lib/partman/definitions.sh

dev=$2
freeid=$3

cd $dev

open_dialog PARTITION_INFO $freeid
read_line x1 freeid freesize freetype x2 x3 x4
close_dialog

[ "$freeid" ] || exit 1

freehsize=$(longint2human $freesize)

ask_for_size () {
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    local noninteractive
    noninteractive=true
    while true; do
	size=''
	while [ ! "$size" ]; do
	    db_set partman-partitioning/new_partition_size "$freehsize"
	    db_subst partman-partitioning/new_partition_size MAXSIZE "$freehsize"
	    db_input high partman-partitioning/new_partition_size ||
	    $noninteractive
	    noninteractive="return 1"
	    db_go || return 1
	    db_get partman-partitioning/new_partition_size
	    
	    case "$RET" in
		max)
		    size=$freesize
		    hsize="$freehsize"
		    ;;
		*%)
		    digits=$(expr "$RET" : '\([1-9][0-9]*\) *%$')
		    if [ "$digits" ]; then
			maxmb=$(expr 0000000"$freesize" : '0*\(..*\)......$')
			size=$(($digits * $maxmb / 100))000000
		    fi
		    if [ "$digits" = 100 ]; then
			hsize="$freehsize"
		    else
			hsize=some_number
		    fi
		    ;;
		*)
		    if valid_human "$RET"; then
			size=$(human2longint "$RET")
		    fi
		    hsize="$RET"
		    ;;
	    esac
	    
	    if [ -z "$size" ]; then
		db_input high partman-partitioning/bad_new_partition_size || true
		db_go || true
	    fi
63
	done
64 65 66
	if ask_for_type; then break; fi
    done
    return 0
67 68 69
}

ask_for_type () {
70 71 72 73 74 75 76 77 78 79
	local noninteractive has_extended parttype
	has_extended=no
	open_dialog PARTITIONS
	while { read_line x1 x2 x3 parttype x5 x6 x7; [ "$parttype" ]; }; do
	    if [ "$parttype" = logical ]; then
		has_extended=yes
	    fi
	done
	close_dialog

80 81 82 83 84 85 86 87 88 89 90 91
	noninteractive=true
	while true; do
		case "$freetype" in
		primary)
			$noninteractive
			type=Primary
			;;
		logical)
			$noninteractive
			type=Logical
			;;
		pri/log)
92 93 94 95 96
			if [ "$has_extended" = yes ]; then
			    db_set partman-partitioning/new_partition_type Logical
			else
			    db_set partman-partitioning/new_partition_type Primary
			fi
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
			db_input high partman-partitioning/new_partition_type ||
				$noninteractive
			db_go || return 1
			db_get partman-partitioning/new_partition_type
			type="$RET"
		esac
		if ask_for_place; then break; fi
		noninteractive="return 1"
	done
}

ask_for_place () {
	local noninteractive
	noninteractive=true
	while true; do
		if [ "$hsize" = "$freehsize" ]; then
			$noninteractive
			place=full
		else
			db_input high partman-partitioning/new_partition_place ||
				$noninteractive
			db_go || return 1
			db_get partman-partitioning/new_partition_place
			place="$RET"
		fi
		if create_new_partition; then break; fi
		noninteractive="return 1"
	done
}

create_new_partition () {
128
	local num id size type fs path name mp mplist mpcurrent numparts device
129 130 131 132 133 134
	open_dialog NEW_PARTITION $type ext2 $freeid $place $size
	id=''
	read_line num id size type fs path name
	close_dialog

	partitions=''
135
	numparts=1
136
	open_dialog PARTITIONS
137
	while { read_line x1 part x3 x4 x5 x6 x7; [ "$part" ]; }; do
138
	    partitions="$partitions $part"
139
	    numparts=$(($numparts + 1))
140 141 142
	done
	close_dialog
	
143 144 145 146 147 148 149 150 151 152
	db_progress START 0 $numparts partman/text/please_wait
	db_progress INFO partman-partitioning/new_state

	if [ -n "$id" -a -f ../../ext3 ]; then
	    # make better defaults for the new partition
	    [ -d $id ] || mkdir $id
	    echo format >$id/method
	    >$id/format
	    >$id/use_filesystem
	    echo ext3 >$id/filesystem
153 154
	    mkdir $id/options
	    mplist='/ /home /usr /var /tmp /usr/local /opt /srv /boot'
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
	    mpcurrent=$(
		for dev in $DEVICES/*; do
		    [ -d $dev ] || continue
		    cd $dev
		    open_dialog PARTITIONS
		    while { read_line num id size type fs path name; [ "$id" ]; }; do
			[ $fs != free ] || continue
			[ -f "$id/method" ] || continue
			[ -f "$id/acting_filesystem" ] || continue
			[ -f "$id/use_filesystem" ] || continue
			[ -f "$id/mountpoint" ] || continue
			echo $(cat $id/mountpoint) # echo ensures 1 line
		    done
		    close_dialog
		done
	    )
	    for mp in $mpcurrent; do
		mplist=$(echo $mplist | sed "s,$mp,,")
	    done
	    mp=''
	    for mp in $mplist; do
		break
	    done
	    if [ "$mp" ]; then
		echo $mp >$id/mountpoint
	    fi
	    menudir_default_choice /lib/partman/active_partition ext3 mountpoint || true
	    menudir_default_choice /lib/partman/choose_partition partition_tree $dev//$id || true
	    # setting the bootable flag is too much unnecessary work:
	    #   1. check if the disk label supports bootable flag
	    #   2. check if the mount point is / or /boot and the partition
	    #      type is `primary'
	    #   3. get the current flags
	    #   4. add `boot' and set the new flags
	    #   5. moreover, when the boot loader is installed in MBR
	    #      no bootable flag is necessary
	fi

	db_progress STEP 1

195 196
	for part in $partitions; do
	    update_partition $dev $part
197
	    db_progress STEP 1
198 199
	done

200 201
	db_progress STOP

202 203 204
	if [ "$id" ]; then
	    while true; do
		set +e
205 206 207 208 209
		device="$(humandev $(cat device))"
		db_subst partman/active_partition DEVICE "$device"
		db_subst partman/active_partition PARTITION "$num"
		db_metaget partman/text/none_detected description
		db_subst partman/active_partition OTHERINFO "${RET}"
210 211 212 213 214 215 216 217 218 219 220 221 222
		ask_user /lib/partman/active_partition "$dev" "$id"
		exitcode="$?"
		if [ "$exitcode" -ge 100 ]; then
		    break
		fi
		set -e
	    done
	fi
}

ask_for_size || exit $?
exit 0