You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

  1. #!/bin/sh
  2. #
  3. # /sbin/iscsi-gen-initiatorname
  4. #
  5. # Generate a default iSCSI Initiatorname for SUSE installations.
  6. #
  7. # Copyright (c) 2011 Hannes Reinecke, SUSE Labs
  8. # This script is licensed under the GPL.
  9. #
  10. if [ "$1" ] ; then
  11. if [ "$1" = "-f" ] ; then
  12. FORCE=1
  13. else
  14. echo "Invalid option $1"
  15. echo "Usage: $0 [-f]"
  16. exit 1
  17. fi
  18. fi
  19. if [ -d /sys/firmware/ibft/initiator ] ; then
  20. read iSCSI_INITIATOR_NAME < /sys/firmware/ibft/initiator/initiator-name
  21. fi
  22. if [ -f /etc/iscsi/initiatorname.iscsi -a -z "$FORCE" ] ; then
  23. if [ "$iSCSI_INITIATOR_NAME" ] ; then
  24. eval $(cat /etc/iscsi/initiatorname.iscsi | sed -e '/^#/d')
  25. if [ "$iSCSI_INITIATOR_NAME" != "$InitiatorName" ] ; then
  26. echo "iSCSI Initiatorname from iBFT is different from the current setting."
  27. echo "Please call '/sbin/iscsi-gen-initiatorname -f' to update the iSCSI Initiatorname."
  28. exit 1
  29. fi
  30. fi
  31. fi
  32. if [ "$iSCSI_INITIATOR_NAME" ] ; then
  33. cat << EOF >> /etc/iscsi/initiatorname.iscsi
  34. ##
  35. ## /etc/iscsi/iscsi.initiatorname
  36. ##
  37. ## iSCSI Initiatorname taken from iBFT BIOS tables.
  38. ##
  39. ## DO NOT EDIT OR REMOVE THIS FILE!
  40. ## If you remove this file, the iSCSI daemon will not start.
  41. ## Any change here will not be reflected to the iBFT BIOS tables.
  42. ## If a different initiatorname is required please change the
  43. ## initiatorname in the BIOS setup and call
  44. ## /sbin/iscsi-gen-initiatorname -f
  45. ## to recreate an updated version of this file.
  46. ##
  47. InitiatorName=$iSCSI_INITIATOR_NAME
  48. EOF
  49. fi
  50. if [ ! -f /etc/iscsi/initiatorname.iscsi ] ; then
  51. cat << EOF >> /etc/iscsi/initiatorname.iscsi
  52. ##
  53. ## /etc/iscsi/iscsi.initiatorname
  54. ##
  55. ## Default iSCSI Initiatorname.
  56. ##
  57. ## DO NOT EDIT OR REMOVE THIS FILE!
  58. ## If you remove this file, the iSCSI daemon will not start.
  59. ## If you change the InitiatorName, existing access control lists
  60. ## may reject this initiator. The InitiatorName must be unique
  61. ## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames.
  62. EOF
  63. YEAR=$(date +"%Y")
  64. MONTH=$(date +"%m")
  65. ISSUEDATE="$YEAR$MONTH"
  66. INAME=$(iscsi-iname -p iqn.$ISSUEDATE.local.openwrt:01)
  67. printf "InitiatorName=$INAME\n" >>/etc/iscsi/initiatorname.iscsi
  68. chmod 0600 /etc/iscsi/initiatorname.iscsi
  69. fi