Browse code

Update hack/update-external-examples.sh

Make it more similar to the other hack/*.sh scripts by using bash,
setting common shell options, making it work on paths relative to the
project root.

Rodolfo Carvalho authored on 2016/02/25 19:40:49
Showing 2 changed files
... ...
@@ -1,14 +1,23 @@
1 1
 QuickStarts
2 2
 ===========
3 3
 
4
-QuickStarts provide the basic skeleton of an application.  Generally they reference a repository containing very simple source code that implements a trivial application using a particular framework.  In addition they define any components needed for the application including a Build configuration, supporting services such as Databases, etc.
4
+QuickStarts provide the basic skeleton of an application. Generally they
5
+reference a repository containing very simple source code that implements a
6
+trivial application using a particular framework. In addition they define any
7
+components needed for the application including a Build configuration,
8
+supporting services such as Databases, etc.
5 9
 
6
-You can instantiate these templates as is, or fork the source repository they reference and supply your forked repository as the source-repository when instantiating them.
10
+You can instantiate these templates as is, or fork the source repository they
11
+reference and supply your forked repository as the source-repository when
12
+instantiating them.
7 13
 
8
-* [CakePHP](https://raw.githubusercontent.com/openshift/cakephp-ex/master/openshift/templates/cakephp-mysql.json) - Provides a basic CakePHP application with a MySQL database.  For more information see the [source repository](https://github.com/openshift/cakephp-ex).
9
-* [Dancer](https://raw.githubusercontent.com/openshift/dancer-ex/master/openshift/templates/dancer-mysql.json) - Provides a basic Dancer(Perl) application with a MySQL database.  For more information see the [source repository](https://github.com/openshift/dancer-ex).
10
-* [Django](https://raw.githubusercontent.com/openshift/django-ex/master/openshift/templates/django-postgresql.json) - Provides a basic Django(Python) application with a PostgreSQL database.  For more information see the [source repository](https://github.com/openshift/django-ex).
11
-* [NodeJS](https://raw.githubusercontent.com/openshift/nodejs-ex/master/openshift/templates/nodejs-mongodb.json) - Provides a basic NodeJS application with a MongoDB database.  For more information see the [source repository](https://github.com/openshift/nodejs-ex).
12
-* [Rails](https://raw.githubusercontent.com/openshift/rails-ex/master/openshift/templates/rails-postgresql.json) - Provides a basic Rails(Ruby) application with a PostgreSQL database.  For more information see the [source repository](https://github.com/openshift/rails-ex).
14
+* [CakePHP](https://raw.githubusercontent.com/openshift/cakephp-ex/master/openshift/templates/cakephp-mysql.json) - Provides a basic CakePHP application with a MySQL database. For more information see the [source repository](https://github.com/openshift/cakephp-ex).
15
+* [Dancer](https://raw.githubusercontent.com/openshift/dancer-ex/master/openshift/templates/dancer-mysql.json) - Provides a basic Dancer (Perl) application with a MySQL database. For more information see the [source repository](https://github.com/openshift/dancer-ex).
16
+* [Django](https://raw.githubusercontent.com/openshift/django-ex/master/openshift/templates/django-postgresql.json) - Provides a basic Django (Python) application with a PostgreSQL database. For more information see the [source repository](https://github.com/openshift/django-ex).
17
+* [NodeJS](https://raw.githubusercontent.com/openshift/nodejs-ex/master/openshift/templates/nodejs-mongodb.json) - Provides a basic NodeJS application with a MongoDB database. For more information see the [source repository](https://github.com/openshift/nodejs-ex).
18
+* [Rails](https://raw.githubusercontent.com/openshift/rails-ex/master/openshift/templates/rails-postgresql.json) - Provides a basic Rails (Ruby) application with a PostgreSQL database. For more information see the [source repository](https://github.com/openshift/rails-ex).
13 19
 
14
-Note: This file is processed by hack/update-external-examples.sh.  New examples must follow the exact syntax of the existing entries.  Files in this directory are automatically pulled down, do not add additional files directly to this directory.
15 20
\ No newline at end of file
21
+Note: This file is processed by `hack/update-external-examples.sh`. New examples
22
+must follow the exact syntax of the existing entries. Files in this directory
23
+are automatically pulled down, do not add additional files directly to this
24
+directory.
... ...
@@ -1,16 +1,26 @@
1
-#!/bin/sh
1
+#!/bin/bash
2
+
2 3
 # This script pulls down example files (eg templates) from external repositories
3 4
 # so they can be included directly in our repository.
4 5
 # Feeds off a README.md file with well defined syntax that informs this
5 6
 # script how to pull the file down.
6 7
 
8
+set -o errexit
9
+set -o nounset
10
+set -o pipefail
11
+
12
+OS_ROOT=$(dirname "${BASH_SOURCE}")/..
13
+
7 14
 # For now the only external examples are in examples/quickstarts.
8
-pushd examples/quickstarts
9
-rm *json
10
-rm *yaml
11
-# Assume the README.md file contains lines with URLs for the raw json/yaml file to be downloaded.
12
-# Specifically look for a line containing https://raw.githubusercontent.com, then
13
-# look for the first content in ()s on that line, which will be the actual url of the file,
14
-# then use curl to pull that file down.
15
-curl `grep https://raw.githubusercontent.com README.md | sed -E "s/.*\((.*)\) -.*/\\1 -O/"`
16
-popd
15
+QUICKSTARTS_DIR="${OS_ROOT}/examples/quickstarts"
16
+(
17
+  cd "${QUICKSTARTS_DIR}"
18
+
19
+  rm -vf *.{json,yaml,yml}
20
+
21
+  # Assume the README.md file contains lines with URLs for the raw json/yaml file to be downloaded.
22
+  # Specifically look for a line containing https://raw.githubusercontent.com, then
23
+  # look for the first content in ()s on that line, which will be the actual url of the file,
24
+  # then use curl to pull that file down.
25
+  curl -# $(grep https://raw.githubusercontent.com README.md | sed -E 's/.*\((.*)\) -.*/\1 -O/')
26
+)