diff --git a/abra.sh b/abra.sh new file mode 100644 index 0000000..7c5fe57 --- /dev/null +++ b/abra.sh @@ -0,0 +1 @@ +export APP_ENTRYPOINT_VERSION=v1 diff --git a/compose.yml b/compose.yml index 0ab16e0..d234fb8 100644 --- a/compose.yml +++ b/compose.yml @@ -11,9 +11,14 @@ services: - PUID=1000 - TZ volumes: + - config:/config - books:/books networks: - proxy + configs: + - source: app_entrypoint + target: /config/custom-cont-init.d/entrypoint.sh + mode: 0555 deploy: restart_policy: condition: on-failure @@ -36,3 +41,10 @@ networks: volumes: books: + config: + +configs: + app_entrypoint: + name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION} + file: entrypoint.sh.tmpl + template_driver: golang diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl new file mode 100644 index 0000000..4cf17e7 --- /dev/null +++ b/entrypoint.sh.tmpl @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +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" +} + +if [ ! -f "/books/metadata.db" ]; then + /usr/bin/mkdir -p /books + /usr/bin/calibredb restore_database --really-do-it --with-library /books + /usr/bin/chown abc:abc /books/metadata.db +else + echo "/books/metadata.db exists, not creating another one" +fi