Add archive_index_template

This commit is contained in:
Jeffrey Serio 2024-11-27 00:50:56 -06:00
parent 018945d4a7
commit 1cece9db2e

38
shell/archive_index_template Executable file
View File

@ -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}/"