Skip to content

Instantly share code, notes, and snippets.

@fiskr
Created March 23, 2015 13:29
Show Gist options
  • Save fiskr/d25e03f67cb38470ac14 to your computer and use it in GitHub Desktop.
Save fiskr/d25e03f67cb38470ac14 to your computer and use it in GitHub Desktop.
Shell script to create, add filters to, build, and download a package all at once!
#!/bin/bash
# Create a package with a given set of root paths
#CONFIG
# you will need to change your username and group name
groupName="Brandon"
username="162084"
function specifyPackageName() {
read -p "Please specify package name. > " packageName
}
specifyPackageName
#get password from user
echo -n "Enter password. >"
read -s answer
pass="$answer"
mkdir -p packages
function specifyEnvironment() {
#check to see if input was provided
if [ $# -eq 0 ]
then
echo "No arguments supplied."
else
env=$1
fi
if [[ $env =~ dev3 ]]
then
echo "Environment is dev3: $env"
#dev hostname
hostname="author.hgtv-dev3.sni.hgtv.com"
else
if [[ $env =~ qa3 ]]
then
echo "Environment is QA3: $env"
#qa3 hostname
hostname="author.hgtv-qa3.sni.hgtv.com"
else
if [[ $env =~ prod2 ]]
then
echo "Environment is Prod2: $env"
#production hostname
hostname="author.hgtv-prod2.sni.hgtv.com"
else
#echo "Environment is neither dev nor prod, please specify."
read -p "Environment is neither dev3, qa3, nor prod2, please specify. > " answer
specifyEnvironment $answer
fi
fi
fi
}
specifyEnvironment
declare -a filterPaths=(
/content/diy-com/en/how-to-test
/content/diy-com/en/testing
)
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 ] # this is the first and only filter path
then
updateCurl="$updateCurl[{\"root\":\"$path\",\"rules\":[]}]"
else
if [ $count -eq 1 ] #this is the first element, start opening [ and forego the comma
then
updateCurl="$updateCurl[{\"root\":\"$path\",\"rules\":[]}"
else
if [ $count -eq $last ] #this is the last element, have ending ]
then
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 -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)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment