diff --git a/autosetup.sh b/autosetup.sh new file mode 100644 index 0000000..450aa75 --- /dev/null +++ b/autosetup.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +# --- Fully Automated "Plug and Play" Project Setup Script --- +# +# This script will: +# 1. Take all necessary environment variables as command-line arguments. +# 2. Verify that the required Docker Compose and Traefik files exist. +# 3. Create the main project directory. +# 4. Move the necessary configuration files into the new directory. +# 5. Generate a .env file using the user-provided variables. +# 6. Create an empty acme.json file for Traefik and set permissions. +# 7. Start the services using podman-compose in detached mode. +# 8. Restart the services to ensure they use the newly created .env file. + +# Define the name of the main project directory +PROJECT_DIR="notesnook-sync" + +# Define the required configuration files as a single string, separated by spaces +REQUIRED_FILES="docker-compose.yml traefik.yml" + +# --- Step 1: Verify command-line arguments --- +if [ "$#" -ne 6 ]; then + echo "Usage: $0 \"TRAEFIK_AUTH_USER_HASH\" \"MINIO_ROOT_PASSWORD\" \"SERVICE_DISCOVERY_URL\" \"SERVICE_DISCOVERY_TOKEN\" \"ATTACHMENTS_SERVER_PUBLIC_URL\" \"MONOGRAPH_PUBLIC_URL\"" + echo "" + echo "Example: $0 \"admin:$apr1$...\" \"A_SECURE_PASSWORD\" \"https://sync.example.com\" \"A_LONG_TOKEN\" \"https://s3.example.com\" \"https://monograph.example.com\"" + exit 1 +fi + +# Assign command-line arguments to variables +TRAEFIK_AUTH_USER="$1" +MINIO_ROOT_PASSWORD="$2" +SERVICE_DISCOVERY_URL="$3" +SERVICE_DISCOVERY_TOKEN="$4" +ATTACHMENTS_SERVER_PUBLIC_URL="$5" +MONOGRAPH_PUBLIC_URL="$6" + +echo "All information has been gathered. Proceeding with setup..." +echo "" + +# --- Step 2: Verify required files exist --- +echo "--- Verifying required files ---" +for file in $REQUIRED_FILES; do + if [ ! -f "$file" ]; then + echo "Error: Required file '$file' not found in the current directory." + echo "Please place '$file' in the same directory as this script and try again." + exit 1 + fi +done +echo "All required files found. Proceeding with setup." +echo "" + +# --- Step 3: Create the main project directory --- +if [ ! -d "$PROJECT_DIR" ]; then + echo "Creating directory: $PROJECT_DIR" + mkdir -p "$PROJECT_DIR" +else + echo "Directory '$PROJECT_DIR' already exists. Skipping creation." +fi +echo "" + +# --- Step 4: Move configuration files into the new directory --- +echo "Moving required configuration files into '$PROJECT_DIR'..." +mv $REQUIRED_FILES "$PROJECT_DIR/" +echo "" + +# --- Step 5: Create and populate the .env file with user-provided variables --- +ENV_FILE="${PROJECT_DIR}/.env" +echo "Creating and populating .env file: $ENV_FILE" +cat > "$ENV_FILE" << EOF +# --- Notesnook Sync Service Environment Variables --- +# +TRAEFIK_AUTH_USER=$TRAEFIK_AUTH_USER +MINIO_ROOT_PASSWORD=$MINIO_ROOT_PASSWORD +SERVICE_DISCOVERY_URL=$SERVICE_DISCOVERY_URL +SERVICE_DISCOVERY_TOKEN=$SERVICE_DISCOVERY_TOKEN +ATTACHMENTS_SERVER_PUBLIC_URL=$ATTACHMENTS_SERVER_PUBLIC_URL +MONOGRAPH_PUBLIC_URL=$MONOGRAPH_PUBLIC_URL +EOF +echo ".env file created with your credentials." +echo "" + +# --- Step 6: Create the acme.json file and set permissions for Traefik --- +ACME_FILE="${PROJECT_DIR}/acme.json" +if [ ! -f "$ACME_FILE" ]; then + echo "Creating empty acme.json file for Traefik." + touch "$ACME_FILE" + echo "Setting file permissions to 600 for security." + chmod 600 "$ACME_FILE" +else + echo "File '$ACME_FILE' already exists. Skipping creation." +fi +echo "" + +# --- Step 7: Navigate and run the services automatically --- +echo "--- Starting services ---" +echo "Changing into the '$PROJECT_DIR' directory..." +cd "$PROJECT_DIR" + +echo "Starting services with podman-compose..." +podman-compose up -d + +# --- Step 8: Restart services to load new .env file --- +echo "Restarting services to load environment variables..." +podman-compose restart + +# --- Final Instructions --- +echo "" +echo "--- Setup Complete! ---" +echo "The services are now running in the background." +echo "You can check their status with: podman-compose ps" +echo ""