#!/bin/csh -f

#ifndef _BLURB_
#define _BLURB_
#/*
#                           CODA FILE SYSTEM
#                             Release 1.0
#                      School of Computer Science
#                      Carnegie Mellon University
#                            Copyright 1993
#
#Coda  may  be  used  under license outside Carnegie Mellon University.
#Contact  the  Coda  Project   Coordinator   for   licensing   details.
#Unlicensed use or distribution of this code is illegal.
#*/
#
#
#static char *rcsid = "$Header: /afs/cs/project/coda-src/cvs/coda/coda-src/scripts/recreatevol,v 4.4 1998/01/20 20:53:12 braam Exp $";
#endif _BLURB_

#/*
#                    IBM COPYRIGHT NOTICE
#
#This file contains  some code identical to or  derived from
#the 1986 version of  the Andrew File System, which is owned
#by  the  IBM  Corporation.  Carnegie Mellon  University has
#obtained permission to distribute this code under the terms
#of the Coda License.
#
#*/

#
# Check that we got the correct input
if ($#argv != 3 && $#argv != 4) then
	echo "createvol volname server partition [cycle]"
	exit 
endif

#
# Can only run these scripts from the SCM (Should this change?)
if (`cat /vice/hostname` != `cat /vice/db/scm`) then
        echo "This must be run from the scm ("`cat /vice/db/scm`")"
        exit
endif

set VOLNAME=$1
set SERVER=$2
set PARTITION=$3
if ( $#argv == 4 ) then
    set CYCLE=$4
else
    set CYCLE=""
endif


#
# Create these files if they don't already exist.
touch /vice/vol/AllVolumes
touch /vice/vol/VRList

# Verify a volume by that name does not already exist
if ($VOLNAME == `awk ' $1 ~ /^'$1'$/  {print $1}' /vice/vol/AllVolumes` ||\
    $VOLNAME == `awk ' $1 ~ /^'$1'$/  {print $1}' /vice/vol/VRList`) then
	echo Volume $VOLNAME already exists
	exit
endif

set vol_msg=`volutil -h $SERVER create $PARTITION $VOLNAME`
echo $vol_msg

set VOLID=`echo $vol_msg | awk '{print $7}'`

if ( "$CYCLE" != "" ) then
    echo "echo $VOLID        $CYCLE        $VOLNAME >>/vice/db/dumplist"
    echo "$VOLID        $CYCLE         $VOLNAME" >>/vice/db/dumplist
endif

