diff --git a/scripts/set-bucket-acls.sh b/scripts/set-bucket-acls.sh index 9da2cf9..242e3ff 100755 --- a/scripts/set-bucket-acls.sh +++ b/scripts/set-bucket-acls.sh @@ -5,37 +5,32 @@ DRY_RUN=${DRY_RUN:-0} -BASEDIR=$(dirname "${0}") +BASEDIR=$(dirname "$0") NOT_PROCESSED_BUCKETS_FILE="${BASEDIR}/not-processed-buckets.txt" -BUCKETS="put-here-the-first-bucket \ -put-here-the-second-bucket" +BUCKETS="put-here-the-first-bucket put-here-the-second-bucket" -echo -n "" >"${NOT_PROCESSED_BUCKETS_FILE}" -for BUCKET in ${BUCKETS}; do +: >"$NOT_PROCESSED_BUCKETS_FILE" + +for BUCKET in $BUCKETS; do echo "Check for bucket '${BUCKET}'" - if ! gsutil ls -d "gs://${BUCKET}/public" >/dev/null 2>&1 || ! gsutil ls -d "gs://${BUCKET}/private" >/dev/null 2>&1; then + if ! gcloud storage ls "gs://${BUCKET}/public/" >/dev/null 2>&1 || + ! gcloud storage ls "gs://${BUCKET}/private/" >/dev/null 2>&1; then echo "Bucket '${BUCKET}' not processed" - echo "${BUCKET}" >>"${NOT_PROCESSED_BUCKETS_FILE}" + echo "${BUCKET}" >>"$NOT_PROCESSED_BUCKETS_FILE" continue fi echo "Bucket '${BUCKET}' has public and private folders. Setting ACLs..." - if [ "${DRY_RUN}" -ne "0" ]; then - echo "Exec the dry run commands..." - echo "DRY RUN: gsutil -m acl set private gs://${BUCKET}/*" - echo "DRY RUN: gsutil -m acl set -r public-read gs://${BUCKET}/public/**" - echo "DRY RUN: gsutil -m acl set -r private gs://${BUCKET}/private/**" - echo "End of dry run commands." + if [[ "$DRY_RUN" -ne 0 ]]; then + echo "DRY RUN: gcloud storage objects update --recursive --predefined-acl=private gs://${BUCKET}/*" + echo "DRY RUN: gcloud storage objects update --recursive --predefined-acl=publicRead gs://${BUCKET}/public/**" + echo "DRY RUN: gcloud storage objects update --recursive --predefined-acl=private gs://${BUCKET}/private/**" continue fi - echo "Exec the real commands..." - # This gsutil command is useful to set the private ACL to the root level objects. - gsutil -m acl set private "gs://${BUCKET}/*" - # Set public-read ACL to all objects inside the public folder. - gsutil -m acl set -r public-read "gs://${BUCKET}/public/**" - # Set private ACL to all objects inside the private folder. - gsutil -m acl set -r private "gs://${BUCKET}/private/**" + gcloud storage objects update --recursive --predefined-acl=private "gs://${BUCKET}/*" + gcloud storage objects update --recursive --predefined-acl=publicRead "gs://${BUCKET}/public/**" + gcloud storage objects update --recursive --predefined-acl=private "gs://${BUCKET}/private/**" echo "Bucket '${BUCKET}' processed." done