diff --git a/shell/archive_index_template b/shell/archive_index_template new file mode 100755 index 0000000..812a383 --- /dev/null +++ b/shell/archive_index_template @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# If the number of arguments is not equal to 1, exit and display usage info. +if [ "$#" -ne 1 ]; then + echo "Usage: archive_index_template 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/$1/g" "${TMP_DIR}/index.html" + +# Put the new index.html into the root of the given bucket. +mcli put "${TMP_DIR}/index.html" "minio/${1}/"