-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathlibrary-sync.sh
executable file
·147 lines (137 loc) · 3.24 KB
/
library-sync.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
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
function print_help {
echo 'Usage: library-sync.sh [--okd][--ocp][--ocp-all][--help]'
echo
echo 'A simple tool to sync the samples from openshift/library to assets of the Samples Operator'
echo 'The default behavior (without any commandline arguments) is to update the OCP samples,'
echo 'that is as if "--ocp" was specified.'
echo
echo 'Comandline arguments:'
echo '--okd the OKD samples are updated'
echo '--ocp the OCP supported samples are updated'
echo '--ocp-all all OCP samples are updated including the unsupported ones'
echo '--help shows this help message and exits'
}
###########################################
# process the commandline args
PROCESS_OKD="false"
PROCESS_ALL_OCP_SAMPLES="false"
if [[ $# -eq 0 ]]; then
PROCESS_OCP="true"
else
PROCESS_OCP="false"
fi
while [[ $# -gt 0 ]]; do
case $1 in
--okd)
PROCESS_OKD="true"
;;
--ocp)
PROCESS_OCP="true"
;;
--ocp-all)
PROCESS_OCP="true"
PROCESS_ALL_OCP_SAMPLES="true"
;;
--help | -h)
print_help && exit 0
;;
esac
shift
done
# set up variables
OCP_SUPPORTED_SAMPLES="ruby python nodejs perl php httpd nginx eap java webserver dotnet golang rails"
OCP_ARCHS="ocp-x86_64 ocp-aarch64 ocp-ppc64le ocp-s390x"
OKD_ARCHS="okd-x86_64"
ALL_ARCHS="$OCP_ARCHS $OKD_ARCHS"
if $PROCESS_OKD; then
if $PROCESS_OCP; then
PROCESSED_ARCHS=$ALL_ARCHS
else
PROCESSED_ARCHS=$OKD_ARCHS
fi
else
PROCESSED_ARCHS=$OCP_ARCHS
fi
# helper functions
function reset_directory() {
git checkout HEAD -- "$1"
# remove any changes from the working tree in this directory that checkout left behind
git stash -a -- "$1"
git stash drop
}
function reset_ocp_unsupported() {
for d in $(ls); do
if [[ "${OCP_SUPPORTED_SAMPLES}" != *"${d}"* ]]; then
reset_directory "${d}"
fi
done
}
# process the openshift library
pushd assets
wget https://github.com/openshift/library/archive/master.zip -O library.zip
unzip library.zip
rm library.zip
pushd library-master
rm -rf api arch cmd community* .git* hack official* vendor Dockerfile LICENSE Makefile OWNERS README.md go.* main.go
pushd operator
pushd ocp-x86_64
pushd official
mv * ..
popd # official
rmdir official
popd # ocp-x86_64
pushd ocp-aarch64
pushd official
mv * ..
popd # official
rmdir official
popd #ocp-aarch64
pushd ocp-ppc64le
pushd official
mv * ..
popd # official
rmdir official
popd #ocp-ppc64le
pushd ocp-s390x
pushd official
mv * ..
popd # official
rmdir official
popd #ocp-s390x
pushd okd-x86_64
pushd community
mv * ..
popd # community
rmdir community
pushd official
cp -r * ..
popd # official
rm -rf official
popd #okd-x86_64
popd # operator
tar cvf ../t.tar operator
popd # library-master
git rm -r operator
tar xvf t.tar
git add operator
rm t.tar
rm -rf library-master
pushd operator
for arch in $ALL_ARCHS; do
if [[ "${PROCESSED_ARCHS}" == *"${arch}"* ]]; then
# There are no unsupported samples in OKD, but we need
# to reset the unsupported samples in OCP.
if ! ${PROCESS_ALL_OCP_SAMPLES}; then
if [[ "${OCP_ARCHS}" == *"${arch}"* ]]; then
pushd "${arch}"
reset_ocp_unsupported
popd # $arch
fi
fi
else
# we're not supposed to update this arch.
reset_directory "${arch}"
fi
done
popd # operator