#!/bin/sh
set -u  # force better programming and ability to use check for not set
if [ "${1:-}" = "-x" ] ; then set -xv; shift; fi

# bin/$RCSfile$  $Revision$

# declare the volumes used on the rip test system

USAGE="`basename $0` <red50|red20|ait|dlt|mam|disk|null|samait|samdlt|sammam>"

if [ -z "${1-}" ] ; then
  echo "$USAGE"
  exit 1
fi

case $1 in
  red50) rm -fr    /pnfs/stk/red50/*
         mkdir     /pnfs/stk/red50/volmap
	 chmod 777 /pnfs/stk/red50/volmap
         volumes_del="
                      000004
                      000005
                      000006
                      000007
                      000008
                      000009
                     "
#                     label  lib   ff   medtype capacity    bytes left
         volumes="
                      000004 red50 none redwood 50000000000 50000000000
                      000005 red50 none redwood 50000000000 50000000000
                      000006 red50 none redwood 50000000000 50000000000
                      000007 red50 none redwood 50000000000 50000000000
                      000008 red50 none redwood 50000000000 50000000000
                      000009 red50 none redwood 50000000000 50000000000
                     "
         ;;
  red20) rm -fr    /pnfs/stk/red20/*
         mkdir     /pnfs/stk/red20/volmap
	 chmod 777 /pnfs/stk/red20/volmap
         volumes_del="
                      000020
                      000021
                      000022
                      000023
                      000024
                      000025
                      000026
                      000027
                      000028
                      000030
                      000031
                      000032
                      000033
                      000034
                      000035
                      000036
                      000037
                      000038
                      000039
                     "
#                     label  lib   ff   medtype capacity    bytes left
         volumes="
                      000020 red20 none redwood 20000000000 20000000000
                      000021 red20 none redwood 20000000000 20000000000
                      000022 red20 none redwood 20000000000 20000000000
                      000023 red20 none redwood 20000000000 20000000000
                      000024 red20 none redwood 20000000000 20000000000
                      000025 red20 none redwood 20000000000 20000000000
                      000026 red20 none redwood 20000000000 20000000000
                      000027 red20 none redwood 20000000000 20000000000
                      000028 red20 none redwood 20000000000 20000000000
                      000030 red20 none redwood 20000000000 20000000000
                      000031 red20 none redwood 20000000000 20000000000
                      000032 red20 none redwood 20000000000 20000000000
                      000033 red20 none redwood 20000000000 20000000000
                      000034 red20 none redwood 20000000000 20000000000
                      000035 red20 none redwood 20000000000 20000000000
                      000036 red20 none redwood 20000000000 20000000000
                      000037 red20 none redwood 20000000000 20000000000
                      000038 red20 none redwood 20000000000 20000000000
                      000039 red20 none redwood 20000000000 20000000000
                     "
         ;;
  ait)   rm -fr    /pnfs/grau/ait/*
         mkdir     /pnfs/grau/ait/volmap
	 chmod 777 /pnfs/grau/ait/volmap
         volumes_del="
                      CA2901
                      CA2902
                      CA2903
                      CA2904
                      CA2905
                      CA2906
                      CA2907
                      CA2908
                      CA2909
                      CA2910
                      CA2911
                      CA2912
                      CA2913
                      CA2914
                      CA2915
                      CA2916
		      CA2917
		      CA2918
		      CA2919
		      CA2920
                      CA2921
                      CA2922
                      CA2923
                      CA2924
                      CA2925
                      CA2926
                      CA2927
                      CA2928
                      CA2929
                      CA2930
                      CA2931
                      CA2932
                      CA2933
                      CA2934
                      CA2935
                      CA2936
		      CA2937
		      CA2938
		      CA2939
		      CA2940
                      CA2941
                      CA2942
                      CA2943
                      CA2944
                      CA2955
                      CA2956
		      CA2957
		      CA2958
		      CA2959
		      CA2960
                     "
#                     label  lib   ff   medtype  capacity   bytes left
         volumes="
                      CA2901 ait   none 8MM     26016563200 26016563200
                      CA2902 ait   none 8MM     26016563200 26016563200
                      CA2903 ait   none 8MM     26016563200 26016563200
                      CA2904 ait   none 8MM     26016563200 26016563200
                      CA2905 ait   none 8MM     26016563200 26016563200
                      CA2906 ait   none 8MM     26016563200 26016563200
                      CA2907 ait   none 8MM     26016563200 26016563200
                      CA2908 ait   none 8MM     26016563200 26016563200
                      CA2909 ait   none 8MM     26016563200 26016563200
                      CA2910 ait   none 8MM     26016563200 26016563200
                      CA2911 ait   none 8MM     26016563200 26016563200
                      CA2912 ait   none 8MM     26016563200 26016563200
                      CA2913 ait   none 8MM     26016563200 26016563200
                      CA2914 ait   none 8MM     26016563200 26016563200
                      CA2915 ait   none 8MM     26016563200 26016563200
                      CA2916 ait   none 8MM     26016563200 26016563200
                      CA2917 ait   none 8MM     26016563200 26016563200
                      CA2918 ait   none 8MM     26016563200 26016563200
                      CA2919 ait   none 8MM     26016563200 26016563200
                      CA2920 ait   none 8MM     26016563200 26016563200
                      CA2921 ait   none 8MM     26016563200 26016563200
                      CA2922 ait   none 8MM     26016563200 26016563200
                      CA2923 ait   none 8MM     26016563200 26016563200
                      CA2924 ait   none 8MM     26016563200 26016563200
                      CA2925 ait   none 8MM     26016563200 26016563200
                      CA2926 ait   none 8MM     26016563200 26016563200
                      CA2927 ait   none 8MM     26016563200 26016563200
                      CA2928 ait   none 8MM     26016563200 26016563200
                      CA2929 ait   none 8MM     26016563200 26016563200
                      CA2930 ait   none 8MM     26016563200 26016563200
                      CA2931 ait   none 8MM     26016563200 26016563200
                      CA2932 ait   none 8MM     26016563200 26016563200
                      CA2933 ait   none 8MM     26016563200 26016563200
                      CA2934 ait   none 8MM     26016563200 26016563200
                      CA2935 ait   none 8MM     26016563200 26016563200
                      CA2936 ait   none 8MM     26016563200 26016563200
                      CA2937 ait   none 8MM     26016563200 26016563200
                      CA2938 ait   none 8MM     26016563200 26016563200
                      CA2939 ait   none 8MM     26016563200 26016563200
                      CA2940 ait   none 8MM     26016563200 26016563200
                      CA2941 ait   none 8MM     26016563200 26016563200
                      CA2942 ait   none 8MM     26016563200 26016563200
                      CA2943 ait   none 8MM     26016563200 26016563200
                      CA2944 ait   none 8MM     26016563200 26016563200
                      CA2955 ait   none 8MM     26016563200 26016563200
                      CA2956 ait   none 8MM     26016563200 26016563200
                      CA2957 ait   none 8MM     26016563200 26016563200
                      CA2958 ait   none 8MM     26016563200 26016563200
                      CA2959 ait   none 8MM     26016563200 26016563200
                      CA2960 ait   none 8MM     26016563200 26016563200
                     "
         ;;
  samait)rm -fr    /pnfs/sam/ait/*
         mkdir     /pnfs/sam/ait/volmap
	 chmod 777 /pnfs/sam/ait/volmap
         volumes_del="
                      CA2945
                      CA2946
                      CA2947
                      CA2948
                      CA2949
                     "
#                     label  lib      ff   medtype capacity    bytes left
         volumes="
                      CA2945 samait   none 8MM     26016563200 26016563200
                      CA2946 samait   none 8MM     26016563200 26016563200
                      CA2947 samait   none 8MM     26016563200 26016563200
                      CA2948 samait   none 8MM     26016563200 26016563200
                      CA2949 samait   none 8MM     26016563200 26016563200
                     "
         ;;
  mam)
         #rm -fr    /pnfs/grau/mammoth/*
         #mkdir     /pnfs/grau/mammoth/volmap
	 #chmod 777 /pnfs/grau/mammoth/volmap
	 volumes_del=""
	 volumes=""
         n=2250;
	 while [ $n -le 2299 ]; do
		volumes_del="$volumes_del
CA$n"
# label lib   ff    medtype   capacity      bytes left
		volumes="$volumes
CA$n mam none 8MM 20113227776 20113227776"
		n=`expr $n + 1`
	 done
         ;;
## sammam)rm -fr    /pnfs/sam/mammoth/*
##        mkdir     /pnfs/sam/mammoth/volmap
##	 chmod 777 /pnfs/sam/mammoth/volmap
##         volumes_del="
##                      CA2270
##                      CA2271
##                      CA2272
##                      CA2273
##                      CA2274
##                     "
#                     label  lib   ff   medtype capacity    bytes left
##         volumes="
##                      CA2270 sammam   none 8MM     20113227776 20113227776
##                      CA2271 sammam   none 8MM     20113227776 20113227776
##                      CA2272 sammam   none 8MM     20113227776 20113227776
##                      CA2273 sammam   none 8MM     20113227776 20113227776
##                      CA2274 sammam   none 8MM     20113227776 20113227776
##                     "
##         ;;
  dlt)   rm -fr    /pnfs/grau/dlt/*
         mkdir     /pnfs/grau/dlt/volmap
	 chmod 777 /pnfs/grau/dlt/volmap
         volumes_del="
                      CA2501
                      CA2502
                      CA2503
                      CA2504
                      CA2505
                      CA2506
                      CA2507
                      CA2508
                      CA2509
                      CA2510
                      CA2511
                      CA2512
                      CA2513
                      CA2514
                      CA2515
                      CA2516
                     "
#                     label  lib   ff   medtype capacity    bytes left
         volumes="
                      CA2501 dlt   none DECDLT  35520749568 35520749568
                      CA2502 dlt   none DECDLT  35520749568 35520749568
                      CA2503 dlt   none DECDLT  35520749568 35520749568
                      CA2504 dlt   none DECDLT  35520749568 35520749568
                      CA2505 dlt   none DECDLT  35520749568 35520749568
                      CA2506 dlt   none DECDLT  35520749568 35520749568
                      CA2507 dlt   none DECDLT  35520749568 35520749568
                      CA2508 dlt   none DECDLT  35520749568 35520749568
                      CA2509 dlt   none DECDLT  35520749568 35520749568
                      CA2510 dlt   none DECDLT  35520749568 35520749568
                      CA2511 dlt   none DECDLT  35520749568 35520749568
                      CA2512 dlt   none DECDLT  35520749568 35520749568
                      CA2513 dlt   none DECDLT  35520749568 35520749568
                      CA2514 dlt   none DECDLT  35520749568 35520749568
                      CA2515 dlt   none DECDLT  35520749568 35520749568
                      CA2516 dlt   none DECDLT  35520749568 35520749568
                     "
         ;;
  samdlt)rm -fr    /pnfs/sam/dlt/*
         mkdir     /pnfs/sam/dlt/volmap
	 chmod 777 /pnfs/sam/dlt/volmap
         volumes_del="
                      CA2545
                      CA2546
                      CA2547
                      CA2548
                      CA2549
                     "
#                     label  lib   ff   medtype capacity    bytes left
         volumes="
                      CA2545 samdlt   none DECDLT  35520749568 35520749568
                      CA2546 samdlt   none DECDLT  35520749568 35520749568
                      CA2547 samdlt   none DECDLT  35520749568 35520749568
                      CA2548 samdlt   none DECDLT  35520749568 35520749568
                      CA2549 samdlt   none DECDLT  35520749568 35520749568
                     "
         ;;

  null)
         #rm -fr    /pnfs/rip6/*
         #rm -fr    /raid/rip6/*
         #mkdir     /pnfs/rip6/volmap
	 #chmod 777 /pnfs/rip6/volmap
	 volumes_del=""
	 volumes=""
	 for l in 1 7 I; do
       	    n=1;
	    while [ $n -le 50 ]; do
		volumes_del="$volumes_del
null${l}-$n"
# label      lib   ff    medtype   capacity      bytes left
		volumes="$volumes
null${l}-$n null$l none  nullfile  2147483648000 2147483648000"
		n=`expr $n + 1`
	    done
	 done
	 ;;
  disk)
         #rm -fr    /pnfs/rip6/*
         #rm -fr    /raid/rip6/*
         #mkdir     /pnfs/rip6/volmap
	 #chmod 777 /pnfs/rip6/volmap
	 volumes_del=""
	 volumes=""
	 for l in 1 7 I; do
       	    n=1;
	    while [ $n -le 59 ]; do
		volumes_del="$volumes_del
null${l}-$n"
		n=`expr $n + 1`
	    done
	 done
#                     label    lib   ff    medtype   capacity    bytes left
         volumes="
                      disk-01 disk none  diskfile       140000      140000
                      disk-02 disk none  diskfile       140000      140000
                      disk-03 disk none  diskfile      1400000     1400000
                      disk-04 disk none  diskfile     14000000     1400000
                      disk-05 disk none  diskfile     14000000    14000000
                      disk-06 disk none  diskfile     14000000    14000000
                      disk-07 disk none  diskfile    140000000   140000000
                      disk-08 disk none  diskfile    140000000   140000000
                      disk-09 disk none  diskfile   1400000000  1400000000
                      disk-11 disk none  diskfile       140000      140000
                      disk-12 disk none  diskfile       140000      140000
                      disk-13 disk none  diskfile      1400000     1400000
                      disk-14 disk none  diskfile     14000000     1400000
                      disk-15 disk none  diskfile     14000000    14000000
                      disk-16 disk none  diskfile     14000000    14000000
                      disk-17 disk none  diskfile    140000000   140000000
                      disk-18 disk none  diskfile    140000000   140000000
                      disk-19 disk none  diskfile   1400000000  1400000000
                      disk-21 disk none  diskfile       140000      140000
                      disk-22 disk none  diskfile       140000      140000
                      disk-23 disk none  diskfile      1400000     1400000
                      disk-24 disk none  diskfile     14000000     1400000
                      disk-25 disk none  diskfile     14000000    14000000
                      disk-26 disk none  diskfile     14000000    14000000
                      disk-27 disk none  diskfile    140000000   140000000
                      disk-28 disk none  diskfile    140000000   140000000
                      disk-29 disk none  diskfile   1400000000  1400000000
                      disk-31 disk none  diskfile       140000      140000
                      disk-32 disk none  diskfile       140000      140000
                      disk-33 disk none  diskfile      1400000     1400000
                      disk-34 disk none  diskfile     14000000     1400000
                      disk-35 disk none  diskfile     14000000    14000000
                      disk-36 disk none  diskfile     14000000    14000000
                      disk-37 disk none  diskfile    140000000   140000000
                      disk-38 disk none  diskfile    140000000   140000000
                      disk-39 disk none  diskfile   1400000000  1400000000
                      disk-41 disk none  diskfile       140000      140000
                      disk-42 disk none  diskfile       140000      140000
                      disk-43 disk none  diskfile      1400000     1400000
                      disk-44 disk none  diskfile     14000000     1400000
                      disk-45 disk none  diskfile     14000000    14000000
                      disk-46 disk none  diskfile     14000000    14000000
                      disk-47 disk none  diskfile    140000000   140000000
                      disk-48 disk none  diskfile    140000000   140000000
                      disk-49 disk none  diskfile   1400000000  1400000000
                      disk-51 disk none  diskfile       140000      140000
                      disk-52 disk none  diskfile       140000      140000
                      disk-53 disk none  diskfile      1400000     1400000
                      disk-54 disk none  diskfile     14000000     1400000
                      disk-55 disk none  diskfile     14000000    14000000
                      disk-56 disk none  diskfile     14000000    14000000
                      disk-57 disk none  diskfile    140000000   140000000
                      disk-58 disk none  diskfile    140000000   140000000
                      disk-59 disk none  diskfile   1400000000  1400000000
                     "
         ;;
  *)     echo "$USAGE"
         exit 1
         ;;
esac

oldifs="$IFS"
IFS="
"
newifs="$IFS"

# Delete all the old volumes, just in case they are already defined
for vol in ${volumes_del}; do
  IFS=$oldifs
  vol=`echo $vol`
  if [ "${vol}x" != "x" ] ; then
    echo enstore volume --delete=$vol
         enstore volume --delete=$vol
    if [ $? != 0 ] ; then echo \'ERROR\'; fi
  fi
  IFS=$newifs
done

# Declare some new volumes
for vol in $volumes; do
  IFS=$oldifs
  vol=`echo $vol`
  if [ "${vol}x" != "x" ] ; then
    echo enstore volume --add=$vol
         enstore volume --add=$vol
    if [ $? != 0 ] ; then echo \'ERROR\'; fi
  fi
  IFS=$newifs
done

IFS="$oldifs"
