2007-07-10 19:04:15 +02:00
|
|
|
#!/bin/bash
|
2007-04-04 20:32:14 +02:00
|
|
|
#
|
|
|
|
# /sbin/iscsi-gen-initiatorname
|
|
|
|
#
|
|
|
|
# Generate a default iSCSI Initiatorname for SUSE installations.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Hannes Reinecke, SUSE Linux Products GmbH.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ "$1" ] ; then
|
|
|
|
if [ "$1" = "-f" ] ; then
|
|
|
|
FORCE=1
|
|
|
|
else
|
|
|
|
echo "Invalid option $1"
|
|
|
|
echo "Usage: $0 [-f]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/iscsi/initiatorname.iscsi -a -z "$FORCE" ] ; then
|
|
|
|
if [ -x /sbin/fwparam_ibft ] ; then
|
|
|
|
eval $(/sbin/fwparam_ibft -b 2> /dev/null | grep iSCSI_INITIATOR_NAME)
|
|
|
|
fi
|
|
|
|
if [ "$iSCSI_INITIATOR_NAME" ] ; then
|
|
|
|
eval $(cat /etc/iscsi/initiatorname.iscsi | sed -e '/^#/d')
|
|
|
|
if [ "$iSCSI_INITIATOR_NAME" != "$InitiatorName" ] ; then
|
|
|
|
echo "iSCSI Initiatorname from iBFT is different from the current setting."
|
|
|
|
echo "Please call '/sbin/iscsi-gen-initiatorname -f' to update the iSCSI Initiatorname."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x /sbin/fwparam_ibft ] ; then
|
|
|
|
eval $(/sbin/fwparam_ibft -b 2> /dev/null | sed -ne '/iSCSI_INITIATOR_NAME/p')
|
|
|
|
|
|
|
|
if [ "$iSCSI_INITIATOR_NAME" ] ; then
|
|
|
|
cat << EOF >> /etc/iscsi/initiatorname.iscsi
|
|
|
|
##
|
|
|
|
## /etc/iscsi/iscsi.initiatorname
|
|
|
|
##
|
|
|
|
## iSCSI Initiatorname taken from iBFT BIOS tables.
|
|
|
|
##
|
|
|
|
## DO NOT EDIT OR REMOVE THIS FILE!
|
|
|
|
## If you remove this file, the iSCSI daemon will not start.
|
|
|
|
## Any change here will not be reflected to the iBFT BIOS tables.
|
|
|
|
## If a different initiatorname is required please change the
|
|
|
|
## initiatorname in the BIOS setup and call
|
|
|
|
## /sbin/iscsi-gen-initiatorname -f
|
|
|
|
## to recreate an updated version of this file.
|
|
|
|
##
|
|
|
|
InitiatorName=$iSCSI_INITIATOR_NAME
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /etc/iscsi/initiatorname.iscsi ] ; then
|
|
|
|
cat << EOF >> /etc/iscsi/initiatorname.iscsi
|
|
|
|
##
|
|
|
|
## /etc/iscsi/iscsi.initiatorname
|
|
|
|
##
|
|
|
|
## Default iSCSI Initiatorname.
|
|
|
|
##
|
|
|
|
## DO NOT EDIT OR REMOVE THIS FILE!
|
|
|
|
## If you remove this file, the iSCSI daemon will not start.
|
|
|
|
## If you change the InitiatorName, existing access control lists
|
|
|
|
## may reject this initiator. The InitiatorName must be unique
|
|
|
|
## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames.
|
|
|
|
EOF
|
|
|
|
ISSUEDATE="1996-04"
|
|
|
|
INAME=$(/sbin/iscsi-iname -p iqn.$ISSUEDATE.de.suse:01)
|
|
|
|
printf "InitiatorName=$INAME\n" >>/etc/iscsi/initiatorname.iscsi
|
|
|
|
chmod 0600 /etc/iscsi/initiatorname.iscsi
|
|
|
|
fi
|
|
|
|
|