This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·57 lines (49 loc) · 2.56 KB
/
generate.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
#!/usr/bin/env sh
###
# Generate teamplates that make Hadoop configurable via environment variables.
###
generate() {
echo "<?xml version=\"1.0\"?>"
echo "<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>"
echo "<configuration>"
for property in $(xmlstarlet select --template --match "/configuration/property/name" --value-of "." --output " " $1); do
ENV=$(echo $property | tr "a-z" "A-Z" | tr "." "_" | tr "-" "_" )
# Some properties contain "[port_number]" as a placeholder. We need special handling for these.
case "$ENV" in
*\[PORT_NUMBER\]*)
PROPERTY_PREFIX=$(echo "$property" | awk -F '\\\[port_number\\\]' '{print $1}')
PROPERTY_SUFFIX=$(echo "$property" | awk -F '\\\[port_number\\\]' '{print $2}')
ENV_PREFIX=$(echo "$ENV" | awk -F '\\\[PORT_NUMBER\\\]' '{print $1}')
ENV_SUFFIX=$(echo "$ENV" | awk -F '\\\[PORT_NUMBER\\\]' '{print $2}')
echo "{{- range \$k, \$v := .Env }}"
echo " {{- if ne (replace \$k \"$ENV_PREFIX\" \"\" 1) \$k }}" # This is roughly equivalent to strings.Contains.
echo " {{- if ne (replace \$k \"$ENV_SUFFIX\" \"\" 1) \$k }}" # This is roughly equivalent to strings.Contains.
echo " {{- \$port := replace (replace \$k \"$ENV_PREFIX\" \"\" 1) \"$ENV_SUFFIX\" \"\" 1 }}"
echo " <property>"
echo " <name>$PROPERTY_PREFIX{{ \$port }}$PROPERTY_SUFFIX</name>"
echo " <value>{{ \$v }}</value>"
echo " </property>"
echo " {{- end }}"
echo " {{- end }}"
echo "{{- end}}"
;;
*)
echo "{{- if .Env.$ENV }}"
echo " <property>"
echo " <name>$property</name>"
echo " <value>{{ .Env.$ENV }}</value>"
echo " </property>"
echo "{{- end }}"
;;
esac
done
echo "</configuration>"
}
curl "https://hadoop.apache.org/docs/r${HADOOP_VERSION}/hadoop-project-dist/hadoop-common/core-default.xml" --output "core-default.xml"
generate "core-default.xml" > core-site.xml.tmpl
curl "https://hadoop.apache.org/docs/r${HADOOP_VERSION}/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml" --output "hdfs-default.xml"
generate "hdfs-default.xml" > hdfs-site.xml.tmpl
curl "https://hadoop.apache.org/docs/r${HADOOP_VERSION}/hadoop-yarn/hadoop-yarn-common/yarn-default.xml" --output "yarn-default.xml"
generate "yarn-default.xml" > yarn-site.xml.tmpl
curl "https://hadoop.apache.org/docs/r${HADOOP_VERSION}/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml" --output "mapred-default.xml"
generate "mapred-default.xml" > mapred-site.xml.tmpl