Files
ignis/scripts/entrypoint.sh

83 lines
2.8 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
2026-03-21 00:34:52 +01:00
# Create user with specified UID/GID
PUID=${PUID:-1000}
PGID=${PGID:-1000}
# Create group if GID doesn't exist, otherwise use existing
if ! getent group "$PGID" >/dev/null 2>&1; then
groupadd -g "$PGID" ignis
else
EXISTING_GROUP=$(getent group "$PGID" | cut -d: -f1)
echo "[ignis] Using existing group $EXISTING_GROUP (GID $PGID)"
fi
# Create user if UID doesn't exist, otherwise use existing
if ! id -u "$PUID" >/dev/null 2>&1; then
GROUP_NAME=$(getent group "$PGID" | cut -d: -f1)
useradd -u "$PUID" -g "$PGID" -m -s /bin/bash ignis 2>/dev/null || useradd -u "$PUID" -g "$GROUP_NAME" -M -N ignis
RUN_USER="ignis"
else
RUN_USER=$(id -un "$PUID")
echo "[ignis] Using existing user $RUN_USER (UID $PUID)"
fi
# Fix ownership of volumes
chown -R "$PUID:$PGID" /vaults /app/obsidian-app
OBSIDIAN_DIR="/app/obsidian-app"
OBSIDIAN_VERSION="${OBSIDIAN_VERSION:-1.12.4}"
if [ ! -f "$OBSIDIAN_DIR/index.html" ]; then
echo "[ignis] First run. Downloading Obsidian v${OBSIDIAN_VERSION}..."
curl -fSL "https://github.com/obsidianmd/obsidian-releases/releases/download/v${OBSIDIAN_VERSION}/obsidian_${OBSIDIAN_VERSION}_amd64.deb" \
-o /tmp/obsidian.deb
echo "[ignis] Extracting .deb..."
mkdir -p /tmp/obsidian-deb /tmp/obsidian-pkg
ar x /tmp/obsidian.deb --output=/tmp/obsidian-deb
tar -xf /tmp/obsidian-deb/data.tar.xz -C /tmp/obsidian-pkg
echo "[ignis] Unpacking asar..."
npx --yes @electron/asar extract \
/tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \
"$OBSIDIAN_DIR"
rm -rf /tmp/obsidian.deb /tmp/obsidian-deb /tmp/obsidian-pkg
echo "[ignis] Obsidian v${OBSIDIAN_VERSION} ready."
else
echo "[ignis] Obsidian already set up."
fi
# Always patch and copy latest bundles (they may have been updated between rebuilds)
node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR"
cp /app/dist/ignis-ui.js "$OBSIDIAN_DIR/ignis-ui.js"
cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js"
cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png"
cp /app/server/assets/* "$OBSIDIAN_DIR/" 2>/dev/null || true
# Install obsidian-headless (ob CLI) if not already present.
# Not included in the image for legal reasons - installed at runtime.
if ! command -v ob &>/dev/null; then
echo "[ignis] Installing obsidian-headless..."
if npm install -g --prefix /usr/local obsidian-headless --silent 2>/dev/null; then
OB_VERSION=$(ob --version 2>/dev/null)
if [ -n "$OB_VERSION" ]; then
echo "[ignis] obsidian-headless $OB_VERSION installed."
else
echo "[ignis] WARNING: obsidian-headless installed but 'ob' command not working."
fi
else
echo "[ignis] WARNING: Failed to install obsidian-headless. Headless sync will not be available."
fi
else
echo "[ignis] obsidian-headless $(ob --version 2>/dev/null) available."
fi
2026-03-21 00:34:52 +01:00
# Run as the determined user
exec gosu "$RUN_USER" node /app/server/index.js