#!/bin/bash
# Author: upadhyay.yogesh@gmail.com
# The host and port of the source server
SOURCE="localhost:4504"
# The user credentials on the source server (username:password)
SOURCE_CRED="admin:admin"
#This is your package location in CRX. Change this package location based on your need
PACKAGE_LOCATION="/etc/packages/my_packages"
# This is date after which you want to delete all package <YYYY>-<MM>-<DD>
DATE="2011-12-11"
#############################################################################
#Query to get all files uploaded after certain date
ALL_PATHS=`curl -s -u $SOURCE_CRED "$SOURCE/bin/querybuilder.json?path=$PACKAGE_LOCATION&type=nt:file&p.limit=-1&daterange.property=jcr:created&daterange.upperBound=2011-11-11&daterange.upperOperation=
echo "$ALL_PATHS"
for SINGLE_PATH in $ALL_PATHS
do
# I have commented this line. Please see what is getting deleted before deleting it
# curl -u $SOURCE_CRED -X POST http://$SOURCE/crx/packmgr/service/.json$SINGLE_PATH?cmd=delete
done
You can also do if else within script to compare package name
if [[ $string =~ .*My.* ]]
then
DELETE PACKAGE
fi
Please check http://dev.day.com/docs/en/crx/current/how_to/package_manager.html#Managing Packages on the Command Line for different curl options
IMPORTANT NOTE: Please test this script before use. I have not tested this script yet :)
Using curl I have to build, download a package from one instance and upload, install in another instance. I have created a package and filter definitions and built the package from command line. All these steps should happen in windows envt in a .bat file.
ReplyDeleteBut I am having issues with simple download of package when I run the curl command. It returns gibberish... I would like to download the file to the current folder and upload to the new instance. Could you let me know the reason for the issue and any better approach.
-Gunesh
Gunesh,
ReplyDeleteWhat curl command you are using to download ?
Yogesh
Yogesh,
ReplyDeleteI am using this command in a batch file
curl -u admin:admin http://localhost:4502/etc/packages//
All other curl commands are working except this one on 5.4.
Correction:
ReplyDeletecurl -u admin:admin http://localhost:4502/etc/packages/groupname/packagename.zip
Gunesh,
ReplyDeleteUse
curl -C - -O -u admin:admin http://localhost:4502/etc/packages/groupname/packagename.zip
Let me know if that works for you.
Yogesh
Yogesh,
ReplyDeleteThis definitely works. Thanks. Also if I download a package to current folder and download it again with already existing package to the same folder, how to overwrite the existing package. I achieved it by deleting from current folder before downloading it again, but it would be great if I can overwrite the same package. I am using the curl for download from batch script.
Gunesh
Gunesh,
ReplyDeleteYou can use force upload option. I think it is force=true as form data in post.
Yogesh
Hi Yogesh,
ReplyDeleteI need to build a package using curl command. I am using the below command:
curl -X POST http://localhost:5412/crx/packmgr/service/.json/etc/packages/my_packages/Url-shorten.zip?cmd=build
The result is : {"success":false,"msg":"no package"}
Any thoughts?
I am using CQ 5.4
Thanks in advance
Regards,
Pradeep
I think you are missing -u : ... If package exist, Above command with -u should work. I just tested and it works for me.
ReplyDeletecurl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/config.zip?cmd=build
{"success":true,"msg":"Package built"}
I'm able to create a package using the following command -
ReplyDeletecurl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages?cmd=create -d packageName=testpackage -d groupName=day {"success":true,"msg":"Package created","path":"/etc/packages/day/testpackage.zip"}
But have no idea on how to set multiple filter(paths) conditions? Please can you let me know how to do this.
Hari,
DeleteYou can also use curl script to delete all packages as mention here http://www.wemblog.com/2013/05/how-to-perform-system-clean-up-in-adobe.html
Yogesh
hi
ReplyDeletecan you create a package with some filters using curl ??
Please check http://www.wemblog.com/2012/04/how-to-change-package-install-behavior.html you can dynamically change filter to create package.
DeleteHi Yogesh
ReplyDeleteWould this method work if you wanted to purge backup packages from .snapshot?
Yes. Should work. Else you can always get to .snapshot folder and delete them.
DeleteYogesh
This comment has been removed by the author.
ReplyDeleteI need to upload a package from local to server using curl command. I am using the below command:
ReplyDeletecurl -u -F package=C:/Users/Downloads/package.zip -X POST http:///crx/packmgr/service/.json/?cmd=upload
The result is : {"success":false,"msg":"package filter parameter missing"}
or else
I need to download package from one instance and also i need to upload same package into same instance.can you provide the curl command for this??
please help me out !!
Apologies..
ReplyDeleteThe command i am using..
curl -u : -F package=c:/user/downloads/package.zip http://localhost:4502/crx/packmgr/service/.json/?cmd=upload
The result is : {"success":false,"msg":"package filter parameter missing"}
Hi Team,
ReplyDeleteI want to delete packages between certain time period like 2015-06-11 to 2015-06-18. I tried all the possibilities mentioned here.
And one more requirement is like "I want to delete all the old packages if any one of the existing packages contains the same content which I am uploading now."
Could u please help me out in writing the curl command.
With Regards,
Sravani.