#!/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.
#130511 L18L: i18n. ref: http://www.murga-linux.com/puppy/viewtopic.php?t=86084

export TEXTDOMAIN=Pdisk
export OUTPUT_CHARSET=UTF-8

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}$(gettext 'EXIT'):10"

xmessage -bg "#8080ff" -center -name "Pdisk" -title "$(gettext 'Pdisk drive partition manager')" -buttons $BUTPARTS "$(gettext '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!')

$(gettext 'Here are the disk drives that Puppy knows about:')
$ALLINFO

$(gettext '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.')

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

$(gettext '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 "$(gettext 'Pdisk drive partition manager')" -buttons $BUTMANAGE,$(gettext 'EXIT'):10 "$(gettext '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
