reductionist 0.12.0

S3 Active Storage server
Documentation
#!/usr/bin/env bash

set -e

origin=$(dirname "$0")
origin=$(cd "$origin"; pwd)
me=$(basename "$0")

volume="$1"
if [ -z "$volume" ]; then
    cat <<EOF

usage: $me <path to share>

EOF
    exit 1
fi
volume=$(cd "$volume"; pwd)

# This could do with better configuration,
# but to work around permission issues these certificates will be copied
# to a path that can be made accessible within the nginx container.
server_crt="/etc/ssl/default/chain.crt"
server_key="/etc/ssl/default/server.key"

cp "$server_crt" "$origin/server.crt"
cp "$server_key" "$origin/server.key"

# Setup htpasswd for basic authentication.
# NOTE: Do NOT commit generated htpasswd contents to version control,
#       it will be ignored using the following default location.
# To change the credentials used:
# - replace: admin admin
# - with   : <your desired username> <your desired password>
htpasswd -bc "$origin/htpasswd" admin admin

# Start our local nginx
# https://hub.docker.com/_/nginx
echo "Starting nginx serving on '$volume'"
docker run \
    --name nginx-user-share \
    --rm \
    -d \
    -p 8000:443 \
    -v "$origin/nginx-ssl.conf:/etc/nginx/conf.d/default.conf" \
    -v "$origin/htpasswd:/etc/nginx/htpasswd" \
    -v "$volume:/usr/share/nginx/html" \
    -v "$origin/server.crt:/etc/ssl/certs/server.crt" \
    -v "$origin/server.key:/etc/ssl/certs/server.key" \
    docker.io/nginx