Created
December 1, 2016 12:50
-
-
Save joemaffia/121ffd1748ce89fa61c440f8d8dd80fd to your computer and use it in GitHub Desktop.
AEM Content Refresh via packmgr
This file contains 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
#!/bin/bash | |
############ log file configuration ############## | |
LOG_DIR="./" | |
today=$(date +"%Y-%m-%d") | |
logfile="$LOG_DIR/aem-content-refresh.log.$today" | |
############ Environment connections ############## | |
# Source Author Slave | |
SOURCE_AUTH_LOGIN="admin" | |
SOURCE_AUTH_PASSWORD="admin" | |
SOURCE_AUTH_URL="0.0.0.0" | |
SOURCE_AUTH_PORT="4502" | |
# Source Publish | |
SOURCE_PUB_LOGIN="admin" | |
SOURCE_PUB_PASSWORD="admin" | |
SOURCE_PUB_URL="0.0.0.0" | |
SOURCE_PUB_PORT="4503" | |
# Destination Author | |
DESTINATION_AUTH_LOGIN="admin" | |
DESTINATION_AUTH_PASSWORD="admin" | |
DESTINATION_AUTH_URL="0.0.0.0" | |
DESTINATION_AUTH_PORT="4502" | |
# Destination Publish | |
DESTINATION_PUB1_LOGIN="admin" | |
DESTINATION_PUB1_PASSWORD="admin" | |
DESTINATION_PUB1_URL="0.0.0.0" | |
DESTINATION_PUB1_PORT="4503" | |
############ Paths to be copied ############## | |
# Paths - uncomment or adjust as needed, will iterate through each path | |
PKG_PATHS=( | |
"/etc/packages/something/content.zip" | |
"/etc/packages/something/dam.zip" | |
) | |
########## Configuration Setup Section (END) ################# | |
############################################################## | |
##################### Functions Start ##################################### | |
workflow_toggle() { | |
state="${1}" | |
host="${2}" | |
port="${3}" | |
login="${4}" | |
password="${5}" | |
echo "-------- Workflow Curl Output - Start -------" | |
curl -is -u "$login:$password" -e "http://$host:$port/system/console/configMgr" "http://$host:$port/system/console/bundles/com.adobe.granite.workflow.core" -F "action=$state" | |
echo | |
echo "-------- Workflow Curl Output - End -------" | |
echo | |
} | |
rebuild_download() { | |
src_host="${1}" | |
src_port="${2}" | |
src_login="${3}" | |
src_password="${4}" | |
for location in "${PKG_PATHS[@]}"; do | |
echo | |
echo "Rebuild packages on $src_host" | |
echo -e "Rebuild package.... $location start time: $(date +"%m-%d-%Y %H:%M") \n" | |
curl -u $src_login:$src_password -X POST http://$src_host:$src_port/crx/packmgr/service/.json$location?cmd=build | |
echo -e "\n\nRebuild completion time: $(date +"%m-%d-%Y %H:%M") " | |
echo | |
echo "Download packages from $src_host" | |
echo -e "Download package.... $location start time: $(date +"%m-%d-%Y %H:%M") \n" | |
curl -u $src_login:$src_password http://$src_host:$src_port$location > ${location##*/} | |
echo -e "\n\nDownload completion time: $(date +"%m-%d-%Y %H:%M") " | |
done | |
} | |
upload_install() { | |
dst_host="${1}" | |
dst_port="${2}" | |
dst_login="${3}" | |
dst_password="${4}" | |
echo "Disabling workflows on $dst_host" | |
workflow_toggle stop "$dst_host" "$dst_port" "$dst_login" "$dst_password" | |
for location in "${PKG_PATHS[@]}"; do | |
echo | |
echo "Upload & Install packages from $src_host to $dst_host" | |
echo -e "Upload & Install package.... $location start time: $(date +"%m-%d-%Y %H:%M") \n" | |
curl -u "$dst_login:$dst_password" -F file=@"${location##*/}" -F name="${location##*/}" -F force=true -F install=true "http://$dst_host:$dst_port/crx/packmgr/service.jsp" | |
echo -e "\n\nUpload & Install completion time: $(date +"%m-%d-%Y %H:%M") " | |
done | |
echo | |
echo "Enabling workflows on $dst_host" | |
workflow_toggle start "$dst_host" "$dst_port" "$dst_login" "$dst_password" | |
} | |
###################### Functions End ###################################### | |
############################## start log file ############################## | |
# capture the rest of the stdout & stderr into the log file | |
exec >>$logfile 2>&1 | |
starttime=$(date) | |
echo "************* Content Refresh script start time ************************" | |
echo $starttime | |
echo "************************************************************************" | |
echo | |
################# 2.Author Refresh ################# | |
if [ -n "$DESTINATION_AUTH_LOGIN" ]; then | |
echo -e "################# 2.Author Refresh #################" | |
rebuild_download "$SOURCE_AUTH_URL" "$SOURCE_AUTH_PORT" "$SOURCE_AUTH_LOGIN" "$SOURCE_AUTH_PASSWORD" | |
upload_install "$DESTINATION_AUTH_URL" "$DESTINATION_AUTH_PORT" "$DESTINATION_AUTH_LOGIN" "$DESTINATION_AUTH_PASSWORD" | |
else | |
echo "No Author Login set" | |
fi | |
################# 3.Publish Refresh ################# | |
################# duplicate for x number of Publish environments ################# | |
if [ -n "$DESTINATION_PUB1_LOGIN" ]; then | |
echo -e "################# 3.Publish Refresh #################" | |
rebuild_download "$SOURCE_PUB_URL" "$SOURCE_PUB_PORT" "$SOURCE_PUB_LOGIN" "$SOURCE_PUB_PASSWORD" | |
upload_install "$DESTINATION_PUB1_URL" "$DESTINATION_PUB1_PORT" "$DESTINATION_PUB1_LOGIN" "$DESTINATION_PUB1_PASSWORD" | |
else | |
echo "No Publish 1 Destination set" | |
fi | |
########### 6.Write to Log and Print complete ############## | |
endtime=$(date) | |
echo | |
echo "******************* Content Refresh complete ************************" | |
echo "Start Time: " $starttime " | End Time: " $endtime | |
echo "*********************************************************************" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment