#!/bin/ash
#
# Interactive partitioning tool for PLD Linux installer.
#
# (C) 2001, 2002 Michal Moskal <malekith@pld-linux.org>
#
# This file can be modified and/or redistributed under
# the terms of GPL version 2 (without any options :^).
#
# WARNING: No serviceable parts inside :)
#

PATH=.:..:$PATH 
add_title="_Partitioner"
. installer-functions
. ui-functions

find_config_paths "$@"
load_or_create_config

load_part () {
  local suf
  if test -n "$2" ; then
    suf=`echo $1_$2 | sed -e 's|/|_|g'`
  else
    suf="$1"
  fi
  part_file=
  part_name=
  part_device=
  part_minor=
  part_start=
  part_size=
  part_filesystem=
  part_format=
  part_touch=
  part_fstab_options=defaults
  part_format_options=
  part_mnt_point=
  part_md_list=
  part_md_part_of=
  part_md_level=
  part_md_parity_algorithm=
  part_md_chunk_size=
  part_md_just_start=
  part_md_persistent_superblock=
  part_md_spare=
  if test -f $suf ; then
    . $suf
  elif test -f /tmp/part.$suf ; then
    . /tmp/part.$suf
  else
    part_file=/tmp/part.$suf
    id=1
    name=$(part $1 $2)
    while [ $id -lt 100 ] ; do
      eval_partition_info $id
      if [ "$dest_part_device" = "" ] ; then
        break
      fi

      case "$dest_part_device" in
      "$name" | "$name:"* )
        part_name=$name
        part_device=$1
        part_minor=$2
	part_filesystem="$dest_part_filesystem"
	if [ "$part_filesystem" = linux-swap ] ; then
	  part_filesystem=swap
	fi
	if [ "$part_filesystem" = swap ] ; then
	  part_mnt_point=swap
	else
	  part_mnt_point="$dest_part_mnt_point"
	fi
        part_format="$dest_part_format_partition"
        part_touch=yes
	part_fstab_options="$dest_part_options"
	part_format_options="$dest_part_format_options"
	break
      esac
      
      id=$(($id+1))
    done
  fi
}

load_raid_partitions () {
  id=1

  while [ $id -lt 100 ] ; do
    eval_partition_info $id
    if [ "$dest_part_device" = "" ] ; then
      break
    fi

    case "$dest_part_device" in
    /dev/md* )
      no=$(echo $dest_part_device | sed -e 's|^/dev/md\([0-9]*\).*|\1|')
      load_part /dev/md $no
      # fix it up
      part_file=/tmp/part.md_$no
      part_device=md
      echo $dest_part_device | (IFS=: read device rest; echo $rest) | (
        IFS=, 
	read part_md_level rest
	part_md_list=
	part_md_persistent_superblock=yes
	part_md_just_start=no
	part_md_parity_algorithm=auto
	part_md_chunk_size=auto
	part_md_spare=
	for md_device in $rest ; do
	  unset IFS
	  case $md_device in
	    /dev/*:spare )
	      part_md_spare="$part_md_spare $(
	      	echo $md_device | (IFS=: read fst snd; echo $fst))"
          esac
	  case $md_device in
	    parity_algorithm=* )
	      part_md_parity_algorithm=$(echo $md_device | sed -e 's/.*=//')
	      ;;
	    chunk_size=* )
	      part_md_chunk_size=$(echo $md_device | sed -e 's/.*=//')
	      ;;
	    persistent_superblock=0 )
	      part_md_persistent_superblock=no
	      ;;
	    just_start=1 )
	      part_md_just_start=yes
	      ;;
	    /dev/* )
	      part_md_list="$part_md_list $(
	  	for f in /tmp/part.* ; do
	    	  ( 
	      	    load_part $f
		    case $md_device in
		      "$part_name" | "$part_name":spare )
	                echo -n "$part_file "
	            esac
	          )
	        done)"
              ;;
	  esac
	done
	save_part
	update_md_part_ofs
      )
    esac
    
    id=$(($id+1))
  done
}

save_part () {
  cat > $part_file <<EOF
part_file="$part_file"
part_name="$part_name"
part_device="$part_device"
part_minor="$part_minor"
part_start="$part_start"
part_size="$part_size"
part_filesystem="$part_filesystem"
part_format="$part_format"
part_touch="$part_touch"
part_fstab_options="$part_fstab_options"
part_format_options="$part_format_options"
part_mnt_point="$part_mnt_point"
part_md_list="$part_md_list"
part_md_part_of="$part_md_part_of"
part_md_level="$part_md_level"
part_md_parity_algorithm="$part_md_parity_algorithm"
part_md_chunk_size="$part_md_chunk_size"
part_md_just_start="$part_md_just_start"
part_md_persistent_superblock="$part_md_persistent_superblock"
part_md_spare="$part_md_spare"
EOF
}

update_md_part_ofs () {
  local we_are
  if [ "$part_device" = md ] ; then
    we_are=$part_file
    for f in /tmp/part.* ; do
      (
        load_part $f
        if [ "$part_md_part_of" = "$we_are" ] ; then
	  part_md_part_of=
	  save_part
	fi
      )
    done
    for f in $part_md_list ; do
      (
        load_part $f
	part_md_part_of=$we_are
	save_part
      )
    done
  fi
}

disk_info () {
  for device in $dest_devices ; do
    parted -s $device print | grep '^Disk geometry' | \
    	sed "s|/dev/.*/disc|$device|; s/^/<br>/"
  done
}

partition_items () {
  local number start end rest start_i end_i name type \
        fs flags next_part new_part_info

  new_part_info=/tmp/new_part_info.`basename $1`
  
  echo 'primary 0.000 1' > $new_part_info
  new_part_type=primary
  parted -s $1 print | grep '^[0-9]' \
  | while read number start end type fs flags; do
    start_i=`echo $start | sed -e 's/\..*//'`
    end_i=`echo $end | sed -e 's/\..*//'`
    name=$(part $1 $number)
    next_part=$(($number+1))
    case " $fs $flags " in
      *" raid "* )
        fs=md
	flags=
	;;
    esac
    if [ "$number" -ge 3 ] ; then
      new_part_type=logical
      if [ $next_part = 4 ] ; then
        next_part=5
      fi
    fi
    if [ "$type" = extended ] ; then
      new_part_type=logical
      echo "$new_part_type $start $next_part" > $new_part_info
    else
      echo "$new_part_type $end $next_part" > $new_part_info
    fi
    load_part $1 $number
    if [ "$part_name" = "" ] ; then
      part_name=$name
      part_device=$1
      part_minor=$number
      if [ "$fs" = "linux-swap" ] ; then
        fs=swap
	part_mnt_point=swap
      elif [ "$fs" = "md" ] ; then
        part_mnt_point=md
      elif [ "$type" = extended ] ; then
        fs=extended
      fi
      part_filesystem=$fs
      part_format=no
      part_touch=no
    fi
    part_size=$(($end_i-$start_i))
    part_start=$start
    save_part 
    echo -n "<item id='${1}@${number}'>"
    printf "%-10s %10.3f %5dMb %-20s : %s" $name $start $(($end_i-$start_i)) \
	"$part_mnt_point ($part_filesystem)" "$flags"
  done

}

raid_items () {
  for f in /tmp/part.md* ; do
    if test -f $f ; then
      load_part $f
      echo -n "<item id='md@${part_minor}'>"
      printf "%-10s %10s %7s %-20s : %s" "/dev/md${part_minor}" "" "" \
			"$part_mnt_point ($part_filesystem)" ""
    fi
  done
}

# reads other command output and displays it
show_result () {
  local output
  log info "running $*"
  dial "<meta res=1>$(nls Running:)<br>$*<br>$(nls "Please wait...")"
  output=$("$@" < /dev/null 2>&1)
  res=$?
  if test "$output"; then
    log info "output = $output"
    output=$(echo "$output" | sed 's/.\{60\}/&<br>/g; s/^/<br>/')
    dial <<EOF
    <br>$*:
    <br>$output
    <br><button>
EOF
  fi
  log info "res = $res"

  return $res
}

remove () {
  if yes_no no "$(nls "Ary you sure to remove %s?" "$part_name")" ; then
    show_result parted -s $part_device rm $part_minor
    part_md_list= update_md_part_ofs
    if test -n "$part_md_part_of" ; then
      file=$part_file
      (
        load_part $part_md_part_of
	all=
	for f in $part_md_list ; do
	  if [ "$f" != "$file" ] ; then
	    all="$all $f"
	  fi
	done
	part_md_list="$all"
	save_part
      )
    fi
    rm -f $part_file
  fi
}

resize () {
  dial <<EOF
$(nls "Enter new size of partition (in megabytes):")<br>
<input caption="$part_size" id=new_size><br>
$ok_cancel
EOF

  if [ "$res" = 1 -a $new_size -gt 2 ] ; then
    end=$((`echo $part_start | sed -e 's/\..*//'`+$new_size))
    show_result parted -s $part_device resize $part_minor $part_start $end
  fi
}

check_box () {
  local val id
  id=$1
  eval val=\$$1
  shift
  case "$val" in
  yes )
    echo -n "<check checked=1 id=$id $*>"
    ;;
  * )
    echo -n "<check checked=0 id=$id $*>"
    ;;
  esac
}

input_box () {
  local val id
  id=$1
  eval val=\$$1
  shift
  echo -n "<input id=$id caption='$val' $*>"
}

raid_help () {
  dial <<EOF
<text width=70 height=17>
$(nls "Linear RAID simply concatenates devices. They are filled ")
$(nls "sequentially. Read performance might increase compared to")
$(nls "single drive.")
<br><br>
$(nls "RAID level 0 is like linear except writes are done in parallel,")
$(nls "so all devices are filled to the same size. Devices doesn't have ")
$(nls "to be of the same size, but should be. It is fastest software RAID,")
$(nls "read/write speed is roughly number-of-devices times better then")
$(nls "single drive.")
<br><br>
$(nls "RAID 1 is mirroring, devices need to be the same size.")
<br><br>
$(nls "RAID 4 is much like RAID 5 except is uses just one disk for parity")
$(nls "information, making it bottleneck.")
<br><br>
$(nls "RAID 5 can be used on 3 or more devices of the same size. If one of")
$(nls "them burns -- it repairs itself, if two burn -- your users will burn")
$(nls "you :) Performance will increase compared to single drive.")
<br><br>
$(nls "Chunk size is expressed in kilobytes. 'auto' should work reasonably.")
<br><br>
$(nls "Spare devices is whitespace separated list of devices, that will be used")
$(nls "as replacement when one of working disks burn. It is supported only")
$(nls "by RAID levels 1, 4 and 5.")
<br><br>
$(nls "Persistent super-block is a special block, which is written in the ")
$(nls "beginning of all disks participating in the array. It is used during")
$(nls "machine boot, better leave it with 'yes'.")
<br><br>
$(nls "Check 'Just start, no mkraid' if you want to use existing RAID array.")
<br><br>
$(nls "Also don't bother changing parity-algorithm if you are not sure")
$(nls "what it does.")
</text>
<button>
EOF
}

raid_stuff () {
  current_md=$part_file
  
  nls "Partitions contained in this RAID array:"
  echo "<menu id=part_md_list checked='$part_md_list'>"
  for f in /tmp/part.* ; do
    (
      load_part $f
      case "$part_filesystem:$part_md_part_of" in
        md: | md:$current_md )
	  printf "<item checked=0 id=$f>%-20s %6dMB" "$part_name" "$part_size"
      esac
    )
  done
  echo "</menu><br>"

  cat <<EOF
