aboutsummaryrefslogtreecommitdiff
path: root/minidlna/entrypoint.sh
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2023-02-19 00:27:14 +0300
committerNeonXP <i@neonxp.dev>2023-02-19 00:27:14 +0300
commit26391945013bbcb647568da54be967e156f89032 (patch)
tree461cfa51a80fece21fe72c19d5a072877aaabf2b /minidlna/entrypoint.sh
initialHEADmaster
Diffstat (limited to 'minidlna/entrypoint.sh')
-rwxr-xr-xminidlna/entrypoint.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/minidlna/entrypoint.sh b/minidlna/entrypoint.sh
new file mode 100755
index 0000000..5b77916
--- /dev/null
+++ b/minidlna/entrypoint.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+
+# Bash strict mode
+set -euo pipefail
+IFS=$'\n\t'
+
+# DEBUG
+[ -z "${DEBUG:-}" ] || set -x
+
+# VARs
+export TZ="${TZ:-}"
+export PUID="${PUID:-100}"
+export PGID="${PGID:-101}"
+export PIDFILE='/minidlna/minidlna.pid'
+export FORCE_SCAN="${FORCE_SCAN:-false}"
+export FORCE_REBUILD="${FORCE_REBUILD:-false}"
+
+# Remove old pid if it exists
+[ -f "$PIDFILE" ] && rm -f "$PIDFILE"
+
+echo '=== Set user and group identifier'
+groupmod --non-unique --gid "$PGID" minidlna
+usermod --non-unique --uid "$PUID" minidlna
+
+if [[ -n "$TZ" ]]; then
+ echo '=== Set timezone'
+ setup-timezone -z "$TZ"
+fi
+
+echo '=== Set standard configuration'
+export MINIDLNA_DB_DIR="${MINIDLNA_DB_DIR:-/minidlna/cache}"
+export MINIDLNA_LOG_DIR="${MINIDLNA_LOG_DIR:-/minidlna}"
+export MINIDLNA_INOTIFY="${MINIDLNA_INOTIFY:-yes}"
+
+echo '=== Set configuration from environment variables'
+: > /etc/minidlna.conf
+for VAR in $(env); do
+ if [[ "$VAR" =~ ^MINIDLNA_ ]]; then
+ if [[ "$VAR" =~ ^MINIDLNA_MEDIA_DIR ]]; then
+ minidlna_name='media_dir'
+ else
+ minidlna_name=$(echo "$VAR" | sed -r "s/MINIDLNA_(.*)=.*/\\1/g" | tr '[:upper:]' '[:lower:]')
+ fi
+ minidlna_value=$(echo "$VAR" | sed -r "s/.*=(.*)/\\1/g")
+ echo "${minidlna_name}=${minidlna_value}" >> /etc/minidlna.conf
+ fi
+done
+
+echo '=== Set permissions'
+mkdir -p /minidlna/ "${MINIDLNA_DB_DIR}" "${MINIDLNA_LOG_DIR}"
+chown -R "${PUID}:${PGID}" /minidlna/ "${MINIDLNA_DB_DIR}" "${MINIDLNA_LOG_DIR}"
+
+echo '=== Generate scan/rebuild flags'
+if [[ "$FORCE_SCAN" == true ]]; then
+ set -- -r "$@"
+fi
+if [[ "$FORCE_REBUILD" == true ]]; then
+ set -- -R "$@"
+fi
+
+echo '=== Start daemon'
+exec su-exec minidlna /usr/sbin/minidlnad -P "$PIDFILE" -S "$@" \ No newline at end of file