Created
January 29, 2025 19:33
-
-
Save rwunsch/8d1ad09efdc56294c0b650f112612d1c to your computer and use it in GitHub Desktop.
AEM Cloud Services SDK - Local Start Script
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" | |
| cd "$SCRIPT_DIR" | |
| # 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 | |
| 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 | |
| # 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