Spaces:
Paused
Paused
| #!/bin/sh | |
| # Exit immediately if a command exits with a non-zero status. | |
| set -e | |
| echo "--- Running Entrypoint Script as user: $(id -u -n) ---" | |
| # --- BEGIN: Install Plugins at Runtime --- | |
| if [ -n "$PLUGINS" ]; then | |
| echo '--- Found PLUGINS environment variable, attempting to install plugins ---' | |
| # Ensure plugin dir exists within the app home | |
| mkdir -p ./plugins | |
| # Using printf/read loop which is often more robust than IFS for comma-separated lists | |
| printf "%s," "$PLUGINS" | while IFS= read -r plugin_url_with_comma; do | |
| # Remove trailing comma if exists | |
| plugin_url="${plugin_url_with_comma%,}" | |
| # Trim leading/trailing whitespace using awk (should be available via busybox) | |
| plugin_url=$(echo "$plugin_url" | awk '{$1=$1;print}') | |
| if [ -z "$plugin_url" ]; then continue; fi | |
| # Extract plugin name: remove .git suffix, then get basename | |
| # Handle URLs that might not end in .git | |
| plugin_name_tmp="${plugin_url%.git}" | |
| plugin_name="${plugin_name_tmp##*/}" | |
| if [ -z "$plugin_name" ]; then | |
| echo "WARN: Could not extract plugin name from URL: $plugin_url, skipping." | |
| continue | |
| fi | |
| plugin_dir="./plugins/$plugin_name" | |
| echo "--- Processing plugin: $plugin_name from $plugin_url ---" | |
| # Clone (remove existing first for clean install) | |
| echo "Removing existing directory $plugin_dir (if any)..." | |
| rm -rf "$plugin_dir" | |
| echo "Cloning $plugin_name from $plugin_url into $plugin_dir..." | |
| if git clone --depth 1 "$plugin_url" "$plugin_dir"; then | |
| echo "Cloned successfully." | |
| # Install dependencies if package.json exists | |
| if [ -f "$plugin_dir/package.json" ]; then | |
| echo "Found package.json, installing dependencies for $plugin_name..." | |
| # Run npm install within the plugin directory using a subshell | |
| (cd "$plugin_dir" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force) | |
| if [ $? -ne 0 ]; then | |
| echo "WARN: Failed to install dependencies for $plugin_name" | |
| else | |
| echo "Dependencies installed for $plugin_name." | |
| fi | |
| else | |
| echo "No package.json found for $plugin_name, skipping dependency install." | |
| fi | |
| else | |
| echo "WARN: Failed to clone $plugin_name from $plugin_url, skipping further processing." | |
| fi | |
| echo "--- Finished processing $plugin_name ---" | |
| done | |
| echo '--- Finished installing all specified plugins ---' | |
| else | |
| echo '--- PLUGINS environment variable not set or empty, skipping plugin installation ---' | |
| fi | |
| # --- END: Install Plugins at Runtime --- | |
| # --- Config Handling --- | |
| echo '--- Checking for CONFIG_YAML environment variable ---' | |
| CONFIG_FILE="./config.yaml" | |
| if [ -n "$CONFIG_YAML" ]; then | |
| echo "Environment variable CONFIG_YAML found. Writing to $CONFIG_FILE..." | |
| # Write directly to ./config.yaml in the CWD (should be APP_HOME) | |
| # Use printf to handle potential special characters in YAML | |
| printf '%s\n' "$CONFIG_YAML" > "$CONFIG_FILE" | |
| if [ $? -eq 0 ]; then | |
| echo "Config written to $CONFIG_FILE successfully." | |
| # --- BEGIN DEBUG: Print the written config file --- | |
| echo "--- Verifying written $CONFIG_FILE ---" | |
| cat "$CONFIG_FILE" | |
| echo "--- End of $CONFIG_FILE ---" | |
| # --- END DEBUG --- | |
| else | |
| echo "ERROR: Failed to write config to $CONFIG_FILE" >&2 | |
| # Clear variable so default logic runs if write failed | |
| CONFIG_YAML="" | |
| fi | |
| else | |
| echo 'Warning: Environment variable CONFIG_YAML is not set or empty.' | |
| fi | |
| # If config file doesn't exist or is empty after potential write attempt, try default | |
| if [ ! -s "$CONFIG_FILE" ]; then | |
| echo "Attempting to copy default config (because $CONFIG_FILE is missing or empty)..." | |
| DEFAULT_CONFIG_EXAMPLE="./public/config.yaml.example" | |
| if [ -f "$DEFAULT_CONFIG_EXAMPLE" ]; then | |
| cp "$DEFAULT_CONFIG_EXAMPLE" "$CONFIG_FILE" && \ | |
| echo "Copied default config from $DEFAULT_CONFIG_EXAMPLE to $CONFIG_FILE" | |
| else | |
| echo "Warning: Default config $DEFAULT_CONFIG_EXAMPLE not found. SillyTavern might fail without a config file." | |
| fi | |
| fi | |
| # --- END Config Handling --- | |
| # --- BEGIN: Configure Git default identity at Runtime --- | |
| # This is needed if plugins perform git operations | |
| echo '--- Configuring Git default user identity at runtime ---' | |
| # Check if user.name or user.email is already set to avoid errors | |
| # Use git config commands directly, checking return code isn't strictly needed here | |
| git config --global user.name "SillyTavern Sync" || echo "Could not set git user.name" | |
| git config --global user.email "sillytavern-sync@example.com" || echo "Could not set git user.email" | |
| # Ensure the app directory is marked as safe | |
| git config --global --add safe.directory "$APP_HOME" || echo "Could not add safe directory" | |
| echo '--- Git identity configured (or attempted) for runtime user. ---' | |
| # --- END: Configure Git default identity at Runtime --- | |
| echo "--- Starting SillyTavern server ---" | |
| # Execute node server directly. 'exec' replaces the shell process with the node process. | |
| exec node server.js |