#!/bin/bash # Give an app its own RustFS bucket and a key that can use only that bucket. # ~/rustfs/new-app.sh photos # creates bucket `photos`, policy `photos-rw`, user `photos` with a random # secret, and writes the settings to ~/rustfs/photos.env (mode 600). # Needs rc's `local` alias, set up with the root keys. set -euo pipefail name=${1:?usage: new-app.sh } [[ $name =~ ^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$ ]] || { echo "not a valid bucket name: $name" >&2; exit 1; } envfile=~/rustfs/$name.env [[ -e $envfile ]] && { echo "$envfile exists; not touching $name" >&2; exit 1; } umask 077 secret=$(openssl rand -hex 24) policy=$(mktemp) trap 'rm -f "$policy"' EXIT cat > "$policy" < "$envfile" <