Skip to content

Commit 5e75592

Browse files
authored
Merge pull request #365 from continuouspipe/feature/function-set-scope-forget
Use subshells to avoid set calls needing to be reset
2 parents bf773dc + b92248a commit 5e75592

File tree

11 files changed

+59
-87
lines changed

11 files changed

+59
-87
lines changed

drupal/usr/local/share/drupal/drupal_functions.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ do_drupal_install() {
9797
# then install it.
9898
if ! drush status bootstrap -r "${WEB_DIRECTORY}" | grep -q Successful ; then
9999
echo 'Installing Drupal'
100-
set +x
101-
INSTALL_OPTS="${DRUPAL_INSTALL_PROFILE} --account-name=\"${DRUPAL_ADMIN_USERNAME}\" --account-pass=\"${DRUPAL_ADMIN_PASSWORD}\" install_configure_form.update_status_module='array(FALSE,FALSE)'"
102-
# We should make sure this is writeable, but only do it directly before an
103-
# install. Drupal will lock it back down on install completion.
104-
chmod -R ug+rw,o-w "${WEB_DIRECTORY}/sites/default/files"
105-
chmod go+w "${WEB_DIRECTORY}/sites/default/settings.php"
106-
as_code_owner "drush site-install ${INSTALL_OPTS} -y -r ${WEB_DIRECTORY}"
107-
set -x
100+
(
101+
set +x
102+
INSTALL_OPTS="${DRUPAL_INSTALL_PROFILE} --account-name=\"${DRUPAL_ADMIN_USERNAME}\" --account-pass=\"${DRUPAL_ADMIN_PASSWORD}\" install_configure_form.update_status_module='array(FALSE,FALSE)'"
103+
# We should make sure this is writeable, but only do it directly before an
104+
# install. Drupal will lock it back down on install completion.
105+
chmod -R ug+rw,o-w "${WEB_DIRECTORY}/sites/default/files"
106+
chmod go+w "${WEB_DIRECTORY}/sites/default/settings.php"
107+
as_code_owner "drush site-install ${INSTALL_OPTS} -y -r ${WEB_DIRECTORY}"
108+
)
108109
fi
109110

110111
}
@@ -123,15 +124,13 @@ do_drupal_sync_database() {
123124
####
124125
# Provide SSH keys so that do_drupal_sync_database_backup_via_ssh can function
125126
####
126-
do_drupal_setup_sync_ssh_keys() {
127+
do_drupal_setup_sync_ssh_keys() (
127128
set +x
128129
do_user_ssh_keys "build" "${DRUPAL_SYNC_SSH_KEY_NAME}" "${DRUPAL_SYNC_SSH_PRIVATE_KEY}" "${DRUPAL_SYNC_SSH_PUBLIC_KEY}" "${DRUPAL_SYNC_SSH_KNOWN_HOSTS}"
129-
set +x
130130
unset DRUPAL_SYNC_SSH_PRIVATE_KEY
131131
unset DRUPAL_SYNC_SSH_PRIVATE_KEY
132132
unset DRUPAL_SYNC_SSH_KNOWN_HOSTS
133-
set -x
134-
}
133+
)
135134

136135
####
137136
# Ability to sync a database dump from a remote server that is accessible via SSH.
@@ -153,7 +152,7 @@ do_drupal_sync_database_backup_via_ssh() {
153152
# Restore a database if required.
154153
# Not triggered by default, please call from a function in your plan.sh to use.
155154
#####
156-
do_drupal_database_restore() {
155+
do_drupal_database_restore() (
157156
set +x
158157
if [ -f "$DATABASE_ARCHIVE_PATH" ]; then
159158
local DATABASE_ARGS=(-h"$DATABASE_HOST")
@@ -187,8 +186,7 @@ do_drupal_database_restore() {
187186
zcat "$DATABASE_ARCHIVE_PATH" | mysql "${DATABASE_ARGS[@]}" "$DATABASE_NAME" || return 1
188187
fi
189188
fi
190-
set -x
191-
}
189+
)
192190

193191
do_drupal_database_sanitise() {
194192
as_code_owner "drush ${DRUPAL_DRUSH_ALIAS} sql-sanitize --yes -r ${WEB_DIRECTORY}"

magento1/usr/local/share/magento1/magento_functions.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function do_magento_frontend_build() {
4545
fi
4646
}
4747

48-
function do_replace_core_config_values() {
48+
function do_replace_core_config_values() (
4949
set +x
5050
local SQL
5151
SQL="DELETE from core_config_data WHERE path LIKE 'web/%base_url';
@@ -61,8 +61,7 @@ function do_replace_core_config_values() {
6161
echo "$SQL"
6262

6363
echo "$SQL" | mysql -h"$DATABASE_HOST" -u"$DATABASE_USER" -p"$DATABASE_PASSWORD" "$DATABASE_NAME"
64-
set -x
65-
}
64+
)
6665

6766
function do_magento_config_cache_enable() {
6867
as_code_owner "php /app/bin/n98-magerun.phar cache:enable config" "${MAGE_ROOT}"
@@ -85,7 +84,7 @@ function do_magento_cache_flush() {
8584
as_code_owner "php bin/n98-magerun.phar cache:flush"
8685
}
8786

88-
function do_magento_create_admin_user() {
87+
function do_magento_create_admin_user() (
8988
if [ "$MAGENTO_CREATE_ADMIN_USER" != 'true' ]; then
9089
return 0
9190
fi
@@ -99,9 +98,8 @@ function do_magento_create_admin_user() {
9998
set +x
10099
echo "Creating admin user '$MAGENTO_ADMIN_USERNAME'"
101100
as_code_owner "php /app/bin/n98-magerun.phar admin:user:create '$MAGENTO_ADMIN_USERNAME' '$MAGENTO_ADMIN_EMAIL' '$MAGENTO_ADMIN_PASSWORD' '$MAGENTO_ADMIN_FORENAME' '$MAGENTO_ADMIN_SURNAME' Administrators" "${MAGE_ROOT}"
102-
set -x
103101
fi
104-
}
102+
)
105103

106104
function do_magento_templating() {
107105
:

magento2/usr/local/share/container/baseimage-30.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ else
7777
fi
7878

7979

80-
do_magento() {
80+
do_magento() (
8181
set +x
8282
if [ "$#" -gt 0 ]; then
8383
as_app_user "./bin/magento $(printf "%q " "$@")"
8484
else
8585
as_app_user "./bin/magento"
8686
fi
87-
}
87+
)

magento2/usr/local/share/magento2/development/install_database.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
do_magento_database_restore() {
3+
do_magento_database_restore() (
44
set +x
55
if [ -f "$DATABASE_ARCHIVE_PATH" ]; then
66
local DATABASE_ARGS=(-h"$DATABASE_HOST")
@@ -34,7 +34,6 @@ do_magento_database_restore() {
3434
zcat "$DATABASE_ARCHIVE_PATH" | mysql "${DATABASE_ARGS[@]}" "$DATABASE_NAME" || exit 1
3535
fi
3636
fi
37-
set -x
38-
}
37+
)
3938

4039
do_magento_database_restore

magento2/usr/local/share/magento2/magento_functions.sh

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function do_magento_install_finalise_custom() {
159159
fi
160160
}
161161

162-
function do_magento_drop_database() {
162+
function do_magento_drop_database() (
163163
set +x
164164

165165
if [ "$FORCE_DATABASE_DROP" != 'true' ]; then
@@ -172,9 +172,9 @@ function do_magento_drop_database() {
172172
else
173173
mysql -h"$DATABASE_HOST" -uroot -e "DROP DATABASE IF EXISTS $DATABASE_NAME" || exit 1
174174
fi
175-
}
175+
)
176176

177-
function check_magento_database_exists() {
177+
function check_magento_database_exists() (
178178
set +e
179179
local DATABASE_EXISTS
180180
if [ -n "$DATABASE_PASSWORD" ]; then
@@ -189,7 +189,7 @@ function check_magento_database_exists() {
189189
else
190190
echo "false";
191191
fi
192-
}
192+
)
193193

194194
function do_magento_database_create() {
195195
echo 'Create Magento database'
@@ -200,14 +200,13 @@ function do_magento_database_create() {
200200
fi
201201
}
202202

203-
function do_magento_database_install() {
203+
function do_magento_database_install() (
204204
set +x
205205
if [ -f "$DATABASE_ARCHIVE_PATH" ]; then
206206
do_magento_drop_database
207207

208208
local DATABASE_EXISTS
209209
DATABASE_EXISTS="$(check_magento_database_exists)"
210-
set -e
211210

212211
if [ "$DATABASE_EXISTS" != "true" ]; then
213212
do_magento_database_create
@@ -221,16 +220,15 @@ function do_magento_database_install() {
221220
fi
222221
fi
223222
set -x
224-
}
223+
)
225224

226-
function do_magento_installer_install() {
225+
function do_magento_installer_install() (
227226
set +x
228227
do_magento_wait_for_database
229228
do_magento_drop_database
230229

231230
local DATABASE_EXISTS
232231
DATABASE_EXISTS="$(check_magento_database_exists)"
233-
set -e
234232

235233
if [ "$DATABASE_EXISTS" != "true" ]; then
236234
do_magento_database_create
@@ -253,9 +251,7 @@ function do_magento_installer_install() {
253251
--use-rewrites=1 \
254252
--session-save=db"
255253
fi
256-
257-
set -x
258-
}
254+
)
259255

260256
function do_magento_wait_for_database() {
261257
if [ "$DATABASE_HOST" != 'localhost' ]; then
@@ -301,8 +297,7 @@ function do_magento_install_development_custom() {
301297
fi
302298
}
303299

304-
function do_replace_core_config_values() {
305-
set +x
300+
function do_replace_core_config_values() (
306301
local SQL
307302
SQL="DELETE from core_config_data WHERE path LIKE 'web/%base_url';
308303
DELETE from core_config_data WHERE path LIKE 'system/full_page_cache/varnish%';
@@ -321,9 +316,7 @@ function do_replace_core_config_values() {
321316
else
322317
echo "$SQL" | mysql -h"$DATABASE_HOST" -u"$DATABASE_USER" "$DATABASE_NAME"
323318
fi
324-
325-
set -x
326-
}
319+
)
327320

328321
function do_magento_build_start_mysql() {
329322
apt-get update -qq -y
@@ -393,10 +386,9 @@ function do_magento_tail_logs() {
393386
/app/var/log/system.log
394387
}
395388

396-
function do_magento_create_admin_user() {
389+
function do_magento_create_admin_user() (
397390
set +x
398391
if [ -z "${MAGENTO_ADMIN_USERNAME}" ] || [ -z "${MAGENTO_ADMIN_PASSWORD}" ]; then
399-
set -x
400392
return 0
401393
fi
402394
local SQL="SELECT 1 FROM admin_user WHERE username='$MAGENTO_ADMIN_USERNAME'"
@@ -412,7 +404,6 @@ function do_magento_create_admin_user() {
412404
set -e
413405

414406
if [ "$HAS_ADMIN_USER" != 0 ]; then
415-
set +x
416407
as_code_owner "bin/magento admin:user:create \
417408
--admin-user='${MAGENTO_ADMIN_USERNAME}' \
418409
--admin-password='${MAGENTO_ADMIN_PASSWORD}' \
@@ -421,7 +412,7 @@ function do_magento_create_admin_user() {
421412
--admin-lastname='Admin'"
422413
set -x
423414
fi
424-
}
415+
)
425416

426417
function do_magento2_build() {
427418

php-apache/usr/local/share/assets/assets_functions.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function assets_apply_database()
5656
}
5757

5858
function assets_apply_database_mysql()
59-
{
59+
(
6060
set +x
6161
local DECOMPRESS
6262
local -r ASSET_FILE="$1"
@@ -87,7 +87,6 @@ function assets_apply_database_mysql()
8787
fi
8888

8989
wait_for_remote_ports "${ASSETS_DATABASE_WAIT_TIMEOUT}" "${DATABASE_HOST}:${DATABASE_PORT}"
90-
set +x
9190

9291
local DATABASES
9392
mapfile -t DATABASES < <(mysql "${DATABASE_ARGS[@]}" --execute="SHOW DATABASES" | tail --lines=+2)
@@ -119,11 +118,10 @@ function assets_apply_database_mysql()
119118
echo "Importing ${ASSET_FILE} into ${APPLY_DATABASE_NAME} MySql database"
120119
"${DECOMPRESS[@]}" | mysql "${DATABASE_ARGS[@]}" "${APPLY_DATABASE_NAME}"
121120
fi
122-
set -x
123-
}
121+
)
124122

125123
function assets_apply_database_postgres()
126-
{
124+
(
127125
set +x
128126
local DECOMPRESS
129127
local -r ASSET_FILE="$1"
@@ -156,7 +154,6 @@ function assets_apply_database_postgres()
156154
fi
157155

158156
wait_for_remote_ports "${ASSETS_DATABASE_WAIT_TIMEOUT}" "${DATABASE_HOST}:${DATABASE_PORT}"
159-
set +x
160157

161158
local DATABASES
162159
mapfile -t DATABASES < <(PGPASSWORD="$PGPASSWORD" psql "${DATABASE_ARGS[@]}" -lqt | cut -d \| -f 1 | sed "s/ //g")
@@ -189,8 +186,7 @@ function assets_apply_database_postgres()
189186
echo "Importing ${ASSET_FILE} into ${APPLY_DATABASE_NAME} MySql database"
190187
"${DECOMPRESS[@]}" | PGPASSWORD="$PGPASSWORD" psql "${DATABASE_ARGS[@]}" "${APPLY_DATABASE_NAME}"
191188
fi
192-
set -x
193-
}
189+
)
194190

195191
function do_assets_apply_database()
196192
{

php-nginx/usr/local/share/assets/assets_functions.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function assets_apply_database()
5656
}
5757

5858
function assets_apply_database_mysql()
59-
{
59+
(
6060
set +x
6161
local DECOMPRESS
6262
local -r ASSET_FILE="$1"
@@ -87,7 +87,6 @@ function assets_apply_database_mysql()
8787
fi
8888

8989
wait_for_remote_ports "${ASSETS_DATABASE_WAIT_TIMEOUT}" "${DATABASE_HOST}:${DATABASE_PORT}"
90-
set +x
9190

9291
local DATABASES
9392
mapfile -t DATABASES < <(mysql "${DATABASE_ARGS[@]}" --execute="SHOW DATABASES" | tail --lines=+2)
@@ -119,11 +118,10 @@ function assets_apply_database_mysql()
119118
echo "Importing ${ASSET_FILE} into ${APPLY_DATABASE_NAME} MySql database"
120119
"${DECOMPRESS[@]}" | mysql "${DATABASE_ARGS[@]}" "${APPLY_DATABASE_NAME}"
121120
fi
122-
set -x
123-
}
121+
)
124122

125123
function assets_apply_database_postgres()
126-
{
124+
(
127125
set +x
128126
local DECOMPRESS
129127
local -r ASSET_FILE="$1"
@@ -156,7 +154,6 @@ function assets_apply_database_postgres()
156154
fi
157155

158156
wait_for_remote_ports "${ASSETS_DATABASE_WAIT_TIMEOUT}" "${DATABASE_HOST}:${DATABASE_PORT}"
159-
set +x
160157

161158
local DATABASES
162159
mapfile -t DATABASES < <(PGPASSWORD="$PGPASSWORD" psql "${DATABASE_ARGS[@]}" -lqt | cut -d \| -f 1 | sed "s/ //g")
@@ -189,8 +186,7 @@ function assets_apply_database_postgres()
189186
echo "Importing ${ASSET_FILE} into ${APPLY_DATABASE_NAME} MySql database"
190187
"${DECOMPRESS[@]}" | PGPASSWORD="$PGPASSWORD" psql "${DATABASE_ARGS[@]}" "${APPLY_DATABASE_NAME}"
191188
fi
192-
set -x
193-
}
189+
)
194190

195191
function do_assets_apply_database()
196192
{

spryker/usr/local/share/spryker/spryker_functions.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ do_spryker_app_permissions() {
4747
fi
4848
}
4949

50-
do_spryker_config_create() {
50+
do_spryker_config_create() (
5151
set +x
5252
echo "Creating Postgres Credentials file in /root/.pgpass"
5353
# create .pgpass in home directory for postgres client
5454
echo "$DATABASE_HOST:*:*:$DATABASE_USER:$DATABASE_PASSWORD" > /root/.pgpass
5555
chmod 0600 /root/.pgpass
56-
set -x
57-
}
56+
)
5857

5958
do_spryker_build() {
6059
do_spryker_directory_create

symfony/usr/local/share/symfony/symfony_functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ do_symfony_build() {
147147
do_symfony_config_create
148148
}
149149

150-
do_symfony_console() {
150+
do_symfony_console() (
151151
set +x
152152
if [ "$#" -gt 0 ]; then
153153
as_app_user "'$SYMFONY_CONSOLE' $(printf "%q " "$@")"
154154
else
155155
as_app_user "'$SYMFONY_CONSOLE'"
156156
fi
157-
}
157+
)

0 commit comments

Comments
 (0)