From 1cece9db2e58fd206f4d6f7a6574aaa7745ee0ff Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Wed, 27 Nov 2024 00:50:56 -0600 Subject: [PATCH] Add archive_index_template --- shell/archive_index_template | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 shell/archive_index_template 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}/"