209 lines
7.3 KiB
Bash
209 lines
7.3 KiB
Bash
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
# Create necessary directories
|
|
mkdir -p /app/data/config /app/data/storage
|
|
|
|
# Print debug information about repository structure
|
|
echo "==> DEBUG: Repository structure at /app/code"
|
|
find /app/code -type d -not -path "*/node_modules/*" -not -path "*/\.*" | sort
|
|
echo "==> DEBUG: All package.json files in repository"
|
|
find /app/code -name "package.json" -not -path "*/node_modules/*" | sort
|
|
|
|
# Create config template file on first run
|
|
if [[ ! -f /app/data/config/config.yaml ]]; then
|
|
echo "==> First run - creating configuration template"
|
|
|
|
# Replace variables in template for things we know
|
|
sed \
|
|
-e "s|%%POSTGRESQL_HOST%%|${CLOUDRON_POSTGRESQL_HOST}|g" \
|
|
-e "s|%%POSTGRESQL_PORT%%|${CLOUDRON_POSTGRESQL_PORT}|g" \
|
|
-e "s|%%POSTGRESQL_USERNAME%%|${CLOUDRON_POSTGRESQL_USERNAME}|g" \
|
|
-e "s|%%POSTGRESQL_PASSWORD%%|${CLOUDRON_POSTGRESQL_PASSWORD}|g" \
|
|
-e "s|%%POSTGRESQL_DATABASE%%|${CLOUDRON_POSTGRESQL_DATABASE}|g" \
|
|
-e "s|%%APP_ORIGIN%%|${CLOUDRON_APP_ORIGIN}|g" \
|
|
-e "s|%%MAIL_SMTP_SERVER%%|${CLOUDRON_MAIL_SMTP_SERVER}|g" \
|
|
-e "s|%%MAIL_SMTP_PORT%%|${CLOUDRON_MAIL_SMTP_PORT}|g" \
|
|
-e "s|%%MAIL_SMTP_USERNAME%%|${CLOUDRON_MAIL_SMTP_USERNAME}|g" \
|
|
-e "s|%%MAIL_SMTP_PASSWORD%%|${CLOUDRON_MAIL_SMTP_PASSWORD}|g" \
|
|
-e "s|%%MAIL_FROM%%|${CLOUDRON_MAIL_FROM}|g" \
|
|
-e "s|%%MAIL_FROM_DISPLAY_NAME%%|${CLOUDRON_MAIL_FROM_DISPLAY_NAME}|g" \
|
|
/app/pkg/config.template.yaml > /app/data/config/config.yaml
|
|
|
|
# Create an S3 configuration file template
|
|
cat > /app/data/config/s3.env.template <<EOT
|
|
# S3 Configuration for Ente
|
|
# Fill in your S3 credentials and rename this file to s3.env
|
|
|
|
# S3 endpoint (example: https://s3.amazonaws.com)
|
|
S3_ENDPOINT=
|
|
|
|
# S3 region (example: us-east-1)
|
|
S3_REGION=
|
|
|
|
# S3 bucket name
|
|
S3_BUCKET=
|
|
|
|
# S3 access key
|
|
S3_ACCESS_KEY=
|
|
|
|
# S3 secret key
|
|
S3_SECRET_KEY=
|
|
|
|
# Prefix for objects in the bucket (optional)
|
|
S3_PREFIX=ente/
|
|
EOT
|
|
|
|
echo "==> IMPORTANT: S3 storage configuration required"
|
|
echo " 1. Edit the file at /app/data/config/s3.env.template"
|
|
echo " 2. Fill in your S3 credentials"
|
|
echo " 3. Rename the file to s3.env"
|
|
echo " 4. Restart the app"
|
|
|
|
# Exit with a message if this is the first run
|
|
if [[ ! -f /app/data/config/s3.env ]]; then
|
|
echo "==> Exiting. Please configure S3 storage and restart the app."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Check if s3.env exists
|
|
if [[ ! -f /app/data/config/s3.env ]]; then
|
|
echo "==> ERROR: S3 configuration not found"
|
|
echo " Please configure S3 storage by editing /app/data/config/s3.env.template"
|
|
echo " and renaming it to s3.env, then restart the app."
|
|
exit 1
|
|
fi
|
|
|
|
# Load S3 environment variables
|
|
source /app/data/config/s3.env
|
|
|
|
# Update the config file with S3 credentials
|
|
sed -i \
|
|
-e "s|%%S3_ENDPOINT%%|${S3_ENDPOINT}|g" \
|
|
-e "s|%%S3_REGION%%|${S3_REGION}|g" \
|
|
-e "s|%%S3_BUCKET%%|${S3_BUCKET}|g" \
|
|
-e "s|%%S3_ACCESS_KEY%%|${S3_ACCESS_KEY}|g" \
|
|
-e "s|%%S3_SECRET_KEY%%|${S3_SECRET_KEY}|g" \
|
|
-e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \
|
|
/app/data/config/config.yaml
|
|
|
|
# Looking for Museum (Go server component)
|
|
echo "==> Looking for Museum (Go server component)"
|
|
|
|
# Find the server directory
|
|
if [ -d "/app/code/server" ]; then
|
|
echo "==> Found server directory at /app/code/server"
|
|
SERVER_DIR="/app/code/server"
|
|
else
|
|
echo "==> ERROR: Could not find server directory at /app/code/server"
|
|
echo "==> Looking for Museum executable or source in alternate locations"
|
|
|
|
# Search for Museum executable or Go source files
|
|
GO_FILES=$(find /app/code -name "*.go" -not -path "*/\.*" | sort)
|
|
if [ -n "$GO_FILES" ]; then
|
|
echo "==> Found Go files in repository:"
|
|
echo "$GO_FILES"
|
|
|
|
# Check for museum in Go files path
|
|
if find /app/code -path "*/museum/*" -name "*.go" | grep -q .; then
|
|
MUSEUM_DIR=$(find /app/code -path "*/museum/*" -name "*.go" | head -1 | xargs dirname)
|
|
echo "==> Found Museum directory at $MUSEUM_DIR"
|
|
else
|
|
echo "==> No clear Museum directory found"
|
|
echo "==> Using first Go file directory as fallback"
|
|
FIRST_GO_FILE=$(echo "$GO_FILES" | head -1)
|
|
MUSEUM_DIR=$(dirname "$FIRST_GO_FILE")
|
|
fi
|
|
|
|
# Check for cmd/museum pattern which is mentioned in docs
|
|
if [ -d "/app/code/server/cmd/museum" ]; then
|
|
MUSEUM_DIR="/app/code/server/cmd/museum"
|
|
echo "==> Found Museum main directory at $MUSEUM_DIR"
|
|
fi
|
|
|
|
SERVER_DIR=$(dirname $(dirname "$MUSEUM_DIR"))
|
|
else
|
|
echo "==> FATAL ERROR: Could not find Go files in repository"
|
|
echo "==> Repository structure:"
|
|
find /app/code -type d -maxdepth 3 | sort
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "==> Selected server directory: $SERVER_DIR"
|
|
echo "==> Contents of $SERVER_DIR:"
|
|
ls -la "$SERVER_DIR"
|
|
|
|
# Check for server dependencies
|
|
echo "==> Installing Go dependencies"
|
|
if [ -x "$(command -v go)" ]; then
|
|
echo "==> Go is installed, version: $(go version)"
|
|
else
|
|
echo "==> Installing Go"
|
|
apt-get update && apt-get install -y golang
|
|
fi
|
|
|
|
# Check for libsodium
|
|
if dpkg -l | grep -q libsodium; then
|
|
echo "==> libsodium is installed"
|
|
else
|
|
echo "==> Installing libsodium"
|
|
apt-get update && apt-get install -y libsodium23 libsodium-dev
|
|
fi
|
|
|
|
# Check for pkg-config
|
|
if [ -x "$(command -v pkg-config)" ]; then
|
|
echo "==> pkg-config is installed"
|
|
else
|
|
echo "==> Installing pkg-config"
|
|
apt-get update && apt-get install -y pkg-config
|
|
fi
|
|
|
|
# Change to server directory
|
|
cd "$SERVER_DIR"
|
|
|
|
# Set up database environment variables
|
|
export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
|
|
export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
|
|
export ENTE_DB_HOST="${CLOUDRON_POSTGRESQL_HOST}"
|
|
export ENTE_DB_PORT="${CLOUDRON_POSTGRESQL_PORT}"
|
|
export ENTE_DB_NAME="${CLOUDRON_POSTGRESQL_DATABASE}"
|
|
export CONFIG_PATH="/app/data/config/config.yaml"
|
|
|
|
# Additional environment variables
|
|
export REMOTE_STORAGE_ENDPOINT="${S3_ENDPOINT}"
|
|
export REMOTE_STORAGE_REGION="${S3_REGION}"
|
|
export REMOTE_STORAGE_BUCKET="${S3_BUCKET}"
|
|
export REMOTE_STORAGE_ACCESS_KEY="${S3_ACCESS_KEY}"
|
|
export REMOTE_STORAGE_SECRET_KEY="${S3_SECRET_KEY}"
|
|
export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}"
|
|
|
|
# Change ownership to cloudron user
|
|
chown -R cloudron:cloudron /app/data
|
|
|
|
# Look for Museum binary first
|
|
if [ -x "$SERVER_DIR/museum" ]; then
|
|
echo "==> Found Museum binary, running it directly"
|
|
exec /usr/local/bin/gosu cloudron:cloudron "$SERVER_DIR/museum"
|
|
elif [ -d "$SERVER_DIR/cmd/museum" ]; then
|
|
echo "==> Found Museum source in cmd/museum, running with go run"
|
|
cd "$SERVER_DIR"
|
|
exec /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go
|
|
else
|
|
# Fallback approach - find main.go files
|
|
MAIN_FILES=$(find "$SERVER_DIR" -name "main.go" | grep -v "test")
|
|
if [ -n "$MAIN_FILES" ]; then
|
|
MAIN_FILE=$(echo "$MAIN_FILES" | head -1)
|
|
MAIN_DIR=$(dirname "$MAIN_FILE")
|
|
echo "==> Using main.go file at $MAIN_FILE"
|
|
cd "$MAIN_DIR"
|
|
exec /usr/local/bin/gosu cloudron:cloudron go run main.go
|
|
else
|
|
echo "==> FATAL ERROR: Could not find Museum binary or main.go source file"
|
|
echo "==> Available Go files:"
|
|
find "$SERVER_DIR" -name "*.go" | sort
|
|
exit 1
|
|
fi
|
|
fi |