Assorted shell and Python scripts
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5# If the number of arguments is not equal to 1, exit and display usage info.
6if [ "$#" -ne 2 ]; then
7 echo "Usage: archive_index_template MINIO_INSTANCE BUCKET_NAME"
8 exit 1
9fi
10
11# Create temporary directory.
12TMP_DIR=$(mktemp -d)
13
14# Check if temporary directory was created.
15if ! test -d "$TMP_DIR"; then
16 echo "Failed to create temp dir"
17 exit 1
18fi
19
20# Cleanup temporary directory.
21function cleanup() {
22 rm -rf "$TMP_DIR"
23 echo "Cleaned up temp dir at $TMP_DIR"
24}
25
26# Trigger cleanup trap on EXIT and SIGINT signals
27trap cleanup EXIT SIGINT
28
29# Download archive-index-template.html and save to temporary directory as
30# index.html.
31wget --quiet https://files.hyperreal.coffee/archive-index-template.html \
32 -O "${TMP_DIR}/index.html"
33
34# Replace "CHANGEME" with the the BUCKET_NAME argument in index.html.
35sed -i "s/CHANGEME/$2/g" "${TMP_DIR}/index.html"
36
37# Put the new index.html into the root of the given bucket.
38mc put "${TMP_DIR}/index.html" "${1}/${2}/"