forked from wttech/CQ-Unix-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcqpkg
executable file
·241 lines (220 loc) · 6.77 KB
/
cqpkg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/sh
# CQ Unix Toolkit
# Copyright (C) 2013 Cognifide Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_usage()
{
cat <<EOT
Usage: $(basename "${0}") [SPECIFICATION...] package-name
Create minimal empty CQ Vault ZIP package locally using provided specification
that can be uploaded to CRX/CQ Package Manager and built or installed.
Please note that all CQ-related files like 'nodetype.cnd' are added to package
during it's building (see 'cqbld' command).
Examples:
cqpkg -r /content content # Create package 'content-1.0.zip'
# in current working directory named
# 'content' that holds '/content' node
# and all subnodes under it.
cqpkg -r /content -o /tmp/pack.zip # Create package 'pack.zip'
content # in '/tmp' directory named
# 'content' that holds '/content' node
# and all subnodes under it.
cqpkg -r /content -g mypackages # Create package 'content-2.0.zip'
-v 2.0 -d 'My first package' # named content with version 2.0,
content # with group 'mypackages' (as namespace)
# with 'My first package' description
# that holds /content node and all
# subnodes under it
cqpkg -r /content/dam # Create dam-jpeg package
-i '/content/dam(/[^/.]+)*(/[^/\.]+\.jpe?g(/.*)?)?$'
dam-jpeg # that holds .jpeg or .jpg nodes
# from /content/dam node.
Options:
-g GROUP define Vault group/namespace for package
-v VERSION define version for package
-d DESCRIPTION define user-friendly package description
-r JCRPATH define new filter root JCR path (allowed many times)
-i REGEXP define include regular expression (allowed many times)
for current filter root path (indicated by -r)
-e REGEXP define exclude regular expression (allowed many times)
for current filter root path (indicated by -r)
-o ZIPPATH generates package in path specified by ZIPPATH
EOT
exit 1
}
_add_filter()
{
filter_definition=$(cat <<EOF
${filter_definition}
<filter root="${1}">
EOF
)
}
_add_include_entry()
{
filter_definition=$(cat <<EOF
${filter_definition}
<include pattern="${1}"/>
EOF
)
}
_add_exclude_entry()
{
filter_definition=$(cat <<EOF
${filter_definition}
<exclude pattern="${1}"/>
EOF
)
}
CWD=$(dirname "${0}")
API="${CWD}/cqapi"
"${API}" -P >/dev/null
if [ ${?} -ne 0 ]
then
echo "Fatal: cannot find or test cqapi command" >&2
exit 1
fi
filter_definition=$(cat <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
EOT
)
toolkit_version=$("${API}" -v)
package_definition=$(cat <<EOT
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>FileVault Package Properties</comment>
<entry key="createdBy">cq-unix-toolkit</entry>
<entry key="buildCount">1</entry>
<entry key="dependencies"/>
<entry key="packageFormatVersion">2</entry>
EOT
)
description="Package genereated by CQ Unix Toolkit ${toolkit_version}"
in_filter_context=0
version="1.0"
while getopts ":g:v:r:i:e:o:d:" opt
do
case "${opt}" in
g)
group="${OPTARG}";;
v)
version="${OPTARG}";;
d)
description="${OPTARG}";;
o)
zipfilename="${OPTARG}";;
r)
if [ ${in_filter_context} -eq 1 ]
then
filter_definition="${filter_definition}\n</filter>"
fi
in_filter_context=1
_add_filter "${OPTARG}";;
i)
if [ ${in_filter_context} -eq 0 ]
then
echo "Include pattern (-i) should be nested in scope of" \
"filter root path (-r)." >&2
echo "Please add -r JCRPATH before adding -i/-e options." >&2
exit 1;
fi
_add_include_entry "${OPTARG}";;
e)
if [ ${in_filter_context} -eq 0 ]
then
echo "Exclude pattern (-e) should be nested in scope of" \
"filter root path (-r)." >&2
echo "Please add -r JCRPATH before adding -i/-e options." >&2
exit 1;
fi
_add_exclude_entry "${OPTARG}";;
\?)
echo "Invalid option: -${OPTARG}" >&2; _usage;;
:)
echo "Option -${OPTARG} requires an argument." >&2; _usage;;
esac
done
shift $((OPTIND-1))
if [ ${#} -ne 1 ]
then
_usage
fi
group_entry=$(cat <<EOT
<entry key="group">${group}</entry>
EOT
)
name=${1}
dir=$(pwd)
if [ -z "${zipfilename}" ]
then
zipfile="${dir}/${name}-${version}.zip"
else
zipfile=$(cd $(dirname "${zipfilename}"); \
pwd)/$(basename "${zipfilename}")
fi
filter_definition=$(cat <<EOT
${filter_definition}
</filter>
</workspaceFilter>
EOT
)
package_definition=$(cat <<EOT
${package_definition}
${group_entry}
<entry key="name">${name}</entry>
<entry key="version">${version}</entry>
<entry key="description">${description}</entry>
</properties>
EOT
)
ZIP=$(which zip)
if [ ${?} -ne 0 -o "${ZIP}" = "" ]
then
echo "Cannot find zip packaging command-line tool. Aborted" >&2
exit 2
fi
tempdir=$(mktemp -d cqpkgXXXXXXXXXX)
exitcode=${?}
if [ ${exitcode} -ne 0 ]
then
echo "Cannot create temporary directory ${tempdir}. Aborted" >&2
exit 1
fi
vault="${tempdir}/META-INF/vault"
mkdir -p "${tempdir}/jcr_root"
mkdir -p "${vault}"
printf "%s" "${filter_definition}" > "${vault}/filter.xml"
printf "%s" "${package_definition}" > "${vault}/properties.xml"
cd "${tempdir}"
"${ZIP}" -q -r - ./ > "${zipfile}"
exitcode=${?}
cd "${dir}"
if [ ${exitcode} -ne 0 ]
then
echo "Cannot create zip package properly." >&2
fi
rm "${vault}/filter.xml"
rm "${vault}/properties.xml"
rmdir "${tempdir}/jcr_root"
rmdir "${tempdir}/META-INF/vault"
rmdir "${tempdir}/META-INF"
rmdir "${tempdir}"
if [ ${exitcode} -eq 0 ]
then
echo "Empty package created: '${zipfile}'"
else
exit 3
fi