11#! /bin/bash
22
3- if [[ -z " $@ " ]]
4- then
5- echo " No starter projects specified."
6- exit 0
7- fi
8-
93# Path of stacks directory in the registry
104STACKS_DIR=/registry/stacks
115# List of starter projects to use offline
126offline_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
1315
1416# Downloads a starter project from a remote git repository and packages it as a zip archive
1517# to be used as an offline resource.
@@ -34,14 +36,21 @@ download_git_starter_project() {
3436
3537 if [ " ${revision} " != " null" ]
3638 then
37- cd $local_path && git checkout $revision && cd -
39+ cd $local_path
40+ git checkout $revision
41+ cd -
3842 fi
3943
4044 if [ " ${subDir} " != " null" ]
4145 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 -
4349 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 -
4554 fi
4655
4756 rm -rf $local_path
@@ -58,12 +67,62 @@ download_zip_starter_project() {
5867 curl -L $remote_url -o ${local_path} .zip
5968}
6069
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+ }
63124
64- echo " Downloading offline starter projects.."
65- for starter_project in ${offline_starter_projects[@]}
66- do
125+ download_all () {
67126 for stack in ${stacks[@]}
68127 do
69128 stack_root=$STACKS_DIR /$stack
77136 do
78137 stack_root=$STACKS_DIR /$stack /$version
79138 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
83143 # Starter project has a git remote
84144 if [ " $( yq e " .starterProjects[] | select(.name == \" ${starter_project} \" ).git" $stack_devfile ) " != " null" ]
85145 then
93153 download_zip_starter_project $stack_root $starter_project
94154 echo " Downloading ${starter_project} starter project in stack ${stack} version ${version} ..done!"
95155 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!"
96175 fi
97176 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
114177 fi
178+ echo
115179 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
117192echo " Downloading offline starter projects..done!"
0 commit comments