#!/bin/sh set -eu . /run/local-config/env export SSL_CERT_FILE=/run/local-config/ca.crt rc alias set local https://rustfs:9000 "$RUSTFS_ACCESS_KEY" "$RUSTFS_SECRET_KEY" >/dev/null attempt=0 until rc ls local/ >/dev/null 2>&1; do attempt=$((attempt + 1)) if [ "$attempt" -ge 20 ]; then echo 'S3 TLS endpoint did not become ready' >&2; exit 1; fi sleep 2 done if [ "$#" -gt 0 ]; then case "$1" in add) read -r user read -r password rc admin user add local/ "$user" "$password" >/dev/null rc admin policy attach local/ messenger-worker --user "$user" >/dev/null ;; remove) read -r user rc admin user remove local/ "$user" >/dev/null ;; *) exit 2 ;; esac exit fi rc bucket create --ignore-existing local/messenger-attachments >/dev/null for role in api worker; do case "$role" in api) user="$API_S3_USER"; password="$API_S3_PASSWORD";; worker) user="$WORKER_S3_USER"; password="$WORKER_S3_PASSWORD";; esac rc admin policy create local/ "messenger-$role" "/bootstrap/$role.json" >/dev/null if ! rc admin user list local/ | awk '{print $1}' | grep -Fxq "$user"; then rc admin user add local/ "$user" "$password" >/dev/null fi rc admin policy attach local/ "messenger-$role" --user "$user" >/dev/null done printf '%s\n' 'Private bucket and both scoped S3 users are ready.'