This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathvendor-openshift.sh
executable file
·113 lines (82 loc) · 3.88 KB
/
vendor-openshift.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
#!/bin/bash
# 'glide update -v' has to be run before running this script.
# If you do 'glide update' after running this scripts, glide is going to ovewrite all changes.
# This adds OpenShift and all packages that are vendored by OpenShift
# to project vendor directory. It has to be run from root directory of the project
# (where vendor directory is).
# For more information why we are doing this see comments glide.yaml
OPENSHIFT_REPO="https://github.com/openshift/origin"
OPENSHIFT_VERSION="v3.7.0"
PROJECT_VENDOR="./vendor"
TMP_OPENSHIFT=`mktemp -d`
echo "Cloning OpenShift $OPENSHIFT_VERSION"
git clone --branch $OPENSHIFT_VERSION --depth 1 $OPENSHIFT_REPO $TMP_OPENSHIFT
# How deep is the package in directory structure?
# example: package hosted in github.com has three level strucure (github.com/<namespace>/<pkgname>)
# packages in k8s.io has only two level strucutre (k8s.io/<pkgname>)
# we need to know where it is so we can move whole package (nothing more nothing less)
#
# If we were to move whole github.com than whole github.com gets replaced in target directory,
# and if target directory had some extra libs from gihtub.com that are not in openshift vendor
# they would get removed.
TWO_LEVEL="cloud.google.com go.pedge.io go4.org google.golang.org gopkg.in k8s.io vbom.ml"
THREE_LEVEL="bitbucket.org github.com golang.org"
function movePKG {
# This function moves package from OpenShift vendor to this project vendor
# Takes one positional argument - package name (github.com/foo/bar)
pkg=$1
target="$PROJECT_VENDOR/$pkg"
target_parent=`dirname $target`
rm -rf $target
mkdir -p $target_parent
echo "Moving $pkg from OpenShift vendor to this project vendor directory"
mv -f $TMP_OPENSHIFT/vendor/$pkg $target_parent
}
# check if we cover everything from openshift vendor
# every domain in OpenShift vendor has to be covered in lists above (to define if its 2 or 3 level structure)
for path in `find $TMP_OPENSHIFT/vendor -maxdepth 1 -mindepth 1 -type d | sort`; do
domain=`basename $path`
found=false
for t in $TWO_LEVEL $THREE_LEVEL; do
if [ "$t" == "$domain" ]; then
found=true
fi
done
if [ $found == false ]; then
echo "ERROR: structure for $domain is not defined"
exit 1
fi
done
# move packages from OpenShifts vendor dir to project vendor dir
# for every package that is organized in two level directory strucure
for domain in $TWO_LEVEL; do
# on Linux you can use just find with `-printf "$domain/%P\n"` instead of awk, but this is not available on MacOS
pkgs=`find -L "${TMP_OPENSHIFT}/vendor/$domain" -maxdepth 1 -mindepth 1 -type d | awk -F/ '{ print($(NF-1)"/"$(NF)) }'`
for pkg in $pkgs; do
movePKG $pkg
done
done
# for every package that is organized in three level directory strucure
for domain in $THREE_LEVEL; do
# on Linux you can use just find with `-printf "$domain/%P\n"` instead of awk, but this is not available on MacOS
pkgs=`find -L "${TMP_OPENSHIFT}/vendor/$domain" -maxdepth 2 -mindepth 2 -type d | awk -F/ '{ print($(NF-2)"/"$(NF-1)"/"$(NF)) }'`
for pkg in $pkgs; do
movePKG $pkg
done
done
# OpenShift vendor directory shouldn't contain any *.go files, they should be all moved to project vendor directory
remaining_go_files=`find ${TMP_OPENSHIFT}/vendor -type f -name *.go`
if [[ "`$remaining_go_files | wc -l`" -ne 0 ]]; then
echo `echo $remaining_go_files| wc -l`
echo "ERROR: There *.go files remaining in OpenShift vendor directory"
echo $remaining_go_files
exit 1
fi
# clean up openshift
rm -rf $TMP_OPENSHIFT/vendor $TMP_OPENSHIFT/.git
# now move OpenShift itself to project vendor
echo "Moving OpenShift to project vendor directory"
rm -rf $PROJECT_VENDOR/github.com/openshift/origin
mkdir -p $PROJECT_VENDOR/github.com/openshift/
mv $TMP_OPENSHIFT $PROJECT_VENDOR/github.com/openshift/origin
echo "DONE."