Created
April 24, 2015 17:28
-
-
Save fiskr/f540b374966f5fbaa107 to your computer and use it in GitHub Desktop.
This combines the create_package and install_package scripts into one file that shares the redundant functions like specifyEnvironment
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 | |
# Create a package with a given set of root paths | |
groupName="Brandon" | |
function requestPass() { | |
username="162084" | |
#get password from user | |
echo -n "Enter password. >" | |
read -s answer | |
pass="$answer" | |
echo "" | |
} | |
mkdir -p packages | |
function specifyPackageName() { | |
read -p "Please specify package name. > " packageName | |
} | |
function specifyEnvironment() { | |
#check to see if input was provided | |
if [ $# -eq 0 ] | |
then | |
#echo "No arguments supplied." | |
echo -n "" | |
else | |
env=$1 | |
fi | |
if [[ $env =~ dev3 ]] | |
then | |
echo "Environment is dev3: $env" | |
#dev hostname | |
hostname="author1.hgtv-dev3.sni.hgtv.com:4502" | |
requestPass | |
else | |
if [[ $env =~ dev4 ]]; then | |
echo "Environment is dev4: $env" | |
#dev4 hostname | |
hostname="author1.hgtv-dev4.sni.hgtv.com:4502" | |
requestPass | |
else | |
if [[ $env =~ qa3 ]] | |
then | |
echo "Environment is QA3: $env" | |
#qa3 hostname | |
hostname="author1.hgtv-qa3.sni.hgtv.com:4502" | |
requestPass | |
else | |
if [[ $env =~ prod ]] | |
then | |
echo "Environment is production: $env" | |
#production hostname | |
hostname="author1.hgtv-prod2.sni.hgtv.com:4502" | |
requestPass | |
else | |
if [[ $env =~ local ]] | |
then | |
echo "Environment is local: $env" | |
#local hostname | |
hostname="localhost:4502" | |
username="admin" | |
pass="admin" | |
else | |
#echo "Environment is neither dev nor prod, please specify." | |
read -p "Environment is neither dev nor prod, please specify. > " answer | |
specifyEnvironment $answer | |
fi | |
fi | |
fi | |
fi | |
fi | |
} | |
declare -a filterPaths=( | |
/content/dam/images/hgtv/editorial/tentpoles/hgtv-dream-home-2015/tours | |
/content/dam/images/RX-DH15_quicken-product-shot.jpg | |
/content/gac-com/en/test-GPC-196 | |
) | |
function createPackage() { | |
echo "What would you like to name the package you are creating?" | |
specifyPackageName | |
echo "Which environment would you like to create this package on?" | |
specifyEnvironment | |
updateCurl="curl -u $username:$pass -X POST -F packageName=$packageName -F groupName=$groupName -F filter=" | |
count="0" | |
last="${#filterPaths[@]}" # the total number of elements in the path array above | |
for path in "${filterPaths[@]}" | |
do | |
count=`expr $count + 1` | |
if [ $count -eq 1 ] && [ $count -eq $last ]; then # this is the first and only filter path | |
updateCurl="$updateCurl[{\"root\":\"$path\",\"rules\":[]}]" | |
else | |
if [ $count -eq 1 ]; then #this is the first element, start opening [ and forego the comma | |
updateCurl="$updateCurl[{\"root\":\"$path\",\"rules\":[]}" | |
else | |
if [ $count -eq $last ]; then #this is the last element, have ending ] | |
updateCurl="$updateCurl,{\"root\":\"$path\",\"rules\":[]}]" | |
else | |
updateCurl="$updateCurl,{\"root\":\"$path\",\"rules\":[]}" | |
fi | |
fi | |
fi | |
done | |
updateCurl="$updateCurl -F packageName=$packageName -F path=/etc/packages/$groupName/$packageName.zip http://$hostname/crx/packmgr/update.jsp" | |
createCurl="curl -u $username:$pass -X POST http://$hostname/crx/packmgr/service/.json/etc/packages/$groupName/$packageName.zip?cmd=create -F packageName=$packageName -F groupName=$groupName" | |
buildCurl="curl --connect-timeout 3600 --max-time 3600 -u $username:$pass -X POST http://$hostname/crx/packmgr/service/.json/etc/packages/$groupName/$packageName.zip?cmd=build" | |
echo "Creating package!" | |
echo "$($createCurl)" | |
echo "Adding filters to package!" | |
echo "$($updateCurl)" | |
echo "Building package!" | |
echo "$($buildCurl)" | |
downloadCurl="curl -o ./packages/$packageName.zip -u $username:$pass http://$hostname/etc/packages/$groupName/$packageName.zip" | |
echo "Downloading package!" | |
echo "$($downloadCurl)" | |
} | |
function installPackage() { | |
echo "Which environment would you like to install to?" | |
specifyEnvironment "" | |
package="./packages/$packageName.zip" | |
doesExist="curl -u $username:$pass -sL --head -w %{http_code} http://$hostname/etc/packages/$groupName/$packageName.zip -o /dev/null" | |
responseCode="$($doesExist)" | |
if [[ $responseCode = "200" ]]; then | |
echo "Deleting package $packageName: " | |
echo "$(curl -w 'Response Code: %{http_code} | Connect: %{time_connect} | TTFB: %{time_starttransfer} | Total time: %{time_total} \n' -o /dev/null -u $username:$pass -F package=@$package http://$hostname/crx/packmgr/service/.json/?cmd=delete)" | |
else | |
echo "Package doesn't exist (response code: $responseCode); no need to delete." | |
fi | |
echo "Uploading package $packageName: " | |
echo "$(curl -w 'Response Code: %{http_code} | Connect: %{time_connect} | TTFB: %{time_starttransfer} | Total time: %{time_total} \n' -o /dev/null -u $username:$pass -F package=@$package http://$hostname/crx/packmgr/service/.json/?cmd=upload)" | |
installUrl="http://$hostname/crx/packmgr/service/.json/etc/packages/$groupName/$packageName.zip?cmd=install" | |
echo "Installing Package $packageName:" | |
echo "$( curl --connect-timeout 3600 -u $username:$pass -X POST "$installUrl" )" | |
} | |
function specifyAction() { | |
#check to see if input was provided | |
if [ $# -eq 0 ]; then | |
#echo "No arguments supplied." | |
echo -n "" | |
else | |
action=$1 | |
fi | |
if [[ $action =~ C ]]; then | |
echo "Your action is to create a package: $action" | |
createPackage | |
else | |
if [[ $action =~ I ]]; then | |
echo "Your action is to install packages: $action" | |
echo "What package would you like to install?" | |
specifyPackageName "" | |
installPackage | |
else | |
if [[ $action =~ B ]]; then | |
echo "Your action is to do both, create and install: $action" | |
createPackage | |
installPackage | |
else | |
read -p "Please specify action: Create package, Install package, or Both. >" action | |
specifyAction $action | |
fi | |
fi | |
fi | |
} | |
specifyAction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment