Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e65ac9d

Browse files
author
Hashim Khan
committed
Added the Script to Migrate Users and Groups from one environment to another.
1 parent ef1a14d commit e65ac9d

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

‎userMigration.sh‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
3+
CREDS='admin:admin'
4+
HOST=localhost
5+
PORT=4502
6+
7+
QUERYURL=/bin/querybuilder.json
8+
DATE=$(date +%Y%m%d%H%M%S)
9+
PACKAGENAMEUSERS="users-${DATE}"
10+
PACKAGENAMEGROUPS="groups-${DATE}"
11+
PARAMSUSERS='path=/home/users&property=jcr%3aprimaryType&property.value=rep%3aUser&p.limit=-1&p.hits=full'
12+
PARAMSGROUP='path=/home/groups&property=jcr%3aprimaryType&property.value=rep%3aGroup&p.limit=-1&p.hits=full'
13+
14+
usage ()
15+
{
16+
echo "Usage: add type of Package you want to Export : user or group"
17+
echo "e.g : ./userMigration user"
18+
exit
19+
}
20+
21+
statusCheck ()
22+
{
23+
if [[ "2ドル" != "true" ]];then
24+
echo "1ドル : Incorrect Curl command or Parameters . Please verify."
25+
exit
26+
fi
27+
}
28+
29+
#Method to Grab the List of Users in the AEM instance.
30+
listUsers ()
31+
{
32+
echo "Getting List of Users:"
33+
OUTPUT=$(curl --write-out -s -u ${CREDS} "http://${HOST}:${PORT}${QUERYURL}?${PARAMSUSERS}")
34+
35+
STATUS=$(jq '.success' <<< "${OUTPUT}")
36+
statusCheck "ListUsers" ${STATUS}
37+
addFilters "${OUTPUT}" 1ドル
38+
39+
}
40+
41+
#Method to Grab the List of Groups in the AEM instance.
42+
listGroups ()
43+
{
44+
echo "Getting List of Groups:"
45+
OUTPUT=$(curl --write-out -s -u ${CREDS} "http://${HOST}:${PORT}${QUERYURL}?${PARAMSGROUP}")
46+
47+
STATUS=$(jq '.success' <<< "${OUTPUT}")
48+
statusCheck "ListGroups" ${STATUS}
49+
addFilters "${OUTPUT}" 1ドル
50+
51+
}
52+
53+
# Method to Create a package with the Given PackageName and Date Stamp.
54+
createPackage ()
55+
{
56+
echo "Creating Package:"
57+
OUTPUT=$(curl --write-out -s -u ${CREDS} \
58+
"http://${HOST}:${PORT}/crx/packmgr/service/.json/etc/packages/users/1ドル.zip?cmd=create" \
59+
-d packageName=1ドル \
60+
-d groupName=users)
61+
62+
63+
STATUS=$(jq '.success' <<< "${OUTPUT}")
64+
statusCheck "Create" ${STATUS}
65+
66+
67+
}
68+
69+
# Method to add Filters to the created package.
70+
addFilters ()
71+
{
72+
OUTPUT=1ドル | jq .
73+
RESULTS=$(jq '.results' <<< ${OUTPUT})
74+
STATUS=$(jq '.success' <<< ${OUTPUT})
75+
USERPATHS=$(jq '.hits[]."jcr:path"' <<< ${OUTPUT} | sed 's/"//g' )
76+
USERNAMES=$(jq '.hits[]."rep:principalName"' <<< ${OUTPUT} | sed 's/"//g' )
77+
ARRAYUSERPATHS=( $USERPATHS )
78+
ARRAYUSERNAMES=( $USERNAMES )
79+
80+
FILTER="["
81+
for ((i=0; i<${RESULTS}; i++)); do
82+
FILTER="${FILTER}{\"root\":\"${ARRAYUSERPATHS[${i}]}\", \"rules\":[{\"modifier\":\"exclude\",\"pattern\":\"${ARRAYUSERNAMES[${i}]}/.tokens\"}]}, "
83+
done
84+
FILTER="${FILTER:0:${#FILTER}-2}]"
85+
86+
echo "Add Filter to Package"
87+
OUTPUT=$(curl --write-out -s -u ${CREDS} \
88+
"http://${HOST}:${PORT}/crx/packmgr/update.jsp" \
89+
-F "path=/etc/packages/users/2ドル.zip" \
90+
-F "packageName=2ドル" \
91+
-F "groupName=users" \
92+
-F "_charset_=UTF-8" \
93+
-F "filter=${FILTER}")
94+
95+
STATUS=$(jq '.success' <<< "${OUTPUT}")
96+
statusCheck "Filter" ${STATUS}
97+
98+
}
99+
100+
# Method to build a package created above.
101+
buildPackage ()
102+
{
103+
echo "Build Package:"
104+
OUTPUT=$(curl --write-out -s -u ${CREDS} -X POST \
105+
"http://${HOST}:${PORT}/crx/packmgr/service/.json/etc/packages/users/1ドル.zip?cmd=build")
106+
107+
STATUS=$(jq '.success' <<< "${OUTPUT}")
108+
statusCheck "Build" ${STATUS}
109+
110+
}
111+
112+
# Perform the actions
113+
if [ "1ドル" = "user" ]; then
114+
createPackage ${PACKAGENAMEUSERS}
115+
listUsers ${PACKAGENAMEUSERS}
116+
buildPackage ${PACKAGENAMEUSERS}
117+
elif [ "1ドル" = "group" ] ; then
118+
119+
createPackage ${PACKAGENAMEGROUPS}
120+
listGroups ${PACKAGENAMEGROUPS}
121+
buildPackage ${PACKAGENAMEGROUPS}
122+
else
123+
usage
124+
fi

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /