forked from devfile/registry-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl_parent_devfiles.sh
85 lines (75 loc) · 2.94 KB
/
dl_parent_devfiles.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
#!/bin/bash
# Path of stacks directory in the registry
STACKS_DIR=${STACKS_DIR:-/registry/stacks}
# Downloads the parent devfile to be used as an offline resource
download_parent_devfile() {
local stack_root=$1
local name=$2
local parent_devfile_uri=$3
parent_devfile=${name}-parent.devfile.yaml
if [ ! -f $stack_root/$parent_devfile ]; then
curl -L $parent_devfile_uri -o $stack_root/$parent_devfile || return 1
fi
}
# Updates the uri to the downloaded offline parent devfile
replace_parent_devfile() {
local stack_root=$1
local name=$2
local parent_devfile_uri=$3
stack_devfile=$stack_root/devfile.yaml
parent_devfile=../${name}-parent.devfile.yaml
if [ -f $stack_root/$parent_devfile ]; then
export PARENT_DEVFILE=$parent_devfile
yq e -i ".parent.uri=env(PARENT_DEVFILE)" $stack_devfile
fi
}
download_and_replace() {
for stack in ${stacks[@]}
do
if [ $stack == "OWNERS" ]; then
continue
fi
stack_root=$STACKS_DIR/$stack
stack_devfile=$stack_root/devfile.yaml
# Read version list for stack
versions=($([ -f ${STACKS_DIR}/${stack}/stack.yaml ] && yq e '.versions.[].version' ${STACKS_DIR}/${stack}/stack.yaml))
# Multi version stack
if [[ ${#versions[@]} -gt 0 ]]
then
for version in ${versions[@]}
do
stack_root=$STACKS_DIR/$stack/$version
stack_devfile=$stack_root/devfile.yaml
name="$(yq e ".metadata.name" $stack_devfile)"
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)"
if [ "$parent_devfile_uri" != "null" ]
then
echo "Downloading parent devfile in stack ${stack} version ${version}.."
download_parent_devfile $stack_root $name $parent_devfile_uri
if [ $? -eq 0 ]; then
replace_parent_devfile $stack_root $name $parent_devfile_uri
fi
echo "Downloading parent devfile in stack ${stack} version ${version}..done!"
fi
done
# Not a multi version stack
else
name="$(yq e ".metadata.name" $stack_devfile)"
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)"
if [ "$parent_devfile_uri" != "null" ]
then
echo "Downloading parent devfile in stack ${stack}.."
download_parent_devfile $stack_root $name $parent_devfile_uri
if [ $? -eq 0 ]; then
replace_parent_devfile $stack_root $name $parent_devfile_uri
fi
echo "Downloading parent devfile in stack ${stack}..done!"
fi
fi
done
}
# Read stacks list
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')"
echo "Downloading parent devfiles.."
download_and_replace
echo "Downloading parent devfiles..done!"