Created
July 8, 2025 09:18
-
-
Save rwunsch/7aa22e8a1ae632caa61a9ea9e03185c6 to your computer and use it in GitHub Desktop.
AEM 6.5 START script with Java 11 check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # export OAUTH_INTEGRATION_ENABLED_ENVIRONMENTS=true | |
| SCRIPT_DIR=$(dirname "$(realpath "$0")") | |
| DIRECTORY=$SCRIPT_DIR/crx-quickstart | |
| ADMIN_PASSWORD="admin" | |
| LOG_FILE="$DIRECTORY/logs/error.log" | |
| INSTALL_DIR="$DIRECTORY/install" | |
| INSTALL_DIR_FROM="$SCRIPT_DIR/install" | |
| cd "$SCRIPT_DIR" | |
| # Check Java version (require Java 11) | |
| JAVA_VERSION_OUTPUT=$(java -version 2>&1) | |
| JAVA_VERSION=$(echo "$JAVA_VERSION_OUTPUT" | awk -F[\".] '/version/ {print $2}') | |
| if [ "$JAVA_VERSION" -ne 11 ]; then | |
| echo "ERROR: Java 11 is required, but found Java version:" | |
| echo "$JAVA_VERSION_OUTPUT" | |
| exit 1 | |
| else | |
| echo "Java 11 is correctly detected." | |
| fi | |
| # Check if port 4502 is free by counting the lines | |
| line_count=$(netstat -tuln | awk '$4 ~ /:4502$/ && $6 == "LISTEN"' | wc -l) | |
| if [ "$line_count" -eq 0 ]; then | |
| echo "Port 4502 is free to use." | |
| else | |
| echo "Another service is already running on port 4502. Exiting..." | |
| exit 1 | |
| fi | |
| # Check if another AEM process is running | |
| if ps aux | grep -E -i "java.* -jar (.*aem-.*\.jar|.*cq-quickstart.*\.jar)" | grep -v "grep" > /dev/null; then | |
| echo "Another AEM process is already running. Exiting..." | |
| exit 1 | |
| else | |
| echo "No other AEM process is running ..." | |
| fi | |
| # Find the .jar file | |
| AEM_JAR=$(find "$SCRIPT_DIR" -maxdepth 1 -type f -regex ".*\(aem-.*\.jar\|cq-quickstart.*\.jar\)" | head -n 1) | |
| if [ -z "$AEM_JAR" ]; then | |
| echo "No AEM or CQ Quickstart jar file found. Exiting..." | |
| exit 1 | |
| else | |
| echo "Found AEM jar file: $AEM_JAR" | |
| fi | |
| # Unpack AEM if necessary | |
| if [ ! -d "$DIRECTORY" ]; then | |
| echo "Directory does not exist: $DIRECTORY." | |
| echo "UNPACKING AEM: STARTING..." | |
| java -Xmx4096M -jar "$AEM_JAR" -unpack -nointeractive | |
| echo "UNPACKING AEM: COMPLETED." | |
| fi | |
| # Start AEM | |
| echo "STARTING AEM." | |
| java -Xmx4096M -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=30303 -Dadmin.password="$ADMIN_PASSWORD" -jar "$AEM_JAR" -p4502 -r"author,localdev,dynamicmedia_scene7" -nobrowser -nointeractive -nofork & | |
| # Check for localhost:4502 to be available | |
| echo "Waiting for AEM to start on localhost:4502..." | |
| SECONDS=0 | |
| until curl -s -o /dev/null -w "%{http_code}" 'http://localhost:4502/libs/granite/core/content/login.html' | grep -q "200"; do | |
| echo -n "." | |
| sleep 1 | |
| done | |
| echo "" | |
| echo "AEM started after $SECONDS seconds." | |
| # Start Glogg | |
| glogg "$SCRIPT_DIR/crx-quickstart/logs/error.log" &>/dev/null & | |
| # Install Service Pack | |
| SERVICE_PACK_INSTALLED=$(curl -u admin:"$ADMIN_PASSWORD" -s 'http://localhost:4502/crx/packmgr/service.jsp?cmd=ls' | grep -oP 'aem-service-pkg-6\.5\.\d+\.0' | sort -V | tail -n 1) | |
| if [ -d "$SCRIPT_DIR" ]; then | |
| echo "Checking for service packs to install..." | |
| for SERVICE_PACK in "$SCRIPT_DIR"/aem-service-pkg-6.5.*.zip; do | |
| if [ -f "$SERVICE_PACK" ]; then | |
| PACK_VERSION=$(echo "$SERVICE_PACK" | grep -oP 'aem-service-pkg-6\.5\.\K(\d+)(?=\.0)') | |
| INSTALLED_VERSION=$(echo "$SERVICE_PACK_INSTALLED" | grep -oP '\d+') | |
| if [ -z "$SERVICE_PACK_INSTALLED" ] || [ "$PACK_VERSION" -gt "$INSTALLED_VERSION" ]; then | |
| echo "Installing Service Pack version $PACK_VERSION..." | |
| # curl -u admin:$ADMIN_PASSWORD -F file=@"$SERVICE_PACK" -F name="aem-service-pkg-6.5.$PACK_VERSION.0" -F force=true http://localhost:4502/crx/packmgr/service.jsp?cmd=install | |
| INSTALL_DIR="$DIRECTORY/install" | |
| mkdir -p "$INSTALL_DIR" | |
| echo "Copying $SERVICE_PACK to $INSTALL_DIR..." | |
| cp "$SERVICE_PACK" "$INSTALL_DIR" | |
| echo "Service Pack copied to $INSTALL_DIR. AEM will install it automatically on the next restart." | |
| # Monitor logs for service pack installation completion | |
| tail -F "$LOG_FILE" | grep -m 1 "com.adobe.granite.installer.Updater Content Package AEM-6.5-Service-Pack-[0-9]{2} Installed successfully" & | |
| LOG_MONITOR_PID=$! | |
| wait $LOG_MONITOR_PID | |
| echo "Service Pack version $PACK_VERSION installed." | |
| else | |
| echo "Service Pack version $PACK_VERSION is already installed. Skipping..." | |
| fi | |
| else | |
| echo "No Service Pack found to install in AEM. (Might be AEM Cloud Service?)" | |
| fi | |
| done | |
| else | |
| echo "No service packs directory found. Skipping service pack installation." | |
| fi | |
| # Install Additional Packages from INSTALL_DIR_FROM="$SCRIPT_DIR/install" to INSTALL_DIR="$DIRECTORY/install" | |
| # Copy Additional Packages | |
| if [ -d "$INSTALL_DIR_FROM" ]; then | |
| echo "Copying additional packages to the install folder..." | |
| mkdir -p "$INSTALL_DIR" # Ensure the target directory exists | |
| # Copy all .zip and .json files | |
| for PACKAGE in "$INSTALL_DIR_FROM"/*.{zip,json}; do | |
| if [ -f "$PACKAGE" ]; then | |
| echo "Copying package: $PACKAGE" | |
| cp "$PACKAGE" "$INSTALL_DIR" | |
| else | |
| echo "No additional packages (.zip or .json) found in $INSTALL_DIR_FROM." | |
| break | |
| fi | |
| done | |
| echo "Additional packages copied to $INSTALL_DIR." | |
| else | |
| echo "Source directory $INSTALL_DIR_FROM not found. Skipping additional package installation." | |
| fi | |
| # Start browser after AEM is ready | |
| wslview http://localhost:4502 & | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment