#!/bin/bash # Script to ensure data directory exists and start the application # Define paths APP_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")" DATA_DIR="$APP_DIR/data" echo "Starting Transmission RSS Manager..." echo "Application directory: $APP_DIR" echo "Data directory: $DATA_DIR" # Ensure the data directory exists if [ ! -d "$DATA_DIR" ]; then echo "Creating data directory: $DATA_DIR" mkdir -p "$DATA_DIR" if [ $? -ne 0 ]; then echo "Failed to create data directory. Trying alternative method..." # Try alternative method if standard mkdir fails cd "$APP_DIR" && mkdir -p data if [ $? -ne 0 ]; then echo "ERROR: Both methods to create data directory failed. Please check permissions." exit 1 fi fi fi # Set permissions chmod -R 755 "$DATA_DIR" # Check for RSS files if [ ! -f "$DATA_DIR/rss-feeds.json" ]; then echo "Creating initial empty rss-feeds.json file" echo "[]" > "$DATA_DIR/rss-feeds.json" fi if [ ! -f "$DATA_DIR/rss-items.json" ]; then echo "Creating initial empty rss-items.json file" echo "[]" > "$DATA_DIR/rss-items.json" fi # Find the node executable path NODE_PATH=$(which node 2>/dev/null) if [ -z "$NODE_PATH" ]; then # If node is not in PATH, try common locations for path in /usr/bin/node /usr/local/bin/node /opt/node/bin/node /usr/lib/node; do if [ -x "$path" ]; then NODE_PATH="$path" break fi done # If we still can't find node, use the default path if [ -z "$NODE_PATH" ]; then NODE_PATH="/usr/bin/node" echo "Warning: Node.js not found in PATH, using default path: $NODE_PATH" fi fi # Create module symlinks to ensure compatibility if [ -f "$APP_DIR/scripts/create-module-links.sh" ]; then echo "Creating module symlinks for compatibility..." bash "$APP_DIR/scripts/create-module-links.sh" else echo "Warning: Module symlink script not found" fi # Start the application cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; } echo "Starting node.js application with: $NODE_PATH $APP_DIR/server.js" exec "$NODE_PATH" "$APP_DIR/server.js"