#!/bin/sh # # Program: SD.CONF Creation Tool # # Author: Matty < matty91 at gmail dot com > # # Current Version: 1.0 # # Revision History: # # Version 1.0 # Initial Release # # Last Updated: 01-25-2005 # # Purpose: # sd-create.sh builds the sd.conf entries for a variable number of targets and LUNs. # # License: # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any # later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Installation: # Copy the shell script to a suitable location # # Usage (script should be run as a non-privileged user): # Usage: ./sd-create.sh -c COUNT -n NAME -p PARENT target1 target2 ... # -c COUNT : Number of LUNs to print per target # -n NAME : Name to put in the device driver place # -p PARENT : Parent of the device # # Examples: # Create 2 LUNS for targets 10 and 15: # $ sd-create.sh -c 2 -n sd -p lpfc 10 15 # # # Date: 01-26-2005 Added 2 LUNs to target 10 # name="sd" parent="lpfc" target=10 lun=0 # name="sd" parent="lpfc" target=10 lun=1 # # # Date: 01-26-2005 Added 2 LUNs to target 15 # name="sd" parent="lpfc" target=15 lun=0 # name="sd" parent="lpfc" target=15 lun=1 DATE=`/bin/date "+%m-%d-%Y"` usage() { echo "Usage: $0 -c COUNT -n NAME -p PARENT target1 target2 ..." echo " -c COUNT : Number of LUNs to print per target" echo " -n NAME : Name to put in the device driver place" echo " -p PARENT : Parent of the device" } ### Process the command line arguments while getopts c:n:p: option do case "${option}" in c) LUNS=${OPTARG};; n) NAME=${OPTARG};; p) PARENT=${OPTARG};; \?) usage exit 1;; esac done ### Make sure the variables contain valid values if [ "${LUNS}" = "" ] || [ "${NAME}" = "" ] || [ "${PARENT}" = "" ] then usage exit 1 else ### Get rid of all of the "-" options shift ` expr $OPTIND - 1` fi ### Make sure one or more targets were passed to the program if [ "${1}" = "" ] then usage exit 1 fi ### Cycle through the targets and generate sd.conf entries while [ "$1" != "" ] do echo "#" echo "# Date: ${DATE} Added ${LUNS} LUNs to target ${1}" echo "#" INDICE=0 while [ ${INDICE} -lt ${LUNS} ] do printf "name=\"${NAME}\" parent=\"${PARENT}\" target=${1} lun=${INDICE};\n" INDICE=`expr ${INDICE} + 1` done shift done