1
1
#! /bin/bash
2
2
3
- if [[ -z " $@ " ]]
4
- then
5
- echo " No starter projects specified."
6
- exit 0
7
- fi
8
-
9
3
# Path of stacks directory in the registry
10
4
STACKS_DIR=/registry/stacks
11
5
# List of starter projects to use offline
12
6
offline_starter_projects=( " $@ " )
7
+ # When no starter projects are specifed,
8
+ # all starter projects will be downloaded
9
+ download_all_starter_projects=false
10
+
11
+ if [[ -z " $@ " ]]
12
+ then
13
+ download_all_starter_projects=true
14
+ fi
13
15
14
16
# Downloads a starter project from a remote git repository and packages it as a zip archive
15
17
# to be used as an offline resource.
@@ -34,14 +36,21 @@ download_git_starter_project() {
34
36
35
37
if [ " ${revision} " != " null" ]
36
38
then
37
- cd $local_path && git checkout $revision && cd -
39
+ cd $local_path
40
+ git checkout $revision
41
+ cd -
38
42
fi
39
43
40
44
if [ " ${subDir} " != " null" ]
41
45
then
42
- cd $local_path /$subDir && zip -q ${local_path} .zip * .[^.]* && cd -
46
+ cd $local_path /$subDir
47
+ zip -q ../${name} -offline.zip * .[^.]*
48
+ cd -
43
49
else
44
- cd $local_path && rm -rf ./.git && zip -q ${local_path} .zip * .[^.]* && cd -
50
+ cd $local_path
51
+ rm -rf ./.git
52
+ zip -q ../${name} -offline.zip * .[^.]*
53
+ cd -
45
54
fi
46
55
47
56
rm -rf $local_path
@@ -58,12 +67,62 @@ download_zip_starter_project() {
58
67
curl -L $remote_url -o ${local_path} .zip
59
68
}
60
69
61
- # Read stacks list
62
- read -r -a stacks <<< " $(ls ${STACKS_DIR} | tr '\n' ' ')"
70
+ download_specific () {
71
+ for starter_project in ${offline_starter_projects[@]}
72
+ do
73
+ for stack in ${stacks[@]}
74
+ do
75
+ stack_root=$STACKS_DIR /$stack
76
+ stack_devfile=$stack_root /devfile.yaml
77
+ # Read version list for stack
78
+ read -r -a versions <<< " $(ls ${STACKS_DIR}/${stack} | grep -e '[0-9].[0-9].[0-9]' | tr '\n' ' ')"
79
+ # If multi version stack
80
+ if [[ ${# versions[@]} -gt 0 ]]
81
+ then
82
+ for version in ${versions[@]}
83
+ do
84
+ stack_root=$STACKS_DIR /$stack /$version
85
+ stack_devfile=$stack_root /devfile.yaml
86
+ # If the specified starter project is found
87
+ if [ ! -z " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" )" $stack_devfile ) " ]
88
+ then
89
+ # Starter project has a git remote
90
+ if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
91
+ then
92
+ echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} .."
93
+ download_git_starter_project $stack_root $starter_project
94
+ echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} ..done!"
95
+ # Starter project has a zip remote
96
+ elif [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).zip" $stack_devfile ) " != " null" ]
97
+ then
98
+ echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} .."
99
+ download_zip_starter_project $stack_root $starter_project
100
+ echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} ..done!"
101
+ fi
102
+ fi
103
+ done
104
+ # If not multi version stack & the specified starter project is found
105
+ elif [ ! -z " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" )" $stack_devfile ) " ]
106
+ then
107
+ # Starter project has a git remote
108
+ if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
109
+ then
110
+ echo " Downloading ${starter_project} starter project in stack ${stack} .."
111
+ download_git_starter_project $stack_root $starter_project
112
+ echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
113
+ # Starter project has a zip remote
114
+ elif [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).zip" $stack_devfile ) " != " null" ]
115
+ then
116
+ echo " Downloading ${starter_project} starter project in stack ${stack} .."
117
+ download_zip_starter_project $stack_root $starter_project
118
+ echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
119
+ fi
120
+ fi
121
+ done
122
+ done
123
+ }
63
124
64
- echo " Downloading offline starter projects.."
65
- for starter_project in ${offline_starter_projects[@]}
66
- do
125
+ download_all () {
67
126
for stack in ${stacks[@]}
68
127
do
69
128
stack_root=$STACKS_DIR /$stack
77
136
do
78
137
stack_root=$STACKS_DIR /$stack /$version
79
138
stack_devfile=$stack_root /devfile.yaml
80
- # If the specified starter project is found
81
- if [ ! -z " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" )" $stack_devfile ) " ]
82
- then
139
+ starter_projects=" $( yq e " .starterProjects[].name" $stack_devfile ) "
140
+
141
+ for starter_project in $starter_projects
142
+ do
83
143
# Starter project has a git remote
84
144
if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
85
145
then
93
153
download_zip_starter_project $stack_root $starter_project
94
154
echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} ..done!"
95
155
fi
156
+ done
157
+ done
158
+ # If not multi version stack
159
+ else
160
+ starter_projects=" $( yq e " .starterProjects[].name" $stack_devfile ) "
161
+ for starter_project in $starter_projects
162
+ do
163
+ # Starter project has a git remote
164
+ if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
165
+ then
166
+ echo " Downloading ${starter_project} starter project in stack ${stack} .."
167
+ download_git_starter_project $stack_root $starter_project
168
+ echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
169
+ # Starter project has a zip remote
170
+ elif [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).zip" $stack_devfile ) " != " null" ]
171
+ then
172
+ echo " Downloading ${starter_project} starter project in stack ${stack} .."
173
+ download_zip_starter_project $stack_root $starter_project
174
+ echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
96
175
fi
97
176
done
98
- # If not multi version stack & the specified starter project is found
99
- elif [ ! -z " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" )" $stack_devfile ) " ]
100
- then
101
- # Starter project has a git remote
102
- if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
103
- then
104
- echo " Downloading ${starter_project} starter project in stack ${stack} .."
105
- download_git_starter_project $stack_root $starter_project
106
- echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
107
- # Starter project has a zip remote
108
- elif [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).zip" $stack_devfile ) " != " null" ]
109
- then
110
- echo " Downloading ${starter_project} starter project in stack ${stack} .."
111
- download_zip_starter_project $stack_root $starter_project
112
- echo " Downloading ${starter_project} starter project in stack ${stack} ..done!"
113
- fi
114
177
fi
178
+ echo
115
179
done
116
- done
180
+ }
181
+
182
+ # Read stacks list
183
+ read -r -a stacks <<< " $(ls ${STACKS_DIR} | tr '\n' ' ')"
184
+
185
+ echo " Downloading offline starter projects.."
186
+ if [ " $download_all_starter_projects " = true ]
187
+ then
188
+ download_all
189
+ else
190
+ download_specific
191
+ fi
117
192
echo " Downloading offline starter projects..done!"
0 commit comments