forked from radanalyticsio/openshift-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-yaml.sh
executable file
·80 lines (63 loc) · 2.22 KB
/
change-yaml.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
#!/bin/bash
function usage() {
echo
echo "Changes the image.*.yaml file and adds it to the current commit (git add)"
echo
echo "Usage: change-yaml.sh [options] SPARK_VERSION"
echo
echo "required arguments"
echo
echo " SPARK_VERSION The spark version number, like 2.2.1"
echo
echo "optional arguments:"
echo
echo " -h Show this message"
}
# Set the hadoop version
HVER=2.7
while getopts h opt; do
case $opt in
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))"
if [ "$#" -lt 1 ]; then
echo No spark version specified
usage
exit 1
fi
SPARK=$1
# Extract the current spark version from the image.yaml file
# Works by parsing the line following "name: sparkversion"
VER=$(sed -n '\@name: sparkversion@!b;n;p' image.yaml | tr -d '[:space:]' | cut -d':' -f2)
if [ "$VER" == "$SPARK" ]; then
echo "Nothing to do, spark version in image.yaml is already $SPARK"
exit 0
fi
# Change spark distro and download urls
if [ ! -z ${SPARK+x} ]; then
wget https://archive.apache.org/dist/spark/spark-${SPARK}/spark-${SPARK}-bin-hadoop${HVER}.tgz.md5 -O /tmp/spark-${SPARK}-bin-hadoop${HVER}.tgz.md5
if [ "$?" -eq 0 ]; then
sum=$(cat /tmp/spark-${SPARK}-bin-hadoop2.7.tgz.md5 | cut -d':' -f 2 | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')
# Fix the url references
sed -i "s@https://archive.apache.org/dist/spark/spark-.*/spark-.*-bin-@https://archive.apache.org/dist/spark/spark-${SPARK}/spark-${SPARK}-bin-@" image.yaml
# Fix the md5 sum references on the line following the url
sed -i '\@url: https://archive.apache.org/dist/spark/@!b;n;s/md5.*/md5: '$sum'/' image.yaml
# Fix the spark version label
sed -i '\@name: sparkversion@!b;n;s/value.*/value: '$SPARK'/' image.yaml
# Fix the concreate version value
V=$(echo $SPARK | cut -d'.' -f1,2)
sed -i 's@^version:.*-latest$@version: '$V'-latest@' image.yaml
else
echo "Failed to get the md5 sum for the specified spark version, the version $SPARK may not be a real version"
exit 1
fi
fi
git add image.yaml