<menu hidden=1 id=md_level>
<item id=raidl>$(nls "Linear RAID")
<item id=raid0>$(nls "RAID level 0")
<item id=raid1>$(nls "RAID level 1 (mirroring)")
<item id=raid4>$(nls "RAID level 4")
<item id=raid5>$(nls "RAID level 5")
</menu>
<menu hidden=1 id=pa>
<item id=auto>auto
<item id=left-symmetric>left-symmetric
<item id=right-symmetric>right-symmetric
<item id=left-asymmetric>left-asymmetric
<item id=right-asymmetric>right-asymmetric
</menu>
$(check_box part_md_persistent_superblock) $(nls "Persistent superblock.")
 $(check_box part_md_just_start) $(nls "Just start, no mkraid.")<br>
$(nls "Chunk size       :") $(input_box part_md_chunk_size)<br>
$(nls "Spare devices    :") $(input_box part_md_spare)<br>
$(nls "RAID level       :") $(input_box part_md_level menu=md_level)<br>
$(nls "Parity algorithm :") $(input_box part_md_parity_algorithm menu=pa)<br>
EOF

}

actions () {
  device=$(echo $part_id | sed -e 's/@.*//')
  part_no=$(echo $part_id | sed -e 's/.*@//')
  load_part $device $part_no
  if [ "$part_filesystem" = extended ] ; then
    dial <<EOF
<meta title="$part_name">
<br>
This is extended partition.
<br><br>
<button res=1>
 <button res=2 caption="$(nls "_Resize")"> 
 <button res=3 caption="$(nls "_Remove")"> 
EOF
  else
    dial <<EOF
<meta title="$part_name">
$(filesystems_menu hidden)
$(nls "Mount point   :") <input id=part_mnt_point caption="$part_mnt_point"><br>
$(nls "Filesystem    :") <input id=part_filesystem menu=fs caption="$part_filesystem"><br>
$(nls "fstab options :") <input id=part_fstab_options caption="$part_fstab_options"><br>
$(nls "mkfs options  :") <input id=part_format_options caption="$part_format_options"><br>
$(check_box part_format) $(nls "Create a filesystem on this partition.")<br>
$(check_box part_touch) $(nls "Mount during installation and add to fstab.")<br>
<button res=1> 
 <button res=2 caption="$(nls "_Resize")"> 
 <button res=3 caption="$(nls "_Remove")"> 
$(if [ "$part_device" = md ] ; then
    echo "<button res=5 caption='$(nls "_RAID options")'>"
  fi)
 <button res=4 caption="$(nls "_Cancel")">
EOF
  fi

  while [ "$res" = 5 ] ; do
      dial <<EOF
<meta title="$(nls "RAID Options")">
$(raid_stuff)
<button res=1> <button res=2 caption="$(nls "_Help")">
 <button res=4 caption="$(nls "_Cancel")">
EOF
    if [ "$res" = 2 ] ; then
      raid_help
      res=5
    fi
  done

  
  case $res in
    1)
      if [ "$part_touch" = no ] ; then
        case "$part_mnt_point" in
	  md | swap | "" )
	    : ok
	    ;;
	  * )
            # this sounds a bit stupid now... 
            info "
$(nls "You have setup mountpoint, but you hasn't told the installer")<br>
$(nls "to use this partition. Check 'Mount during installation ...'")<br>
$(nls "to mount it during installation and include it in /etc/fstab.")"
        esac
      fi
      update_md_part_ofs
      save_part
      ;;
    2)
      update_md_part_ofs
      save_part
      resize
      ;;
    3)
      remove
      ;;
    4)
      ;;
  esac
}

filesystems_menu () {
  if [ $KERNEL_VERCODE -ge 4 ] ; then
    xfs="<item id=xfs>$(nls "xfs: _Journaling FS from SGI")
"
    ext3="<item id=ext3>$(nls "ext_3 (ext2 + Journaling)")
"
  else
    xfs=
    ext3=
  fi
  
  echo -n '<menu id=fs '

  case "$1" in
    hidden )
      echo "hidden=1>"
      ;;
    *)
      echo "res=1>"
      ;;
  esac

  cat <<EOF
<item id=ext2>$(nls "_Second _Extended (ext2)")
<item id=swap>$(nls _Swapspace)
<item id=reiserfs>$(nls "_Reiser FS")
<item id=md>$(nls "_RAID building partition")
$xfs<item id=jfs>$(nls "jfs: _Journaling FS from IBM")
$ext3</menu>
EOF
}

make_new () {
  choose_disk || return 0
  
  dial <<EOF
<meta title="$(nls "Filesystem")">
$(filesystems_menu)
$ok_cancel
EOF
  if [ "$res" != 1 ] ; then
    return 0
  fi
  disk_end=$(parted -s $device print | \
  	     grep 'Disk geometry' | \
	     sed -e 's/.*-//' | \
	     sed -e 's/\..*//')
  read JUNK new_part_start JUNK < /tmp/new_part_info.`basename $device`
  new_part_start=$(echo "$new_part_start" | sed -e 's/\..*//')
  remaining=$(($disk_end-$new_part_start-1))
  disk_end=$(($disk_end-1)).999
  get_input size $remaining "$(nls "Filesystem: %s" "$fs"
  	)<br>$(nls "Enter size of partition to create (in Mb):"
	)<br>$(nls "Free space: %d Mb" $remaining)"
  if [ "$?" != 0 -o "$size" -lt 3 ] ; then
    return 0
  fi
  
  case "$fs" in
  xfs | jfs | ext3 | reiserfs )
    if [ $size -lt 50 ] ; then
      dial <<EOF
$(nls "Sorry, but journaling filesystem (%s)" "$fs")<br>
$(nls "cannot be created on such a tiny partition!")<br>
<button>
EOF
      return 0
    fi
  esac
  
  case "$fs" in
  swap )
    mnt=swap
    new_part_fs=linux-swap
    ;;
  md )
    mnt=md
    new_part_fs=ext2	# fake, we do ,,set raid on'' later
    ;;
  * )
    new_part_fs=$fs
    dial <<EOF
$(nls "Filesystem: %s" "$fs")<br>
$(nls "Size: %d" "$size")<br>
$(nls "Please choose mountpoint for this partition:")
<menu id=mnt res=1>
<item id=/>/ ($(nls "Root filesystem"))
<item id=/boot>/boot
<item id=/home>/home
<item id=/usr>/usr
<item id=/var>/var
<item id=/var/spool>/var/spool
<item id=/var/mail>/var/mail
<item id=/var/cache>/var/cache
<item id=/home/users>/home/users
<item id=custom>$(nls "_C_u_s_t_o_m")
<item id=skip>$(nls "Don't use for installation.")
</menu>
$ok_cancel
EOF
    
    if [ "$res" != 1 ] ; then
      return 0
    fi

    if [ "$mnt" = custom ] ; then
      if get_input mnt / "$(nls "Enter mount point for partition:")" ; then
        :
      else
        return 0
      fi
    fi
  esac
  
  read new_part_type new_part_start new_part_no < /tmp/new_part_info.`basename $device`
 
  if [ "$new_part_no" = 5 ]  ; then
    if parted -s $device print | grep -q ' extended ' ; then
      # ok, we already have extended partition
      :
    else
      if yes_no yes "
