diff options
author | Lee Duncan <lduncan@suse.com> | 2022-04-08 08:25:18 -0700 |
---|---|---|
committer | Lee Duncan <lduncan@suse.com> | 2022-04-08 08:25:18 -0700 |
commit | e1c491d59ffaeac367966b703f91eab4972a54f6 (patch) | |
tree | efa94d391675800887c85247e9f66908b2dae382 /utils | |
parent | 92c2677008610d282d3f6240eab740f79a41a3dc (diff) | |
download | open-iscsi-e1c491d59ffaeac367966b703f91eab4972a54f6.tar.gz |
Check for root in iscsi-gen-initiatorname
The man page is also updated
Diffstat (limited to 'utils')
-rw-r--r-- | utils/iscsi-gen-initiatorname.sh.template | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/utils/iscsi-gen-initiatorname.sh.template b/utils/iscsi-gen-initiatorname.sh.template index a06d6d0..5c2bfdf 100644 --- a/utils/iscsi-gen-initiatorname.sh.template +++ b/utils/iscsi-gen-initiatorname.sh.template @@ -77,7 +77,7 @@ usage_and_exit() echo "Where OPTIONS are from:" echo " -h print usage and exit" echo " -f overwrite existing InitiatorName, if any" - echo " -p IQN-PRE set the prefix for the IQN generated (default ${DEFAULT_IQN_PREFIX})" + echo " -p IQN-PRE set prefix for generated IQN (default ${DEFAULT_IQN_PREFIX})" exit $xit_val } @@ -112,7 +112,12 @@ done shift $(($OPTIND-1)) if [ "$#" -gt 0 ] ; then - echo "Invalid argument(s): $*" + echo "Error: Invalid argument(s): $*" 1>&2 + usage_and_exit 1 +fi + +if [ "$EUID" -ne 0 ] ; then + echo "Error: You must be root to run this command" 1>&2 usage_and_exit 1 fi @@ -131,21 +136,20 @@ KERNEL_INAME="$(kernel_supplied_initiatorname)" # if we have a local initiator name and "force" is not set end it now if [ "$InitiatorName" -a -z "$FORCE" ] ; then echo "Error: you cannot overwrite the current InitiatorName unless 'force' is set." 1>&2 - echo "Please call '$NAME -f' to update iSCSI InitiatorName, if needed." 1>&2 - exit 1 + usage_and_exit 1 fi # ensure we can write the initiator name file if [ -r "$INAME_FILE" ] ; then if [ ! -w "$INAME_FILE" ] ; then echo "Error: cannot update InitiatorName, write protected: $INAME_FILE" 1>&1 - echo "Please ensure you are root and filesystem is read/write." 1>&2 + echo "Please ensure the filesystem is read/write." 1>&2 exit 1 fi # the file exists but we can write over it elif [ ! -w "$INAME_DIR" ] ; then echo "Error: no write permission in directory: $INAME_DIR" 1>&2 - echo "Please ensure you are root and filesystem is read/write." 1>&2 + echo "Please ensure the filesystem is read/write." 1>&2 exit 1 fi |