From bac25d27c8b389c4e3a81f0930cacc8b5741f0ed Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Wed, 26 Jun 2024 09:58:18 +0200 Subject: [PATCH] Fix bug in script --- manifests/script.pp | 2 +- .../create_folders_in_fullnode_buckets.erb.sh | 46 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/manifests/script.pp b/manifests/script.pp index f4a9e84..b70c78d 100644 --- a/manifests/script.pp +++ b/manifests/script.pp @@ -250,7 +250,7 @@ class sunetdrive::script ( if $customer in ['extern', 'gih', 'hkr', 'suni', 'common', 'su', 'lnu'] { sunet::scriptherder::cronjob { 'makebuckets': ensure => absent, - cmd => 'bin/true', + cmd => 'bin/true', } } else { sunet::scriptherder::cronjob { 'makebuckets': diff --git a/templates/script/create_folders_in_fullnode_buckets.erb.sh b/templates/script/create_folders_in_fullnode_buckets.erb.sh index 8cfe792..526ce58 100644 --- a/templates/script/create_folders_in_fullnode_buckets.erb.sh +++ b/templates/script/create_folders_in_fullnode_buckets.erb.sh @@ -7,16 +7,16 @@ include_userbuckets="<%= @include_userbuckets %>" container="nextcloud_app_1" yq="/usr/local/bin/yq" if ! [[ -x ${yq} ]]; then - pip install yq + pip install yq fi declare -a directories if [[ -n ${1} ]]; then - directories=("${@}") + directories=("${@}") else - directories+=("Arbetsmaterial") - directories+=("Bevarande") - directories+=("Gallringsbart") + directories+=("Arbetsmaterial") + directories+=("Bevarande") + directories+=("Gallringsbart") fi olddir="${PWD}" @@ -25,31 +25,31 @@ dirty=0 primary='' declare -a users=( 'admin' ) cd "${tempdir}" || echo "Could not cd to tempdir" -declare -a projects=( "${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml ) +declare -a projects=( $("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml) ) if [[ "${include_userbuckets}" == "true" ]]; then - primary=$("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.primary_project' /etc/hiera/data/common.yaml) - projects+=( "${primary}" ) + primary=$("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.primary_project' /etc/hiera/data/common.yaml) + projects+=( "${primary}" ) fi for project in "${projects[@]}"; do - for bucket in $(rclone lsd "${project}:" | awk '{print $NF}' | grep -E -v '^primary'); do - count=$(rclone size --json "${project}:${bucket}" | jq -r .count) - if [[ ${count} -gt 0 ]]; then - echo "Skipping ${project}:${bucket} because it has stuff in it already" - continue - fi - for directory in "${directories[@]}"; do - dirty=1 + for bucket in $(rclone lsd "${project}:" | awk '{print $NF}' | grep -E -v '^primary'); do + count=$(rclone size --json "${project}:${bucket}" | jq -r .count) + if [[ ${count} -gt 0 ]]; then + echo "Skipping ${project}:${bucket} because it has stuff in it already" + continue + fi + for directory in "${directories[@]}"; do + dirty=1 if [[ -n ${primary} ]] && [[ ${project} == "${primary}" ]] ; then user=$(echo "${bucket}" | awk -F '-' '{print $1}') users+=( "${user}@${eppn_suffix}" ) fi - echo "Creating ${project}:${bucket}/${directory} because it looks nice and empty" - temp="README.md" - echo "**${directory}**" >"${temp}" - echo "Var god lämna kvar denna fil/Please leave this file" >>"${temp}" - rclone --no-traverse move "${temp}" "${project}:${bucket}/${directory}" - done - done + echo "Creating ${project}:${bucket}/${directory} because it looks nice and empty" + temp="README.md" + echo "**${directory}**" >"${temp}" + echo "Var god lämna kvar denna fil/Please leave this file" >>"${temp}" + rclone --no-traverse move "${temp}" "${project}:${bucket}/${directory}" + done + done done cd "${olddir}" || echo "could not cd to home dir" rmdir "${tempdir}"