#!/usr/bin/env bash set -euo pipefail # If the number of arguments is not equal to 1, exit and display usage info. if [ "$#" -ne 2 ]; then echo "Usage: archive_index_template MINIO_INSTANCE BUCKET_NAME" exit 1 fi # Create temporary directory. TMP_DIR=$(mktemp -d) # Check if temporary directory was created. if ! test -d "$TMP_DIR"; then echo "Failed to create temp dir" exit 1 fi # Cleanup temporary directory. function cleanup() { rm -rf "$TMP_DIR" echo "Cleaned up temp dir at $TMP_DIR" } # Trigger cleanup trap on EXIT and SIGINT signals trap cleanup EXIT SIGINT # Download archive-index-template.html and save to temporary directory as # index.html. wget --quiet https://files.hyperreal.coffee/archive-index-template.html \ -O "${TMP_DIR}/index.html" # Replace "CHANGEME" with the the BUCKET_NAME argument in index.html. sed -i "s/CHANGEME/$2/g" "${TMP_DIR}/index.html" # Put the new index.html into the root of the given bucket. mc put "${TMP_DIR}/index.html" "${1}/${2}/"