From 52b0ef769ed1eae46d6156180d2191d38dded3a3 Mon Sep 17 00:00:00 2001 From: F13 <> Date: Thu, 6 Jun 2024 22:36:57 -0500 Subject: [PATCH] Add support for UNFLIPPER_TOKEN_FILE --- README.md | 2 ++ start.sh | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0637236..b5d2b04 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,5 @@ To run: ```bash docker run -d --rm -e "UNFLIPPER_TOKEN=[token]" --name unflipper ghcr.io/f13/unflipper ``` + +`UNFLIPPER_TOKEN_FILE` is also supported for use with Docker secrets. diff --git a/start.sh b/start.sh index 38da9d4..4f308d3 100755 --- a/start.sh +++ b/start.sh @@ -1,3 +1,23 @@ #!/bin/bash -/usr/bin/env python3 start.py \ No newline at end of file +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +file_env 'UNFLIPPER_TOKEN' + +/usr/bin/env python3 start.py