diff --git a/onefs/isilon_create_directories.sh b/onefs/isilon_create_directories.sh index 92ee1d0..c877f86 100644 --- a/onefs/isilon_create_directories.sh +++ b/onefs/isilon_create_directories.sh @@ -16,6 +16,7 @@ declare -a ERRORLIST=() DIST="" FIXPERM="n" ZONE="System" +CLUSTER_NAME="" #set -x @@ -26,7 +27,7 @@ function banner() { } function usage() { - echo "$0 --dist [--zone ] [--fixperm]" + echo "$0 --dist [--zone ] [--fixperm] [--append-cluster-name ]" exit 1 } @@ -53,7 +54,7 @@ function makedir() { if [ "z$1" == "z" ] ; then echo "ERROR -- function makedir needs directory as an argument" else - mkdir $1 + mkdir -p $1 fi } @@ -61,9 +62,11 @@ function fixperm() { if [ "z$1" == "z" ] ; then echo "ERROR -- function fixperm needs directory owner group perm as an argument" else - isi_run -z $ZONEID chown $2 $1 - isi_run -z $ZONEID chown :$3 $1 - isi_run -z $ZONEID chmod $4 $1 + uid=$(getUserUid $2) + gid=$(getGroupGid $3) + chown $uid $1 + chown :$gid $1 + chmod $4 $1 fi } @@ -78,12 +81,23 @@ function getHdfsRoot() { echo $hdfsroot } -function getAccessZoneId() { - local zoneid - hdfsroot=$(isi zone zones view $1 | grep "Zone ID:" | cut -f2 -d :) - echo $hdfsroot +#Params: Username +#returns: UID +function getUserUid() { + local uid + uid=$(isi auth users view --zone $ZONE $1 | grep " UID" | cut -f2 -d :) + echo $uid +} + +#Params: GroupName +#returns: GID +function getGroupGid() { + local gid + gid=$(isi auth groups view --zone $ZONE $1 | grep " GID:" | cut -f2 -d :) + echo $gid } + if [ "`uname`" != "Isilon OneFS" ]; then fatal "Script must be run on Isilon cluster as root." fi @@ -111,6 +125,11 @@ while [ "z$1" != "z" ] ; do echo "Info: will fix permissions and owners on existing directories" FIXPERM="y" ;; + "--append-cluster-name") + shift + CLUSTER_NAME="-$1" + echo "Info: will add clustername to end of usernames: $CLUSTER_NAME" + ;; *) echo "ERROR -- unknown arg $1" usage ;; @@ -279,9 +298,6 @@ case "$DIST" in ;; esac -ZONEID=$(getAccessZoneId $ZONE) -echo "Info: Access Zone ID is $ZONEID" - HDFSROOT=$(getHdfsRoot $ZONE) echo "Info: HDFS root dir is $HDFSROOT" @@ -300,6 +316,13 @@ prefix=0 for direntry in ${dirList[*]}; do read -a specs <<<"$(echo $direntry | sed 's/#/ /g')" + + if [[ ${specs[0]} == /user/* ]] ; then + specs[0]="${specs[0]}$CLUSTER_NAME" + fi + specs[2]="${specs[2]}$CLUSTER_NAME" + specs[3]="${specs[3]}$CLUSTER_NAME" + echo "DEBUG: specs dirname ${specs[0]}; perm ${specs[1]}; owner ${specs[2]}; group ${specs[3]}" ifspath=$HDFSROOT${specs[0]} # echo "DEBUG: ifspath = $ifspath" diff --git a/onefs/isilon_create_users.sh b/onefs/isilon_create_users.sh index 1b1e5b0..4f576df 100755 --- a/onefs/isilon_create_users.sh +++ b/onefs/isilon_create_users.sh @@ -17,6 +17,7 @@ DIST="" STARTUID=1000 STARTGID=1000 ZONE="System" +CLUSTER_NAME="" #set -x @@ -27,7 +28,7 @@ function banner() { } function usage() { - echo "$0 --dist [--startgid ] [--startuid ] [--zone ]" + echo "$0 --dist [--startgid ] [--startuid ] [--zone ] [--append-cluster-name ]" exit 1 } @@ -50,7 +51,7 @@ function yesno() { [ -n "$1" ] || myPrompt=">>> Please enter yes/no: " read -rp "$myPrompt" yn [ "z${yn:0:1}" = "zy" -o "z${yn:0:1}" = "zY" ] && return 0 -# exit "DEBUG: returning false from function yesno" +# exit ": returning false from function yesno" return 1 } @@ -140,6 +141,11 @@ while [ "z$1" != "z" ] ; do ZONE="$1" echo "Info: will put users in zone: $ZONE" ;; + "--append-cluster-name") + shift + CLUSTER_NAME="-$1" + echo "Info: will add clustername to end of usernames: $CLUSTER_NAME" + ;; *) echo "ERROR -- unknown arg $1" usage @@ -193,6 +199,7 @@ echo "Info: HDFS root: $HDFSROOT" gid=$STARTGID for group in $REQUIRED_GROUPS; do # echo "DEBUG: GID=$gid" + group="$group$CLUSTER_NAME" if groupExists $group $ZONE ; then gid=$(getGidFromGroup $group $ZONE) addError "Group $group already exists at gid $gid in zone $ZONE" @@ -210,6 +217,7 @@ done uid=$STARTUID for user in $REQUIRED_USERS; do # echo "DEBUG: UID=$uid" + user="$user$CLUSTER_NAME" if userExists $user $ZONE ; then uid=$(getUidFromUser $user $ZONE) addError "User $user already exists at uid $uid in zone $ZONE" @@ -224,7 +232,9 @@ for user in $REQUIRED_USERS; do done for user in $SUPER_USERS; do + user="$user$CLUSTER_NAME" for group in $SUPER_GROUPS; do + group="$group$CLUSTER_NAME" isi auth groups modify $group --add-user $user --zone $ZONE [ $? -ne 0 ] && addError "Could not add user $user to $group group in zone $ZONE" done @@ -233,15 +243,15 @@ done # Special cases case "$DIST" in "cdh") - isi auth groups modify sqoop --add-user sqoop2 --zone $ZONE + isi auth groups modify sqoop$CLUSTER_NAME --add-user sqoop2$CLUSTER_NAME --zone $ZONE [ $? -ne 0 ] && addError "Could not add user sqoop2 to sqoop group in zone $ZONE" ;; "bi") - isi auth groups modify users --add-user hive --zone $ZONE + isi auth groups modify users$CLUSTER_NAME --add-user hive$CLUSTER_NAME --zone $ZONE [ $? -ne 0 ] && addError "Could not add user hive to users group in zone $ZONE" - isi auth groups modify hcat --add-user hive --zone $ZONE + isi auth groups modify hcat$CLUSTER_NAME --add-user hive$CLUSTER_NAME --zone $ZONE [ $? -ne 0 ] && addError "Could not add user hive to hcat group in zone $ZONE" - isi auth groups modify knox --add-user kafka --zone $ZONE + isi auth groups modify knox$CLUSTER_NAME --add-user kafka$CLUSTER_NAME --zone $ZONE [ $? -ne 0 ] && addError "Could not add user kafka to knox group in zone $ZONE" ;; esac