Files
mtusi2026lab7/scripts/bootstrap_s3.sh
T
2026-11-11 13:53:51 +03:00

26 lines
881 B
Bash

#!/bin/sh
set -eu
export MC_CONFIG_DIR=/tmp/mc
mkdir -p "$MC_CONFIG_DIR/certs/CAs"
cp /pki/ca.crt "$MC_CONFIG_DIR/certs/CAs/ca.crt"
for attempt in $(seq 1 45); do
if mc alias set local https://s3:9000 operator "$(cat /credentials/root)" >/dev/null 2>&1; then
break
fi
test "$attempt" -lt 45
sleep 1
done
mc mb --ignore-existing local/messenger-attachments >/dev/null
mc anonymous set none local/messenger-attachments >/dev/null
case "${S3_ROLE:-all}" in
all) roles="api worker reconciler" ;;
api) roles=api ;;
*) exit 2 ;;
esac
for role in $roles; do
mc admin policy create local "messenger-$role" "/policies/$role.json" >/dev/null
mc admin user add local "lab-$role" "$(cat "/credentials/$role")" >/dev/null
mc admin policy attach local "messenger-$role" --user "lab-$role" >/dev/null
done
echo 'Private bucket and scoped accounts ready'