-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync_and_migrate.sh
executable file
·137 lines (129 loc) · 4.4 KB
/
sync_and_migrate.sh
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
#!/bin/bash
PROBLEM_NAMES=(\
grafana \
centos-ops \
mysql \
sles12-backport-sp5-standard \
sles12-backport-sp5-product \
sles12-backport-sp4-standard \
sles12-backport-sp4-product \
sles12-update-sp5 \
sles12-debug-update-sp5 \
)
PROBLEM_URLS=(\
https://packages.grafana.com/oss/rpm \
http://ftp.cs.stanford.edu/centos/7/opstools/x86_64/ \
http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/ \
https://updates.suse.com/SUSE/Backports/SLE-12-SP5_x86_64/standard/ \
https://updates.suse.com/SUSE/Backports/SLE-12-SP5_x86_64/product/ \
https://updates.suse.com/SUSE/Backports/SLE-12-SP4_x86_64/standard/ \
https://updates.suse.com/SUSE/Backports/SLE-12-SP4_x86_64/product/ \
https://updates.suse.com/SUSE/Updates/SLE-SERVER/12-SP5/x86_64/update/ \
https://updates.suse.com/SUSE/Updates/SLE-SERVER/12-SP5/x86_64/update_debug/ \
)
# SUSE_TOKENS is assumed to be a string which is an ordered list of repo-auth-tokens matching the
# URLs above. Fill from your own account-access. For non-SUSE-repos, use "NULL"
SUSE_TOKENS=($SUSE_TOKEN_STR)
echo TOKENS : ${SUSE_TOKENS[@]}
export PULP2_AUTH=`python -c 'import base64; print(base64.encodestring("admin:admin".encode())[:-1].decode())'`
cleanup=""
p2setup=""
migrate="yes"
resync="yes"
mirror="yes"
pulp-admin login -u admin -p admin
# cleanup
if [ -n "$cleanup" ]; then
echo ">>> REPO/REMOTE CLEANUP"
for i in ${!PROBLEM_NAMES[@]}
do
if [ $i -gt 2 ]
then
continue
fi
echo clean ${PROBLEM_NAMES[$i]}
REMOTE_HREF=$(pulp rpm repository show --name ${PROBLEM_NAMES[$i]} | jq -r .remote)
pulp rpm remote destroy --href ${REMOTE_HREF}
pulp rpm repository destroy --name ${PROBLEM_NAMES[$i]}
pulp-admin rpm repo delete --repo-id ${PROBLEM_NAMES[$i]}
done
echo ">> ORPHAN CLEANUP"
pulp orphans delete | jq .pulp_href
pulp-admin orphan remove --all
fi
if [ -n "$p2setup" ]; then
# setup and sync into pulp2
echo ">>> SYNC"
for i in ${!PROBLEM_NAMES[@]}
do
if [ $i -gt 2 ]
then
continue
fi
echo ${PROBLEM_NAMES[$i]} : ${PROBLEM_URLS[$i]}
echo Token : ${SUSE_TOKENS[$i]}
pulp-admin rpm repo create --repo-id ${PROBLEM_NAMES[$i]} \
--feed ${PROBLEM_URLS[$i]} --download-policy immediate
if [[ "NULL" != ${SUSE_TOKENS[$i]} ]]
then
CONFIG="{\"query_auth_token\": \"${SUSE_TOKENS[$i]}\" }"
echo Config : ${CONFIG}
http --verify no --auth admin:admin \
PUT https://localhost/pulp/api/v2/repositories/${PROBLEM_NAMES[$i]}/ \
importer_config:="${CONFIG}"
fi
pulp-admin rpm repo sync run --repo-id ${PROBLEM_NAMES[$i]}
TASKS_OUTPUT=""
echo -n "Waiting on sync "
while [ -z "${TASKS_OUTPUT}" ]; do
TASKS_OUTPUT=$(pulp-admin tasks list | grep "No tasks found")
echo -n "."; sleep 5
done
echo -e "\n\n"
done
fi
if [ -n "$migrate" ]; then
# 2to3 migration
echo "MIGRATING"
PLAN_HREF=$(pulp migration plan create --plan '{"plugins": [{"type": "rpm"}]}' | jq -r .pulp_href)
echo "Plan: $PLAN_HREF"
pulp migration plan run --href ${PLAN_HREF}
# The plan's child-tasks can take some time to complete after the plan declares itself done...
echo WAITING...
sleep 180
fi
if [ -n "$resync" ]; then
# sync in pulp3
echo ">>> SYNC AUTOPUBLISH"
for i in ${!PROBLEM_NAMES[@]}
do
if [ $i -gt 2 ]
then
continue
fi
echo ${PROBLEM_NAMES[$i]} : ${PROBLEM_URLS[$i]}
echo Token : ${SUSE_TOKENS[$i]}
REMOTE_HREF=$(pulp rpm repository show --name ${PROBLEM_NAMES[$i]} | jq -r .remote)
echo "Remote-href: ${REMOTE_HREF}"
pulp rpm repository sync --name ${PROBLEM_NAMES[$i]}
echo -e "\n\n"
done
fi
if [ -n "$mirror" ]; then
# sync in pulp3
echo ">>> SYNC MIRROR"
for i in ${!PROBLEM_NAMES[@]}
do
if [ $i -gt 2 ]
then
continue
fi
echo ${PROBLEM_NAMES[$i]} : ${PROBLEM_URLS[$i]}
echo Token : ${SUSE_TOKENS[$i]}
REMOTE_HREF=$(pulp rpm repository show --name ${PROBLEM_NAMES[$i]} | jq -r .remote)
echo "Remote-href: ${REMOTE_HREF}"
pulp rpm repository update --name ${PROBLEM_NAMES[$i]} --no-autopublish
pulp rpm repository sync --name ${PROBLEM_NAMES[$i]} --mirror
echo -e "\n\n"
done
fi