$(nls "Due the limitations of msdos disk label, in order to create")<br>
$(nls "this partition you will need extended partition first.")<br>
<br>
$(nls "Would you like to create it?")<br>
<br>
$(nls "If you choose \"No\" this program will terminate.")<br>" ; then
        show_result parted -s $device mkpart extended $new_part_start $disk_end
      else
        exit 1
      fi
    fi
  fi
  
  end=$((`echo $new_part_start | sed -e 's/\..*//'`+$size-1)).999
  show_result parted -s $device mkpart $new_part_type $new_part_fs \
  	$new_part_start $end || return
  if [ "$fs" = md ] ; then
    show_result parted -s $device set $new_part_no raid on || return
  fi
 
  # clear part_* stuff:
  load_part /dev/null
  part_file=/tmp/part.$(echo ${device}_$new_part_no | sed -e 's|/|_|g')
  part_filesystem=$fs
  if [ "$mnt" = skip ] ; then
    part_format=no
    part_touch=no
    part_mnt_point=""
  else
    part_mnt_point="$mnt"
    part_format=yes
    part_touch=yes
  fi

  part_minor=$new_part_no
  part_device=$device
  part_name=$(part $device $new_part_no)
 
  save_part
}

# set $device
last_device=
choose_disk () {
  device=
  for f in $dest_devices ; do
    if test "$device" ; then
      break
    fi
    device=$f
    f=
  done
  
  if test -z "$f" ; then
    return 0
  fi

  device=$last_device
  
  dial <<EOF 
<meta title="$(nls "Choose disk")">
<menu id=device selected=$device res=1>
$(
  for f in $dest_devices ; do
    name=$(disk_name $f)
    echo "<item id=$f>$f $name"
  done
)
</menu>
<button>
EOF

  last_device=$device
}

init_disklabels () {
  for device in $dest_devices ; do
    if parted -s $device print | grep -q 'Error: .* unrecogni.ed disk label' ; then
      if yes_no no "
$(nls 'Parted was unable to recognize disk label on %s.' "$device")<br>
$(nls 'If it is new disk, it is highly possible, that it simply')<br>
$(nls 'does not contain any partitions, so you can safely choose')<br>
$(nls '"Yes" here. Otherwise, if you are sure that there are some')<br>
$(nls 'partitions on this disk, you should choose "No", and check')<br>
$(nls 'possible reasons by running parted by hand.')<br>
<br>
$(nls 'Create new empty disk label?')<br>" ; then
      parted -s $device mklabel msdos
      else
        exit 1
      fi
    fi
  done
}

encoded_raid_device () {
  val="/dev/md$part_minor:$part_md_level"
  for f in $part_md_list ; do
    dev=$(load_part $f; echo $part_name)
    spare=
    if echo " $part_md_spare " | grep -q " $dev " ; then
      spare=:spare
    fi
    val="${val},${dev}${spare}"
  done

  if [ "$part_md_persistent_superblock" = no ] ; then
    val="$val,persistent_superblock=0"
  fi

  if [ "$part_md_just_start" = yes ] ; then
    val="$val,just_start=1"
  fi

  if [ "$part_md_parity_algorithm" != auto ] ; then
    val="$val,parity_algorithm=$part_md_parity_algorithm"
  fi
  
  if [ "$part_md_chunk_size" != auto ] ; then
    val="$val,chunk_size=$part_md_chunk_size"
  fi

  echo $val | sed -e 's/ //g'
}

save_it () {
  load_config
  
  # clean up
  id=1
  while [ $id -lt 100 ] ; do
    eval dest_part${id}_mnt_point=
    eval dest_part${id}_device=
    id=$(($id+1))
  done

  id=1
  devs=
  actions=
  
  for f in /tmp/part.* ; do
    load_part $f
    if [ "$part_touch" = no ] ; then
      continue
    fi
    if [ "$part_filesystem" = linux-swap -o "$part_filesystem" = swap ] ; then
      part_filesystem=swap
      part_mnt_point=swap
    fi
   
    if [ "$part_device" = md ] ; then
      eval "dest_part${id}_device=\"$(encoded_raid_device)\""
    else
      eval "dest_part${id}_device=\"$part_name\""
    fi
    eval "dest_part${id}_mnt_point=\"$part_mnt_point\""
    eval "dest_part${id}_filesystem=\"$part_filesystem\""
    eval "dest_part${id}_format_partition=\"$part_format\""
    eval "dest_part${id}_options=\"$part_fstab_options\""
    eval "dest_part${id}_format_options=\"$part_format_options\""
    eval "dest_part${id}_size=\"$part_size\""	# just for reference
    
    log info "saved part #$id, $part_name on $part_mnt_point ($part_size MB, $part_filesystem)"

    if [ "$part_device" != md ] ; then
      if echo " $devs " | grep -q " $part_device " ; then
        :
      else
        devs="$devs $part_device"
        actions="$actions use_existing"
      fi
    fi
    
    id=$(($id+1))
  done

  eval "dest_devices=\"$devs\""
  eval "dest_devices_actions=\"$actions\""

  save_config
}

make_new_md () {
  try=0

  while [ $try -le 15 ] ; do
    if test -f /tmp/part.md_$try ; then
      :
    else
      break
    fi
    try=$(($try+1))
  done
  load_part /dev/null

  part_minor=$try
  part_file=/tmp/part.md_$part_minor
  part_device=md
  part_name=/dev/md$part_minor
  part_filesystem=ext2
  part_format=yes
  part_touch=yes
  part_fstab_options=defaults
  part_mnt_point=/
  part_md_level=raid5
  part_md_parity_algorithm=auto
  part_md_chunk_size=auto
  part_md_just_start=no
  part_md_persistent_superblock=yes
  part_md_spare=""

  save_part

  dial <<EOF
$(nls "New RAID entry for %s created." "$part_name")<br><br>
$(nls "Press [Enter] on it to set it up. Note that in order")<br>
$(nls "to add partitions to this array, you first need to")<br>
$(nls "create some partitions with ,,filesystem'' set to 'md'.")<br>
             <button>
EOF
  
}

#######
# Main
######

load_parted || exit 1

dev=
for dev in $dest_devices ; do
  :
done

if [ "$dev" = "" ] ; then
  info "Sorry, but dest_devices is empty."
  exit 1
fi

case $arch in
  ppc )
    dial <<EOF
<meta title="$(nls 'Warning!')">
<br>
$(nls "It is not recommended to create partition in mac disklabel using<br>")
$(nls "this tool. You should make them manually with parted, and only<br>")
$(nls "assign mount-points/filesystems to them here.<br>")
$(nls "Also note, that for proper boot you should have Apple_bootstrap<br>")
$(nls "partition as second on first hard drive. And one more thing:<br>")
$(nls "when making partitions with parted, don't leave gaps between them.<br>")
<br>
$(nls "In order to use parted to make partitions, switch to different<br>")
$(nls "console now, and run it (it has just been loaded). Additionally<br>")
$(nls "you might want to use pdisk: type load_package pdisk to get it.<br>")
<br>
                               <button>
EOF
esac

init_disklabels

part_no=1

rm -f /tmp/part.*
echo -n > /tmp/need-load-raid

while : ; do
  dial <<EOF
<meta title="$(nls "Partition Editor")">
<br>
$(nls "Press enter on partition to see available actions.")<br>
`disk_info`<br><br>
$(nls "Device          Start    Size Mount point (fs)     : Flags")<br>
<menu res=1 id=part_id selected=$part_no>
$(
  for f in $dest_devices ; do
    partition_items $f
  done
  if test -f /tmp/need-load-raid ; then
    # need to do that after partition_items has been called
    load_raid_partitions
    rm -f /tmp/need-load-raid
  fi
  raid_items
)
</menu>
<br>
<button res=1 caption="$(nls "_Actions")">
 <button res=2 caption="$(nls "_Make new partition")"><br>
<button res=3 caption="$(nls "_Make RAID array")">
 <button res=4 caption="$(nls '_Leave partitioner')">
EOF
  case $res in
  1)
    actions
    ;;
  2)
    make_new
    ;;
  3)
    make_new_md
    ;;
  4)
    save_it
    exit 0
    ;;
  esac
done

# vim:ft=sh
