-
Notifications
You must be signed in to change notification settings - Fork 23
/
cqchk
executable file
·144 lines (129 loc) · 4.13 KB
/
cqchk
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
#!/bin/sh
# CQ Unix Toolkit
# Copyright (C) 2021 Wunderman Thompson Technology
#
# 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}") [OPTION...]
Invoke CRX repository check and fix on them. By default fixes are not performed.
Read-only access to repositorys is used unless -f option is provided.
Examples:
cqchk -u admin -f # Check repository and fix error automatically
cqchk -i http://localhost:5510 # Check repository for localhost instance on
# on tcp port 5510 without fixing anything
cqchk -p secret # Check reposiotry without fixing anything
# provided login password: secret
Options:
-u use specified username for connection
-p use provided password for authentication
-i use specified instance URL to connect
-f force fixing erros when possible
EOT
exit 1
}
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
CURLBIN=$("${API}" -c)
if [ ${?} -ne 0 ]; then
echo "Fatal: cannot find curl" >&2
exit 1
fi
# API common options
cmdapi=$("${API}" -P "${@}")
username=$(echo "${cmdapi}" | cut -f1)
password=$(echo "${cmdapi}" | cut -f2)
instance=$(echo "${cmdapi}" | cut -f3)
passed=$(echo "${cmdapi}" | cut -f4)
apigetopts=$(echo "${cmdapi}" | cut -f5)
# Custom arguments
fix=false
while getopts ":f${apigetopts}" opt; do
case "${opt}" in
f)
fix=true
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
_usage
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
_usage
;;
esac
done
shift $((OPTIND - 1))
if [ ${#} -ge 1 -o "${passed}" -eq 0 ]; then
_usage
fi
ECHON=$(which echo)
[ ${?} -ne 0 -o -z "${ECHON}" ] && ECHON="echo" || ECHON="${ECHON} -n "
${ECHON} "Starting repository traversal check..."
REFERER="${instance}/system/console/jmx/com.adobe.granite%3Atype%3DRepository"
AUTH="${username}:${password}"
FILEPATH="/system/console/jmx/com.adobe.granite%3Atype%3DRepository/op/traversa\
lCheck/java.lang.String%2Cjava.lang.Boolean%2Cjava.lang.Boolean"
REFERERHEADER="Referer: ${REFERER}"
STATUS=$(${CURLBIN} \
-s \
--write-out "%{http_code}" \
-u "${AUTH}" \
-H "${REFERERHEADER}" \
-X POST --data "logEach=false&fixInconsistencies=${fix}" \
"${instance}${FILEPATH}")
EXITCODE=${?}
"${API}" -C ${EXITCODE}
if [ ${EXITCODE} -ne 0 ]; then
echo "Cannot invoke repository traversal check." >&2
exit ${EXITCODE}
fi
STATUSCODE=$(echo "${STATUS}" | tail -n 1)
STATUS=$(echo "${STATUS}" | sed '$d;')
echo "${STATUS}"
"${API}" -H "${STATUSCODE}"
EXITCODE2=${?}
if [ ${EXITCODE2} -ne 0 ]; then
echo "Cannot invoke repository traversal check." >&2
exit ${EXITCODE2}
fi
${ECHON} "Starting repository consistency check..."
FILEPATH="/system/console/jmx/com.adobe.granite%3Atype%3DRepository/op/consiste\
ncyCheck/java.lang.String%2Cjava.lang.Boolean"
STATUS=$(${CURLBIN} \
-s \
--write-out "%{http_code}" \
-u "${AUTH}" \
-H "${REFERERHEADER}" \
-X POST --data "fixInconsistencies=${fix}" \
"${instance}${FILEPATH}")
EXITCODE=${?}
"${API}" -C ${EXITCODE}
if [ ${EXITCODE} -ne 0 ]; then
echo "Cannot invoke repository consistency check." >&2
exit ${EXITCODE}
fi
STATUSCODE=$(echo "${STATUS}" | tail -n 1)
STATUS=$(echo "${STATUS}" | sed '$d;')
echo "${STATUS}"
"${API}" -H "${STATUSCODE}"
EXITCODE2=${?}
if [ ${EXITCODE2} -ne 0 ]; then
echo "Cannot invoke repository consistency check." >&2
exit ${EXITCODE2}
fi