#!/bin/sh set -eu cd /run/tls export MC_CONFIG_DIR=/tmp/mc mkdir -p "$MC_CONFIG_DIR/certs/CAs" cp ca.crt "$MC_CONFIG_DIR/certs/CAs/lab7.crt" export MC_HOST_root="https://$(cat root_user):$(cat root_password)@s3:9000" mc mb --ignore-existing "root/$S3_BUCKET" mc anonymous set none "root/$S3_BUCKET" >/dev/null policy() { role="$1" staging="$2" final="$3" cat > /tmp/policy.json </dev/null mc admin user add root "messenger-$role" "$(cat "$role"_password)" >/dev/null mc admin policy attach root "messenger-$role" --user "messenger-$role" >/dev/null } policy api '"s3:PutObject","s3:DeleteObject"' '"s3:GetObject"' policy worker '"s3:GetObject","s3:DeleteObject"' '"s3:GetObject","s3:PutObject"' policy reconciler '"s3:DeleteObject"' '"s3:DeleteObject"' echo "Private bucket and role policies ready"