szabodanika / microbin

A secure, configurable file-sharing and URL shortening web app written in Rust.
https://microbin.eu
BSD 3-Clause "New" or "Revised" License
2.65k stars 163 forks source link

Docker environment variables #65

Closed modem7 closed 1 year ago

modem7 commented 1 year ago

Heya,

Great project you have!

I understand that you're not so hot on Docker stuff currently, and there's quite a few variables that aren't available.

Would something like this be suitable for starters (I'm sure others could improve on it)?

#!/bin/bash

set -e

# Website
# https://github.com/szabodanika/microbin

# Version variables
MICROBINVER=$(microbin --version)

# Software versions
echo $MICROBINVER

# Declare Variables
PORT="${PORT:-"8080"}"
THREADS="${THREADS:-"1"}"

# Declare the string array
arrVar=()

# Add to string array if variable is true
if [ "$EDITABLE" == "true" ]
  then
    arrVar+=("--editable")
fi

if [ "$HIDE_FOOTER" == "true" ]
  then
    arrVar+=("--hide-footer")
fi

if [ "$HIGHLIGHTSYNTAX" == "true" ]
  then
    arrVar+=("--highlightsyntax")
fi

if [ "$PRIVATE" == "true" ]
  then
    arrVar+=("--private")
fi

if [ "$HIDE_FOOTER" == "true" ]
  then
    arrVar+=("--hide-footer")
fi

if [ "$HIDE_HEADER" == "true" ]
  then
    arrVar+=("--hide-header")
fi

if [ "$HIDE_LOGO" == "true" ]
  then
    arrVar+=("--hide-logo")
fi

if [ "$NO_LISTING" == "true" ]
  then
    arrVar+=("--no-listing")
fi

if [ "$PURE_HTML" == "true" ]
  then
    arrVar+=("--pure-html")
fi

if [ "$READ_ONLY" == "true" ]
  then
    arrVar+=("--readonly")
fi

if [ "$WIDE" == "true" ]
  then
    arrVar+=("--wide")
fi

#########################
#User Editable Variables#
#########################

if [ -v AUTH_USERNAME ]
  then
    arrVar+=("--auth-username $AUTH_USERNAME")
fi

if [ -v AUTH_PASSWORD ]
  then
    arrVar+=("--auth-password $AUTH_PASSWORD")
fi

if [ -v FOOTER_TEXT ]
  then
    arrVar+=("--footer_text $FOOTER_TEXT")
fi

if [ -v BIND_ADDR ]
  then
    arrVar+=("--bind $BIND_ADDR")
fi

# Save and define variables
printf -v str ' %s' "${arrVar[@]}"  # save to variable str without printing
MICROBIN_VARS="${str:1}"  # to remove the leading space 

# Show defined variables
echo "Microbin starting with following variables: microbin --port $PORT --threads $THREADS $MICROBIN_VARS"

# Start Microbin
microbin --port $PORT --threads $THREADS $MICROBIN_VARS
This would give you the following variables: Variable Value
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false
EDITABLE true false

EDITABLE="${EDITABLE:-}"

HIDE_FOOTER="${HIDE_FOOTER:-}"

HIGHLIGHTSYNTAX="${HIGHLIGHTSYNTAX:-}"

PRIVATE="${PRIVATE:-}"

HIDE_FOOTER="${HIDE_FOOTER:-}"

HIDE_HEADER="${HIDE_HEADER:-}"

HIDE_LOGO="${HIDE_LOGO:-}"

NO_LISTING="${NO_LISTING:-}"

PURE_HTML="${PURE_HTML:-}"

READ_ONLY="${READ_ONLY:-}"

WIDE="${WIDE:-}"

AUTH_USERNAME="${AUTH_USERNAME-}"

AUTH_PASSWORD="${AUTH_PASSWORD-""}"

FOOTER_TEXT="${FOOTER_TEXT-}"

BIND_ADDR="${BIND_ADDR-""}"

PORT="${PORT:-"8080"}" THREADS="${THREADS:-"1"}"

modem7 commented 1 year ago

Accidental double post of https://github.com/szabodanika/microbin/issues/66