admin-scripts/shell/archive_index_template

39 lines
1016 B
Plaintext
Raw Permalink Normal View History

2024-11-27 07:50:56 +01:00
#!/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"
2024-11-27 07:50:56 +01:00
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.
2024-12-02 05:34:35 +01:00
sed -i "s/CHANGEME/$2/g" "${TMP_DIR}/index.html"
2024-11-27 07:50:56 +01:00
# Put the new index.html into the root of the given bucket.
mc put "${TMP_DIR}/index.html" "${1}/${2}/"