forked from DataDog/datadog-agent-boshrelease
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare
executable file
·128 lines (114 loc) · 3.24 KB
/
prepare
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
#!/usr/bin/env bash
SRC=$(pwd)/blobs
SHELL=/bin/bash
AWK=awk
read_spec() {
local spec="$1"
$AWK '/^files:/ {
while (getline) {
if ($1 == "-") {
if ($3 ~ /#/) {
url=$3$4;
sub(/#/, "", url)
print $2"@"url;
}
} else {
next;
}
}
}' "$spec"
}
exec_download() {
local output="$1"
local url="$2"
local package=$(dirname "${output}")
local src=$(basename "${output}")
(
cd ${SRC}
if [ ! -s "${output}" ]; then
echo " Downloading ${url} ..."
mkdir -p "${package}"
curl -L -s "${url}" -o "${output}"
fi
)
}
add_blob() {
local blob="$1"
bosh add-blob ${SRC}/${1} ${1} || true
}
get_agent_version() {
local file="$1"
local version=""
if [ -f $file ]; then
version=$(grep -o -h -e "DD_AGENT_VERSION=[0-9]\.[0-9]\.[0-9][~]*[r]*[c]*\.*[0-9]*" $file)
version=$(echo $version | cut -d'=' -f 2)
fi
echo $version
}
check_versions() {
local agent_script=$(pwd)/packages/dd-agent/packaging
local agent_version=$(get_agent_version $agent_script)
for script in $(pwd)/packages/*/spec ; do
local base=$(dirname "${script}")
local priorversion=""
for spec in $(read_spec "${script}"); do
local downloadfile=$(echo $spec | cut -d'@' -f 1)
local downloadurl=$(echo $spec | cut -d'@' -f 2)
local file_version=$(echo $downloadfile | grep -o -h -e "[0-9]\.[0-9]\.[0-9][~]*[r]*[c]*\.*[0-9]*")
local url_version=$(echo $downloadfile | grep -o -h -e "[0-9]\.[0-9]\.[0-9][~]*[r]*[c]*\.*[0-9]*")
if [ "$file_version" != "$url_version" ]; then
echo "The Agent versions in the File and URL do not match"
exit 1
fi
local version="$file_version"
if [ -n "$version" ]; then
if [ "$version" = "$agent_version" ]; then
if [ -n "$priorversion" ]; then
if [ "$version" != "$priorversion" ]; then
echo "The Agent blob versions do not match"
exit 1
fi
fi
else
echo "The Agent versions do not match the version in the script"
exit 1
fi
fi
priorversion="$version"
done
done
}
remove_stale() {
local stale_files=""
local spec_files=""
for spec in $(read_spec "${script}"); do
local downloadfile=$(echo $spec | cut -d'@' -f 1)
local filename=$(echo $downloadfile | cut -d'/' -f 2)
spec_files="$filename $spec_files"
done
for saved_file in $(ls blobs/dd-agent); do
res=$(echo "$spec_files" | grep -o -h "$saved_file")
if [[ ! "$res" ]]; then
bosh remove-blob "dd-agent/$saved_file"
fi
done
}
main() {
for script in $(pwd)/packages/*/spec ; do
local base=$(dirname "${script}")
echo "* Procesing ${script} ..."
local priorversion=""
for spec in $(read_spec "${script}"); do
local downloadfile=$(echo $spec | cut -d'@' -f 1)
local file_version=$(echo $downloadfile | grep -o -h -e "[0-9]\.[0-9]\.[0-9][~]*[r]*[c]*\.*[0-9]*")
local downloadurl=$(echo $spec | cut -d'@' -f 2)
exec_download "${downloadfile}" "${downloadurl}"
add_blob "${downloadfile}"
done
done
check_versions
remove_stale
}
# Run!
mkdir -p $SRC
main