#!/bin/sh
#----------------------------------------------------------------------------
# system-devices-vg-create - create volume groups
#
# Creation   : 02.09.2009 schlotze
# Last Update: $Id: system-filesystems-vg-create 16982 2008-10-17 12:52:01Z schlotze $
#
#----------------------------------------------------------------------------
. /var/install/include/anykey
. /var/install/include/mecho
. /var/install/include/techo

echo ""

#exec 2> /tmp/system-devices-vg-create-trace$$.log
#set -x

mecho --info "Create volume groups"
mecho --info "Available physical volumes"
techo begin 4 11 35 6 6 9r 9r
techo row --info "No." --info "PV" --info "VG" --info "Fmt" --info "Attr" --info "PSize" --info "PFree"
mecho --info "================================================================================"

idx=1
pvs > /tmp/tmp_pvs$$
while read line
do
    set -- $line
    if [ "$1" != "PV" ]
    then
        eval pv_$idx='"$1"'
        if [ "$6" = "" ]
        then
            techo row $idx $1 "" $2 $3 $4 $5
        else
            techo row $idx $1 $2 $3 $4 $5 $6
        fi
        idx=`expr $idx + 1`
    fi
done < /tmp/tmp_pvs$$

rm /tmp/tmp_pvs$$

idx=`expr $idx - 1`
nopvdevice=`/var/install/bin/ask "Please choose a physical volume where you want to create the volume group in from the list above" "" "1-$idx" "0=Exit"`
if [ "$nopvdevice" != "0" ]
then
    name=`/var/install/bin/ask "Please enter the name of the volume group you want to create (e.g. volg1) [0=Exit]" "" "+"`
    
    if [ "$name" != "0" ]
    then
        eval "pvdevice"='$pv_'$nopvdevice
        echo "$pvdevice"
        vgcreate $name $pvdevice
    fi
fi
echo ""
anykey
exit 0
