Files
tidarr/docker/entrypoint.sh
cl.st 7a54c3dd76 Refacto api (#903)
* refacto wip

* move from yarn to pnpm

* update api doc

* fix pnpm

* fix ci

* fix express type

* fix api

* front fixes

* fix delete loading
2026-09-21 23:03:57 +02:00

84 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
# AUTH JWT SECRET
# Use JWT_SECRET from environment if set, otherwise generate a random one
if [ -z "$JWT_SECRET" ]; then
export JWT_SECRET=`tr -dc A-Za-z0-9 </dev/urandom | head -c 15; echo`
fi
echo "----------------------------------------"
cat << "EOF"
_____ ___ ____ _ ____ ____
|_ _|_ _| _ \ / \ | _ \| _ \
| | | || | | |/ _ \ | |_) | |_) |
| | | || |_| / ___ \| _ <| _ <
|_| |___|____/_/ \_\_| \_\_| \_\
EOF
echo "----------------------------------------"
if [ "$ENVIRONMENT" = "development" ]; then
echo " DEVELOPMENT MODE - VERSION: ${VERSION:-unknown}"
else
echo " PRODUCTION MODE - VERSION: ${VERSION:-unknown}"
fi
echo "----------------------------------------"
# Set custom umask (default: 0022 for 755 permissions)
# When PUID/PGID are set, default to 0002 for 775 permissions (group writable)
if [ -n "$UMASK" ]; then
EFFECTIVE_UMASK=$UMASK
elif [ -n "$PUID" ] && [ -n "$PGID" ]; then
EFFECTIVE_UMASK=0002
else
EFFECTIVE_UMASK=0022
fi
# Set umask for root shell
umask $EFFECTIVE_UMASK
# Install custom python packages
if [ -f /shared/requirements.txt ]; then
echo "🐍 [TIDARR] Install custom python requirements ..."
python -m pip install --no-cache-dir -r /shared/requirements.txt
fi
# Set ownership of shared directories if PUID/PGID are set
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
echo "🔑 [TIDARR] Setting ownership to PUID=$PUID PGID=$PGID"
echo "🔑 [TIDARR] Using UMASK=$EFFECTIVE_UMASK"
# Create required directories if they don't exist
mkdir -p /shared/.processing 2>/dev/null || true
mkdir -p /shared/.tiddl 2>/dev/null || true
mkdir -p /shared/beets 2>/dev/null || true
# Change ownership only of specific Tidarr-related files/directories
# Avoid traversing cache directories (.cache, .pnpm-store, .pki, node_modules)
chown $PUID:$PGID /shared 2>/dev/null || true
find /shared -mindepth 1 \( -path /shared/.npm -o -path /shared/.pnpm-store -o -path /shared/.cache \) -prune -o -exec chown $PUID:$PGID {} +
# In production, allow the user to write custom.css in the app/build directory
if [ "$ENVIRONMENT" != "development" ]; then
chown -R $PUID:$PGID /tidarr/app/build 2>/dev/null || true
fi
# Run as specified UID/GID using su-exec
# Set HOME to /shared for tiddl config access
# Export UMASK as environment variable so Node.js can access it for setPermissions()
# Set umask for any processes that respect it (tiddl/Python ignores shell umask)
if [ "$ENVIRONMENT" = "development" ]; then
exec su-exec $PUID:$PGID sh -c "export HOME=/shared && export UMASK=$EFFECTIVE_UMASK && umask $EFFECTIVE_UMASK && export CI=true && exec sh -c 'pnpm install && pnpm dev'"
else
exec su-exec $PUID:$PGID sh -c "export HOME=/shared && export UMASK=$EFFECTIVE_UMASK && umask $EFFECTIVE_UMASK && exec pnpm --filter tidarr-api prod"
fi
else
# Run as root (default)
if [ "$ENVIRONMENT" = "development" ]; then
export CI=true
pnpm install
pnpm dev
else
pnpm --filter tidarr-api prod
fi
fi