From 7c6344aca96e870cdbc768e35e3d14f580b7d81e Mon Sep 17 00:00:00 2001 From: Pieter Neerincx Date: Fri, 24 Feb 2023 11:33:55 +0100 Subject: [PATCH 1/3] Improved hpc-environment-permissions.bash to make it also work with newer Bash version on new chaperone machines. --- .../hpc-environment-permissions.bash | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/roles/envsync/templates/hpc-environment-permissions.bash b/roles/envsync/templates/hpc-environment-permissions.bash index f2b798c0f..fc264da3d 100644 --- a/roles/envsync/templates/hpc-environment-permissions.bash +++ b/roles/envsync/templates/hpc-environment-permissions.bash @@ -42,18 +42,18 @@ REAL_USER="$(logname 2>/dev/null || echo 'no login name')" # Retain ownership and change group + perms if necessary on the originals. # function verifyAndFixOriginals() { - local _ROOT_OF_HPC_ENV_ORIGINAL="$1" - - declare -a local _HPC_ENV_FOLDERS=("${_ROOT_OF_HPC_ENV_ORIGINAL}/modules/" + local _ROOT_OF_HPC_ENV_ORIGINAL="${1}" + declare -a _HPC_ENV_FOLDERS=("${_ROOT_OF_HPC_ENV_ORIGINAL}/modules/" "${_ROOT_OF_HPC_ENV_ORIGINAL}/software/" "${_ROOT_OF_HPC_ENV_ORIGINAL}/data/" "${_ROOT_OF_HPC_ENV_ORIGINAL}/sources/" "${_ROOT_OF_HPC_ENV_ORIGINAL}/.tmp/") - - for (( i = 0 ; i < ${#_HPC_ENV_FOLDERS[@]:-0} ; i++ )) + for (( i = 0 ; i < ${#_HPC_ENV_FOLDERS[@]} ; i++ )) do - find "${_HPC_ENV_FOLDERS[${i}]}" \! -group "${SYS_GROUP}" -exec chgrp "${SYS_GROUP}" '{}' \; - verifyPermissions "${_HPC_ENV_FOLDERS[${i}]}" '0775' '0664' 'ug+rwX,o+rX,o-w' '2775' + if [[ -e "${_HPC_ENV_FOLDERS[${i}]}" ]]; then + find "${_HPC_ENV_FOLDERS[${i}]}" \! -group "${SYS_GROUP}" -a \! -type l -exec chgrp "${SYS_GROUP}" '{}' \; + verifyPermissions "${_HPC_ENV_FOLDERS[${i}]}" '0775' '0664' 'ug+rwX,o+rX,o-w' '2775' + fi done } @@ -61,17 +61,17 @@ function verifyAndFixOriginals() { # Change ownership, group and perms if necessary on the copies. # function verifyAndFixCopies() { - local _ROOT_OF_HPC_ENV_COPY="$1" - - declare -a local _HPC_ENV_FOLDERS=("${_ROOT_OF_HPC_ENV_COPY}/modules/" - "${_ROOT_OF_HPC_ENV_COPY}/software/" - "${_ROOT_OF_HPC_ENV_COPY}/data/") - - for (( i = 0 ; i < ${#_HPC_ENV_FOLDERS[@]:-0} ; i++ )) + local _ROOT_OF_HPC_ENV_COPY="${1}" + declare -a _HPC_ENV_FOLDERS=("${_ROOT_OF_HPC_ENV_COPY}/modules/" + "${_ROOT_OF_HPC_ENV_COPY}/software/" + "${_ROOT_OF_HPC_ENV_COPY}/data/") + for (( i = 0 ; i < ${#_HPC_ENV_FOLDERS[@]} ; i++ )) do - find "${_HPC_ENV_FOLDERS[${i}]}" \! -user "${SYS_USER}" -exec chown "${SYS_USER}" '{}' \; - find "${_HPC_ENV_FOLDERS[${i}]}" \! -group "${SYS_GROUP}" -exec chgrp "${SYS_GROUP}" '{}' \; - verifyPermissions "${_HPC_ENV_FOLDERS[${i}]}" '0755' '0644' 'u+rwX,go+rX,go-w' '2755' + if [[ -e "${_HPC_ENV_FOLDERS[${i}]}" ]]; then + find "${_HPC_ENV_FOLDERS[${i}]}" \! -user "${SYS_USER}" -a \! -type l -exec chown "${SYS_USER}" '{}' \; + find "${_HPC_ENV_FOLDERS[${i}]}" \! -group "${SYS_GROUP}" -a \! -type l -exec chgrp "${SYS_GROUP}" '{}' \; + verifyPermissions "${_HPC_ENV_FOLDERS[${i}]}" '0755' '0644' 'u+rwX,go+rX,go-w' '2755' + fi done } @@ -81,14 +81,14 @@ function verifyAndFixCopies() { # unless there really was something to change. Mostly used for "group" folders. # function verifyPermissions() { - local _FOLDER="$1" - local _FIND_FILE_PERMS_EXECUTABLE="$2" - local _FIND_FILE_PERMS_REGULAR="$3" - local _CHMOD_FILE_PERMS="$4" - local _FOLDER_PERMS="$5" + local _FOLDER="${1}" + local _FIND_FILE_PERMS_EXECUTABLE="${2}" + local _FIND_FILE_PERMS_REGULAR="${3}" + local _CHMOD_FILE_PERMS="${4}" + local _FOLDER_PERMS="${5}" echo "INFO: Verify and fix permissions with file perms ${_CHMOD_FILE_PERMS} and folder perms ${_FOLDER_PERMS} for for folder ${_FOLDER}... " - find "${_FOLDER}" -type f -a \! \( -perm ${_FIND_FILE_PERMS_EXECUTABLE} -o -perm ${_FIND_FILE_PERMS_REGULAR} \) -exec chmod "${_CHMOD_FILE_PERMS}" '{}' \; - find "${_FOLDER}" -type d -a \! -perm ${_FOLDER_PERMS} -exec chmod "${_FOLDER_PERMS}" '{}' \; + find "${_FOLDER}" -type f -a \! \( -perm "${_FIND_FILE_PERMS_EXECUTABLE}" -o -perm "${_FIND_FILE_PERMS_REGULAR}" \) -exec chmod "${_CHMOD_FILE_PERMS}" '{}' \; + find "${_FOLDER}" -type d -a \! -perm "${_FOLDER_PERMS}" -exec chmod "${_FOLDER_PERMS}" '{}' \; } # @@ -104,7 +104,7 @@ fi # # Check (and fix if necessary) our original shared HPC environment. # -if [ -e ${ORIGINAL_HPC_ENV_PREFIX} ] && [ -d ${ORIGINAL_HPC_ENV_PREFIX} ]; then +if [[ -e "${ORIGINAL_HPC_ENV_PREFIX}" ]] && [[ -d "${ORIGINAL_HPC_ENV_PREFIX}" ]]; then echo "INFO: Found original environment @ ${ORIGINAL_HPC_ENV_PREFIX}: will verify and fix permissions... " verifyAndFixOriginals "${ORIGINAL_HPC_ENV_PREFIX}" echo 'INFO: Done!' @@ -116,22 +116,23 @@ fi # Find all rsynced copies of our shared HPC environment. # declare -a COPIED_HPC_ENV_PREFIXES -for (( i = 0 ; i < ${#COPIED_HPC_ENV_MOUNT_POINT_PARENTS[@]:-0} ; i++ )) +for (( i = 0 ; i < ${#COPIED_HPC_ENV_MOUNT_POINT_PARENTS[@]} ; i++ )) do # # Check for presence of folders for logical file system (LFS) names # and if present whether they contain a copy of ${ORIGINAL_HPC_ENV_PREFIX}. # - declare -a LFS_MOUNT_POINTS="$(find ${COPIED_HPC_ENV_MOUNT_POINT_PARENTS[${i}]} -mindepth 1 -maxdepth 1 -type d)" - for (( j = 0 ; j < ${#LFS_MOUNT_POINTS[@]:-0} ; j++ )) + declare -a LFS_MOUNT_POINTS + readarray -t LFS_MOUNT_POINTS< <(find "${COPIED_HPC_ENV_MOUNT_POINT_PARENTS[${i}]}" -mindepth 1 -maxdepth 1 -type d) + for (( j = 0 ; j < ${#LFS_MOUNT_POINTS[@]} ; j++ )) do - [ -z ${LFS_MOUNT_POINTS[${j}]} ] && continue + [[ -z "${LFS_MOUNT_POINTS[${j}]}" ]] && continue COPIED_HPC_ENV_PREFIX="${LFS_MOUNT_POINTS[${j}]}${ORIGINAL_HPC_ENV_PREFIX}" - if [ -e "${COPIED_HPC_ENV_PREFIX}" ] && \ - [ -r "${COPIED_HPC_ENV_PREFIX}" ] && \ - [ -w "${COPIED_HPC_ENV_PREFIX}" ] && \ - [ -d "${COPIED_HPC_ENV_PREFIX}" ]; then - if [ "${#COPIED_HPC_ENV_PREFIXES[@]:-0}" -eq 0 ]; then + if [[ -e "${COPIED_HPC_ENV_PREFIX}" ]] && \ + [[ -r "${COPIED_HPC_ENV_PREFIX}" ]] && \ + [[ -w "${COPIED_HPC_ENV_PREFIX}" ]] && \ + [[ -d "${COPIED_HPC_ENV_PREFIX}" ]]; then + if [[ "${#COPIED_HPC_ENV_PREFIXES[@]}" -eq 0 ]]; then COPIED_HPC_ENV_PREFIXES=("${COPIED_HPC_ENV_PREFIX}") else COPIED_HPC_ENV_PREFIXES=("${COPIED_HPC_ENV_PREFIXES[@]:-}" "${COPIED_HPC_ENV_PREFIX}") @@ -145,10 +146,10 @@ done # # Check (and fix if necessary) all rsynced copies of our shared HPC environment. # -if [ "${#COPIED_HPC_ENV_PREFIXES[@]:-0}" -eq 0 ]; then +if [[ "${#COPIED_HPC_ENV_PREFIXES[@]}" -eq 0 ]]; then echo "WARN: Found no environment copies and will not verify and fix permissions for environment copies." else - for THIS_HPC_ENV_PREFIX in ${COPIED_HPC_ENV_PREFIXES[@]:-}; do + for THIS_HPC_ENV_PREFIX in "${COPIED_HPC_ENV_PREFIXES[@]:-}"; do echo "INFO: Will verify and fix permissions for environment copy @ ${THIS_HPC_ENV_PREFIX} ... " verifyAndFixCopies "${THIS_HPC_ENV_PREFIX}" echo 'INFO: Done!' From b65552e81e33848c2529148278c21199754cea2a Mon Sep 17 00:00:00 2001 From: Pieter Neerincx Date: Fri, 24 Feb 2023 12:04:16 +0100 Subject: [PATCH 2/3] Improved hpc-environment-permissions.bash to make it also work with newer Bash version on new chaperone machines. --- roles/envsync/templates/hpc-environment-permissions.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/envsync/templates/hpc-environment-permissions.bash b/roles/envsync/templates/hpc-environment-permissions.bash index fc264da3d..d788db325 100644 --- a/roles/envsync/templates/hpc-environment-permissions.bash +++ b/roles/envsync/templates/hpc-environment-permissions.bash @@ -115,7 +115,7 @@ fi # # Find all rsynced copies of our shared HPC environment. # -declare -a COPIED_HPC_ENV_PREFIXES +declare -a COPIED_HPC_ENV_PREFIXES=() for (( i = 0 ; i < ${#COPIED_HPC_ENV_MOUNT_POINT_PARENTS[@]} ; i++ )) do # @@ -138,7 +138,7 @@ do COPIED_HPC_ENV_PREFIXES=("${COPIED_HPC_ENV_PREFIXES[@]:-}" "${COPIED_HPC_ENV_PREFIX}") fi else - echo "WARN: ${COPIED_HPC_ENV_PREFIX} not available (symlink dead or mount missing)." + echo "INFO: no ${ORIGINAL_HPC_ENV_PREFIX} copy found on ${LFS_MOUNT_POINTS[${j}]}." fi done done From be97f48d790e61234a332ebd0a4f8c4fee1c03ee Mon Sep 17 00:00:00 2001 From: Pieter Neerincx Date: Fri, 24 Feb 2023 12:06:04 +0100 Subject: [PATCH 3/3] Improved hpc-environment-permissions.bash to make it also work with newer Bash version on new chaperone machines. --- roles/envsync/templates/hpc-environment-permissions.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/envsync/templates/hpc-environment-permissions.bash b/roles/envsync/templates/hpc-environment-permissions.bash index d788db325..9b7e45a74 100644 --- a/roles/envsync/templates/hpc-environment-permissions.bash +++ b/roles/envsync/templates/hpc-environment-permissions.bash @@ -138,7 +138,7 @@ do COPIED_HPC_ENV_PREFIXES=("${COPIED_HPC_ENV_PREFIXES[@]:-}" "${COPIED_HPC_ENV_PREFIX}") fi else - echo "INFO: no ${ORIGINAL_HPC_ENV_PREFIX} copy found on ${LFS_MOUNT_POINTS[${j}]}." + echo "INFO: No ${ORIGINAL_HPC_ENV_PREFIX} copy found on ${LFS_MOUNT_POINTS[${j}]}." fi done done