-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdependency_checker
249 lines (205 loc) · 10 KB
/
dependency_checker
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
## Downloads MDB install packages appropriate for the platform
## running this script, and determines dependencies required,
## filtering out deps that can be safely assumed to be present
## on all systems (i.e. glibc).
## General usage:
##
## 1. Set TESTING to 0 for mainline versions, or 1 for
## release candidates in the 'testing' branch.
## 2. Update the 8 bash arrays for MDB vers, platforms,
## and distro versions as needed.
## 3. Run script on a DEB-based system to check all
## specified MDB DEB files for dependencies, and/or:
## 4. Run script on an RPM-based system to check all
## specified MDB RPM files for dependencies.
############################################################
## YOUR VALUES ##
#################
# Set to 1 if testing unreleased RC candidates, like 4.4.0~rc7
# Set to 0 to use mainline versioning, like 4.2.7
TESTING=1
## Provide bash arrays of what to download / check for.
## Separate multiple values with a single space.
## MongoDB versions to download. Must be full release version. Should be latest:
#MDB_VERS=(4.4.0~rc7) # DEB versioning for RCs, apparently
MDB_VERS=(4.4.0-0.1.rc7) # RPM versioning for RCs, apparently
#MDB_VERS=(4.2.2 4.0.14 3.6.16)
## RPM-based platforms to check:
RPM_PLATFORMS=(redhat amazon suse)
## DEB-based platforms to check:
DEB_PLATFORMS=(debian ubuntu)
## RHEL versions to check:
RHEL_VERS=(6 7 8)
## Amazon Linux versions to check. Must use 2013.03 intead of "1":
AMZN_VERS=(2)
## Debian versions to check. Must use codenames:
DEBIAN_VERS=(buster stretch)
## Ubuntu versions to check. Must use codenames:
UBUNTU_VERS=(focal bionic xenial)
## SUSE versions to check:
SUSE_VERS=(12 15)
############################################################
## BEGIN SCRIPT ##
##################
TMPSPACE=/tmp/dependency_tester$$
mkdir $TMPSPACE
CURRENTDIR=`pwd`
cd $TMPSPACE
## Detect platform:
PLATFORM=`hostnamectl | grep Operating | awk -F":" '{print $2}'`
## Determine package type to use, based on platform:
if [ `echo $PLATFORM | egrep -ic '(centos|redhat|amazon|suse)'` -gt 0 ]; then
PKG_TYPE="rpm"
elif [ `echo $PLATFORM | egrep -ic '(ubuntu|debian)'` -gt 0 ]; then
PKG_TYPE="deb"
else
echo "ERROR: Unable to determine platform type (rpm or deb)! (??)"
exit;
fi
## Check for curl:
if [ `command -v curl | grep -ic curl` -ne 1 ]; then
echo "Please install curl to use this program"
echo "Exiting ..."
exit;
fi
## For each edition, build out URLS that we'll be using to download and check.
## A series of for loops generates the unique URLs for both MDB editions for
## all supported platforms that use the same package format (RMP or DEB) as
## the system running this script.
## Loop twice, once per edition:
for EDITION_SWITCH in `seq 0 1`; do
if [ $EDITION_SWITCH -eq 0 ]; then
EDITION="Community"
URL_BASE="https://repo.mongodb.org"
EDITION_NAME="mongodb-org"
else
EDITION="Enterprise"
URL_BASE="https://repo.mongodb.com"
EDITION_NAME="mongodb-enterprise"
fi
## If we are running on an RPM-based distro, check all RPMs
if [ $PKG_TYPE == "rpm" ]; then
## Loop per supported RPM Platform:
for PLATFORM_NAME in "${RPM_PLATFORMS[@]}"; do
if [ $PLATFORM_NAME == "redhat" ]; then
PKG_MGR="yum"
BUILD="el"
PLATFORM_VERS=("${RHEL_VERS[@]}")
elif [ $PLATFORM_NAME == "amazon" ]; then
PKG_MGR="yum"
BUILD="amzn"
PLATFORM_VERS=("${AMZN_VERS[@]}")
elif [ $PLATFORM_NAME == "suse" ]; then
PKG_MGR="zypper"
BUILD="suse"
PLATFORM_VERS=("${SUSE_VERS[@]}")
fi
## Loop per supported version of that platform:
for PLATFORM_VER in "${PLATFORM_VERS[@]}"; do
## Loop per MongoDB version:
for MDB_VER in "${MDB_VERS[@]}"; do
## Determine MongoDB branch from provided version (i.e. 4.2 from 4.2.2),
## or use 'testing' if $TESTING is set:
if [ $TESTING ]; then
MDB_BRANCH="testing"
else
MDB_BRANCH=`echo $MDB_VER | egrep -m 1 -o '^[0-9]\.[0-9]{1,2}'`
fi
## Assemble URL from all the components we've assembled thus far,
## ... but AMZN just has to be different
## ... and apparently the 'testing' branch also uses its own versioning:
if [ $TESTING ]; then
URL="$URL_BASE/$PKG_MGR/$PLATFORM_NAME/$PLATFORM_VER/$EDITION_NAME/$MDB_BRANCH/x86_64/RPMS/$EDITION_NAME-server-"$MDB_VER".$BUILD$PLATFORM_VER.x86_64.$PKG_TYPE"
elif [[ $PLATFORM_NAME == "amazon" && $PLATFORM_VER == "2013.03" ]]; then
URL="$URL_BASE/$PKG_MGR/$PLATFORM_NAME/$PLATFORM_VER/$EDITION_NAME/$MDB_BRANCH/x86_64/RPMS/$EDITION_NAME-server-"$MDB_VER"-1.amzn1.x86_64.$PKG_TYPE"
else
URL="$URL_BASE/$PKG_MGR/$PLATFORM_NAME/$PLATFORM_VER/$EDITION_NAME/$MDB_BRANCH/x86_64/RPMS/$EDITION_NAME-server-"$MDB_VER"-1.$BUILD$PLATFORM_VER.x86_64.$PKG_TYPE"
fi
## Check to make sure a PKG exists for the given version / platform combination:
STATUS=`curl -s -I $URL | head -n 1 | cut -d$' ' -f2`
if [ ! $STATUS == "200" ]; then
echo -e "\nNo $PKG_TYPE available for MongoDB $MDB_VER $EDITION Edition on $PLATFORM_NAME $PLATFORM_VER"
echo "Skipping ..."
else
echo -e "\nDownloading $PKG_TYPE for MongoDB $MDB_VER $EDITION Edition on $PLATFORM_NAME $PLATFORM_VER"
curl -O -# $URL
FILENAME=`echo $URL | sed s%^.*RPMS/%%g`
## List all dependencies, remove shells, tzdata,
## rpm tools, and MDB deps, and write to file
## for later processing:
rpm -qpR $FILENAME | egrep -v '(/bin/sh|/bin/bash|tzdata|timezone|rpmlib|librpm|python|mongodb)' > $TMPSPACE/$FILENAME.deplist
## Set bash field separator to newline:
IFS=$'\n'
## Loop over each dep in the deplist file.
## If a package is part of the GCC or GLIBC
## packages, add them to an exlude list for later:
for line in `cat $TMPSPACE/$FILENAME.deplist`; do
if [ `echo $line | egrep -ic '(GLIBC|GCC|GNU_HASH)'` -gt 0 ]; then
FOUND_PKG=`echo $line | cut -d'(' -f1`
echo $FOUND_PKG >> $TMPSPACE/$FILENAME.excludelist
fi
done
## Print dependencies minus excludelist:
grep -v -f $TMPSPACE/$FILENAME.excludelist $TMPSPACE/$FILENAME.deplist
## Cleanup:
rm -f $TMPSPACE/$FILENAME.deplist
rm -f $TMPSPACE/$FILENAME.excludelist
## NOTE: If running this directly on the same platform
## as RPM was built for (i.e. run on RHEL8 to check RHEL8 RPMs),
## the following would be better, as it provides the upstream
## packages that would satisfy the listed dependencies as well:
## yum deplist $FILENAME | grep provider | awk -F":" '{print $2}' | sort -u
## Clean up RPM:
rm -f $FILENAME
fi
done
done
done
## If we are running on a DEB-based distro, check all DEBs
elif [ $PKG_TYPE == "deb" ]; then
## Loop per supported DEB Platform:
for PLATFORM_NAME in "${DEB_PLATFORMS[@]}"; do
if [ $PLATFORM_NAME == "debian" ]; then
PKG_MGR="apt"
RELEASE="main"
PLATFORM_VERS=("${DEBIAN_VERS[@]}")
elif [ $PLATFORM_NAME == "ubuntu" ]; then
PKG_MGR="apt"
RELEASE="multiverse"
PLATFORM_VERS=("${UBUNTU_VERS[@]}")
fi
## Loop per supported version of that platform:
for PLATFORM_VER in "${PLATFORM_VERS[@]}"; do
## Loop per MongoDB version:
for MDB_VER in "${MDB_VERS[@]}"; do
## Determine MongoDB branch from provided version (i.e. 4.2 from 4.2.2),
## or use 'testing' if $TESTING is set:
if [ $TESTING ]; then
MDB_BRANCH="testing"
else
MDB_BRANCH=`echo $MDB_VER | egrep -m 1 -o '^[0-9]\.[0-9]{1,2}'`
fi
## Assemble URL from all the components we've assembled thus far:
URL="$URL_BASE/$PKG_MGR/$PLATFORM_NAME/dists/$PLATFORM_VER/$EDITION_NAME/$MDB_BRANCH/$RELEASE/binary-amd64/$EDITION_NAME-server_"$MDB_VER"_amd64.$PKG_TYPE"
## Check to make sure a PKG exists for the given version / platform combination:
STATUS=`curl -s -I $URL | head -n 1 | cut -d$' ' -f2`
if [ ! $STATUS == "200" ]; then
echo -e "\nNo $PKG_TYPE available for MongoDB $MDB_VER $EDITION Edition on $PLATFORM_NAME $PLATFORM_VER"
echo "Skipping ..."
else
echo -e "\nDownloading $PKG_TYPE for MongoDB $MDB_VER $EDITION Edition on $PLATFORM_NAME $PLATFORM_VER"
curl -O -# $URL
FILENAME=`echo $URL | sed s%^.*binary-amd64/%%g`
## List dependencies, skipping GCC/GLIBC and built-ins:
dpkg -I $FILENAME | grep Depends | sed 's%Depends: %%g' | sed 's%,%\n%g' | egrep -v '(adduser|tzdata|libc6|libgcc1|libgcc-s1)'
## Clean up DEB:
rm -f $FILENAME
fi
done
done
done
fi
done
cd $CURRENTDIR
rm -rf $TMPSPACE