#!/bin/sh
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#v3.97 BK bugfix.
#110205 use probedisk2.
#130203 change probedisk2 to probedisk.

if [ -f /usr/sbin/cfdisk -o -f /sbin/cfdisk ];then #v3.97
 BUTMANAGE="fdisk:20,cfdisk:21"
else
 BUTMANAGE="fdisk:20"
fi

ALLINFO="`probedisk 2>/dev/null | grep -v "optical|" | grep -v "/scd"`" #110205
ALLPARTS="`echo "$ALLINFO" | cut -f 1 -d "|" | cut -f 3 -d "/" | tr "\n" " "`"
ALLMNTD="`df | grep "/dev/" | cut -f 1 -d " " | grep -v "loop" | tr "\n" " "`"

butval=20
BUTPARTS=""
for EACHPART in $ALLPARTS
do
BUTPARTS="${BUTPARTS}$EACHPART:$butval,"
butval=`expr $butval + 1`
done
BUTPARTS="${BUTPARTS}EXIT:10"

xmessage -bg "#8080ff" -center -name "Pdisk" -title "Pdisk drive partition manager" -buttons $BUTPARTS "Welcome, this program enables you to run either fdisk, or, if it is
installed, cfdisk. These are utility applications to examine and
modify disk drive partitions. This includes creating and erasing
partitions, so is not for the faint-of-heart!

Here are the disk drives that Puppy knows about:
$ALLINFO

If any drive is wrong or missing, exit this program and run the
\"Mount/unmount drives\" program, that you will find in the \"File 
Managers\" menu. That tool will enable you to probe the hardware.

These partitions are curently mounted:
$ALLMNTD
...you can view these but NOT change them.

To continue this program, click a drive button..."

RETVAL=$?
if [ $RETVAL -lt 11 ];then
 exit
fi

EDITPART="`echo "$BUTPARTS" | tr "," "\n" | grep "$RETVAL" | cut -f 1 -d ":"`"

xmessage -bg "#80C080" -center -name "Pdisk" -title "Pdisk drive partition manager" -buttons $BUTMANAGE,EXIT:10 "Chose the partition manager program that you want to use..."

RETVAL=$?
if [ $RETVAL -lt 11 ];then
 exit
fi

if [ $RETVAL -eq 21 ];then
 rxvt -bg "#C080ff" -e cfdisk /dev/$EDITPART
else
 rxvt -bg "#C080ff" -e fdisk /dev/$EDITPART
fi